-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
506 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dist | ||
node_modules | ||
.DS_store | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/medusa-payment-stripe-processor/src/__fixtures__/data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export const PaymentIntentDataByStatus = { | ||
REQUIRE_PAYMENT_METHOD: { | ||
id: "requires_payment_method", | ||
status: "requires_payment_method" | ||
}, | ||
REQUIRES_CONFIRMATION: { | ||
id: "requires_confirmation", | ||
status: "requires_confirmation" | ||
}, | ||
PROCESSING: { | ||
id: "processing", | ||
status: "processing" | ||
}, | ||
REQUIRES_ACTION: { | ||
id: "requires_action", | ||
status: "requires_action" | ||
}, | ||
CANCELED: { | ||
id: "canceled", | ||
status: "canceled" | ||
}, | ||
REQUIRES_CAPTURE: { | ||
id: "requires_capture", | ||
status: "requires_capture" | ||
}, | ||
SUCCEEDED: { | ||
id: "succeeded", | ||
status: "succeeded" | ||
}, | ||
} |
216 changes: 216 additions & 0 deletions
216
packages/medusa-payment-stripe-processor/src/__mocks__/cart.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
import { IdMap } from "medusa-test-utils" | ||
|
||
export const carts = { | ||
emptyCart: { | ||
id: IdMap.getId("emptyCart"), | ||
items: [], | ||
region_id: IdMap.getId("testRegion"), | ||
customer_id: "test-customer", | ||
payment_sessions: [], | ||
shipping_options: [ | ||
{ | ||
id: IdMap.getId("freeShipping"), | ||
profile_id: "default_profile", | ||
data: { | ||
some_data: "yes", | ||
}, | ||
}, | ||
], | ||
}, | ||
frCart: { | ||
id: IdMap.getId("fr-cart"), | ||
email: "[email protected]", | ||
title: "test", | ||
region_id: IdMap.getId("region-france"), | ||
items: [ | ||
{ | ||
id: IdMap.getId("line"), | ||
title: "merge line", | ||
description: "This is a new line", | ||
thumbnail: "test-img-yeah.com/thumb", | ||
|
||
unit_price: 8, | ||
variant: { | ||
id: IdMap.getId("eur-8-us-10"), | ||
}, | ||
product: { | ||
id: IdMap.getId("product"), | ||
}, | ||
// { | ||
// unit_price: 10, | ||
// variant: { | ||
// id: IdMap.getId("eur-10-us-12"), | ||
// }, | ||
// product: { | ||
// id: IdMap.getId("product"), | ||
// }, | ||
// quantity: 1, | ||
// }, | ||
quantity: 10, | ||
}, | ||
{ | ||
id: IdMap.getId("existingLine"), | ||
title: "merge line", | ||
description: "This is a new line", | ||
thumbnail: "test-img-yeah.com/thumb", | ||
unit_price: 10, | ||
variant: { | ||
id: IdMap.getId("eur-10-us-12"), | ||
}, | ||
product: { | ||
id: IdMap.getId("product"), | ||
}, | ||
quantity: 1, | ||
}, | ||
], | ||
shipping_methods: [ | ||
{ | ||
id: IdMap.getId("freeShipping"), | ||
profile_id: "default_profile", | ||
}, | ||
], | ||
shipping_options: [ | ||
{ | ||
id: IdMap.getId("freeShipping"), | ||
profile_id: "default_profile", | ||
}, | ||
], | ||
payment_sessions: [ | ||
{ | ||
provider_id: "stripe", | ||
data: { | ||
id: "pi_123456789", | ||
customer: IdMap.getId("not-lebron"), | ||
}, | ||
}, | ||
], | ||
payment_method: { | ||
provider_id: "stripe", | ||
data: { | ||
id: "pi_123456789", | ||
customer: IdMap.getId("not-lebron"), | ||
}, | ||
}, | ||
region: { currency_code: "usd" }, | ||
total: 100, | ||
shipping_address: {}, | ||
billing_address: {}, | ||
discounts: [], | ||
customer_id: IdMap.getId("lebron"), | ||
context: {} | ||
}, | ||
frCartNoStripeCustomer: { | ||
id: IdMap.getId("fr-cart-no-customer"), | ||
title: "test", | ||
region_id: IdMap.getId("region-france"), | ||
items: [ | ||
{ | ||
id: IdMap.getId("line"), | ||
title: "merge line", | ||
description: "This is a new line", | ||
thumbnail: "test-img-yeah.com/thumb", | ||
content: [ | ||
{ | ||
unit_price: 8, | ||
variant: { | ||
id: IdMap.getId("eur-8-us-10"), | ||
}, | ||
product: { | ||
id: IdMap.getId("product"), | ||
}, | ||
quantity: 1, | ||
}, | ||
{ | ||
unit_price: 10, | ||
variant: { | ||
id: IdMap.getId("eur-10-us-12"), | ||
}, | ||
product: { | ||
id: IdMap.getId("product"), | ||
}, | ||
quantity: 1, | ||
}, | ||
], | ||
quantity: 10, | ||
}, | ||
{ | ||
id: IdMap.getId("existingLine"), | ||
title: "merge line", | ||
description: "This is a new line", | ||
thumbnail: "test-img-yeah.com/thumb", | ||
content: { | ||
unit_price: 10, | ||
variant: { | ||
id: IdMap.getId("eur-10-us-12"), | ||
}, | ||
product: { | ||
id: IdMap.getId("product"), | ||
}, | ||
quantity: 1, | ||
}, | ||
quantity: 10, | ||
}, | ||
], | ||
shipping_methods: [ | ||
{ | ||
id: IdMap.getId("freeShipping"), | ||
profile_id: "default_profile", | ||
}, | ||
], | ||
shipping_options: [ | ||
{ | ||
id: IdMap.getId("freeShipping"), | ||
profile_id: "default_profile", | ||
}, | ||
], | ||
payment_sessions: [ | ||
{ | ||
provider_id: "stripe", | ||
data: { | ||
id: "pi_no", | ||
customer: IdMap.getId("not-lebron"), | ||
}, | ||
}, | ||
], | ||
payment_method: { | ||
provider_id: "stripe", | ||
data: { | ||
id: "pi_no", | ||
customer: IdMap.getId("not-lebron"), | ||
}, | ||
}, | ||
shipping_address: {}, | ||
billing_address: {}, | ||
discounts: [], | ||
customer_id: IdMap.getId("vvd"), | ||
}, | ||
} | ||
|
||
export const CartServiceMock = { | ||
withTransaction: function () { | ||
return this | ||
}, | ||
retrieve: jest.fn().mockImplementation((cartId) => { | ||
if (cartId === IdMap.getId("fr-cart")) { | ||
return Promise.resolve(carts.frCart) | ||
} | ||
if (cartId === IdMap.getId("fr-cart-no-customer")) { | ||
return Promise.resolve(carts.frCartNoStripeCustomer) | ||
} | ||
if (cartId === IdMap.getId("emptyCart")) { | ||
return Promise.resolve(carts.emptyCart) | ||
} | ||
return Promise.resolve(undefined) | ||
}), | ||
updatePaymentSession: jest | ||
.fn() | ||
.mockImplementation((cartId, stripe, paymentIntent) => { | ||
return Promise.resolve() | ||
}), | ||
} | ||
|
||
const mock = jest.fn().mockImplementation(() => { | ||
return CartServiceMock | ||
}) | ||
|
||
export default mock |
39 changes: 39 additions & 0 deletions
39
packages/medusa-payment-stripe-processor/src/__mocks__/customer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { IdMap } from "medusa-test-utils" | ||
|
||
export const CustomerServiceMock = { | ||
withTransaction: function () { | ||
return this | ||
}, | ||
retrieve: jest.fn().mockImplementation((id) => { | ||
if (id === IdMap.getId("lebron")) { | ||
return Promise.resolve({ | ||
_id: IdMap.getId("lebron"), | ||
first_name: "LeBron", | ||
last_name: "James", | ||
email: "[email protected]", | ||
password_hash: "1234", | ||
metadata: { | ||
stripe_id: "cus_123456789_new", | ||
}, | ||
}) | ||
} | ||
if (id === IdMap.getId("vvd")) { | ||
return Promise.resolve({ | ||
_id: IdMap.getId("vvd"), | ||
first_name: "Virgil", | ||
last_name: "Van Dijk", | ||
email: "[email protected]", | ||
password_hash: "1234", | ||
metadata: {}, | ||
}) | ||
} | ||
return Promise.resolve(undefined) | ||
}), | ||
setMetadata: jest.fn().mockReturnValue(Promise.resolve()), | ||
} | ||
|
||
const mock = jest.fn().mockImplementation(() => { | ||
return CustomerServiceMock | ||
}) | ||
|
||
export default mock |
10 changes: 10 additions & 0 deletions
10
packages/medusa-payment-stripe-processor/src/__mocks__/eventbus.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const EventBusServiceMock = { | ||
emit: jest.fn(), | ||
subscribe: jest.fn(), | ||
} | ||
|
||
const mock = jest.fn().mockImplementation(() => { | ||
return EventBusServiceMock | ||
}) | ||
|
||
export default mock |
37 changes: 37 additions & 0 deletions
37
packages/medusa-payment-stripe-processor/src/__mocks__/stripe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { PaymentIntentDataByStatus } from "../__fixtures__/data"; | ||
|
||
function buildPaymentIntent(data) { | ||
const paymentIntentData = {} | ||
|
||
return Object.assign(paymentIntentData, data) | ||
} | ||
|
||
export const StripeMock = { | ||
retrieve: jest.fn().mockImplementation(async (paymentId) => { | ||
if (paymentId === PaymentIntentDataByStatus.REQUIRE_PAYMENT_METHOD) { | ||
return buildPaymentIntent({ status: PaymentIntentDataByStatus.REQUIRE_PAYMENT_METHOD }) | ||
} | ||
if (paymentId === PaymentIntentDataByStatus.REQUIRES_CONFIRMATION) { | ||
return buildPaymentIntent({ status: PaymentIntentDataByStatus.REQUIRES_CONFIRMATION }) | ||
} | ||
if (paymentId === PaymentIntentDataByStatus.PROCESSING) { | ||
return buildPaymentIntent({ status: PaymentIntentDataByStatus.PROCESSING }) | ||
} | ||
if (paymentId === PaymentIntentDataByStatus.CANCELED) { | ||
return buildPaymentIntent({ status: PaymentIntentDataByStatus.REQUIRES_ACTION }) | ||
} | ||
if (paymentId === PaymentIntentDataByStatus.CANCELED) { | ||
return buildPaymentIntent({ status: PaymentIntentDataByStatus.CANCELED }) | ||
} | ||
if (paymentId === PaymentIntentDataByStatus.REQUIRES_CAPTURE) { | ||
return buildPaymentIntent({ status: PaymentIntentDataByStatus.REQUIRES_CAPTURE }) | ||
} | ||
if (paymentId === PaymentIntentDataByStatus.SUCCEEDED) { | ||
return buildPaymentIntent({ status: PaymentIntentDataByStatus.SUCCEEDED }) | ||
} | ||
}) | ||
} | ||
|
||
const stripe = jest.fn(() => StripeMock) | ||
|
||
export default stripe |
12 changes: 12 additions & 0 deletions
12
packages/medusa-payment-stripe-processor/src/__mocks__/totals.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const TotalsServiceMock = { | ||
withTransaction: function () { | ||
return this | ||
}, | ||
getTotal: jest.fn(), | ||
} | ||
|
||
const mock = jest.fn().mockImplementation(() => { | ||
return TotalsServiceMock | ||
}) | ||
|
||
export default mock |
Oops, something went wrong.