chore(medusa,core-flows): cart payment collection link (#8457)
This commit is contained in:
1 parent
decd830474
commit
5125d1328d
16 files changed
+249
-211
No files matched your search
@@ -165,9 +165,6 @@ export async function createOrderSeeder({ api }) {
|
||||
const paymentCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
cart_id: cart.id,
|
||||
region_id: region.id,
|
||||
currency_code: region.currency_code,
|
||||
amount: cart.total,
|
||||
})
|
||||
).data.payment_collection
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
import { getProductFixture } from "../../../../helpers/fixtures"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -17,6 +18,8 @@ medusaIntegrationTestRunner({
|
||||
|
||||
describe("POST /admin/payment-collections/:id/payment-sessions", () => {
|
||||
let region
|
||||
let product
|
||||
let cart
|
||||
|
||||
beforeEach(async () => {
|
||||
region = (
|
||||
@@ -26,15 +29,43 @@ medusaIntegrationTestRunner({
|
||||
adminHeaders
|
||||
)
|
||||
).data.region
|
||||
|
||||
product = (
|
||||
await api.post(
|
||||
"/admin/products",
|
||||
getProductFixture({
|
||||
title: "test",
|
||||
status: "published",
|
||||
variants: [
|
||||
{
|
||||
title: "Test variant",
|
||||
manage_inventory: false,
|
||||
prices: [
|
||||
{
|
||||
amount: 150,
|
||||
currency_code: "usd",
|
||||
rules: { region_id: region.id },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}),
|
||||
adminHeaders
|
||||
)
|
||||
).data.product
|
||||
|
||||
cart = (
|
||||
await api.post("/store/carts", {
|
||||
region_id: region.id,
|
||||
items: [{ variant_id: product.variants[0].id, quantity: 1 }],
|
||||
})
|
||||
).data.cart
|
||||
})
|
||||
|
||||
it("should create a payment session", async () => {
|
||||
const paymentCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
region_id: region.id,
|
||||
cart_id: "cart.id",
|
||||
amount: 150,
|
||||
currency_code: "usd",
|
||||
cart_id: cart.id,
|
||||
})
|
||||
).data.payment_collection
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import { setupTaxStructure } from "../../../../modules/__tests__/fixtures"
|
||||
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { createAdminUser } from "../../../../helpers/create-admin-user"
|
||||
import { getProductFixture } from "../../../../helpers/fixtures"
|
||||
import { createOrderSeeder } from "../../fixtures/order"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
@@ -16,20 +17,59 @@ medusaIntegrationTestRunner({
|
||||
let paymentCollection
|
||||
let payment
|
||||
let container
|
||||
let region
|
||||
let product
|
||||
let cart
|
||||
|
||||
beforeEach(async () => {
|
||||
container = getContainer()
|
||||
paymentModule = container.resolve(ModuleRegistrationName.PAYMENT)
|
||||
await createAdminUser(dbConnection, adminHeaders, container)
|
||||
|
||||
region = (
|
||||
await api.post(
|
||||
"/admin/regions",
|
||||
{ name: "United States", currency_code: "usd", countries: ["us"] },
|
||||
adminHeaders
|
||||
)
|
||||
).data.region
|
||||
|
||||
product = (
|
||||
await api.post(
|
||||
"/admin/products",
|
||||
getProductFixture({
|
||||
title: "test",
|
||||
status: "published",
|
||||
variants: [
|
||||
{
|
||||
title: "Test variant",
|
||||
manage_inventory: false,
|
||||
prices: [
|
||||
{
|
||||
amount: 1000,
|
||||
currency_code: "usd",
|
||||
rules: { region_id: region.id },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}),
|
||||
adminHeaders
|
||||
)
|
||||
).data.product
|
||||
|
||||
cart = (
|
||||
await api.post("/store/carts", {
|
||||
region_id: region.id,
|
||||
items: [{ variant_id: product.variants[0].id, quantity: 1 }],
|
||||
})
|
||||
).data.cart
|
||||
|
||||
const collection = (
|
||||
await api.post(
|
||||
"/store/payment-collections",
|
||||
{
|
||||
cart_id: "test-cart",
|
||||
region_id: "test-region",
|
||||
amount: 1000,
|
||||
currency_code: "usd",
|
||||
cart_id: cart.id,
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
deleteLineItemsStepId,
|
||||
deleteLineItemsWorkflow,
|
||||
findOrCreateCustomerStepId,
|
||||
linkCartAndPaymentCollectionsStepId,
|
||||
listShippingOptionsForCartWorkflow,
|
||||
refreshPaymentCollectionForCartWorkflow,
|
||||
updateLineItemInCartWorkflow,
|
||||
@@ -1143,9 +1142,6 @@ medusaIntegrationTestRunner({
|
||||
await createPaymentCollectionForCartWorkflow(appContainer).run({
|
||||
input: {
|
||||
cart_id: cart.id,
|
||||
region_id: defaultRegion.id,
|
||||
currency_code: "dkk",
|
||||
amount: 5000,
|
||||
},
|
||||
throwOnError: false,
|
||||
})
|
||||
@@ -1182,17 +1178,13 @@ medusaIntegrationTestRunner({
|
||||
const workflow =
|
||||
createPaymentCollectionForCartWorkflow(appContainer)
|
||||
|
||||
workflow.appendAction(
|
||||
"throw",
|
||||
linkCartAndPaymentCollectionsStepId,
|
||||
{
|
||||
invoke: async function failStep() {
|
||||
throw new Error(
|
||||
`Failed to do something after linking cart and payment collection`
|
||||
)
|
||||
},
|
||||
}
|
||||
)
|
||||
workflow.addAction("throw", {
|
||||
invoke: async function failStep() {
|
||||
throw new Error(
|
||||
`Failed to do something after linking cart and payment collection`
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
const region = await regionModuleService.createRegions({
|
||||
name: "US",
|
||||
@@ -1214,9 +1206,6 @@ medusaIntegrationTestRunner({
|
||||
const { errors } = await workflow.run({
|
||||
input: {
|
||||
cart_id: cart.id,
|
||||
region_id: region.id,
|
||||
currency_code: "usd",
|
||||
amount: 5000,
|
||||
},
|
||||
throwOnError: false,
|
||||
})
|
||||
@@ -1280,7 +1269,7 @@ medusaIntegrationTestRunner({
|
||||
|
||||
const paymentCollection =
|
||||
await paymentModule.createPaymentCollections({
|
||||
amount: 5000,
|
||||
amount: 5001,
|
||||
currency_code: "dkk",
|
||||
region_id: defaultRegion.id,
|
||||
})
|
||||
@@ -1288,7 +1277,7 @@ medusaIntegrationTestRunner({
|
||||
const paymentSession = await paymentModule.createPaymentSession(
|
||||
paymentCollection.id,
|
||||
{
|
||||
amount: 5000,
|
||||
amount: 5001,
|
||||
currency_code: "dkk",
|
||||
data: {},
|
||||
provider_id: "pp_system_default",
|
||||
|
||||
@@ -1400,7 +1400,7 @@ medusaIntegrationTestRunner({
|
||||
adjustments: [
|
||||
expect.objectContaining({
|
||||
code: "PROMOTION_APPLIED",
|
||||
amount: 180,
|
||||
amount: 177.86561264822134,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@@ -1414,7 +1414,7 @@ medusaIntegrationTestRunner({
|
||||
expect.objectContaining({
|
||||
id: expect.not.stringContaining(lineItemAdjustment.id),
|
||||
code: "PROMOTION_APPLIED",
|
||||
amount: 120,
|
||||
amount: 122.13438735177866,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@@ -1542,10 +1542,7 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
const response = await api.post(`/store/payment-collections`, {
|
||||
region_id: region.id,
|
||||
cart_id: cart.id,
|
||||
amount: 0,
|
||||
currency_code: cart.currency_code,
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -1570,18 +1567,12 @@ medusaIntegrationTestRunner({
|
||||
|
||||
const firstCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
region_id: region.id,
|
||||
cart_id: cart.id,
|
||||
amount: 0,
|
||||
currency_code: cart.currency_code,
|
||||
})
|
||||
).data.payment_collection
|
||||
|
||||
const response = await api.post(`/store/payment-collections`, {
|
||||
region_id: region.id,
|
||||
cart_id: cart.id,
|
||||
amount: 0,
|
||||
currency_code: cart.currency_code,
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
@@ -1608,19 +1599,13 @@ medusaIntegrationTestRunner({
|
||||
|
||||
const firstCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
region_id: region.id,
|
||||
cart_id: firstCart.id,
|
||||
amount: 0,
|
||||
currency_code: firstCart.currency_code,
|
||||
})
|
||||
).data.payment_collection
|
||||
|
||||
const secondCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
region_id: region.id,
|
||||
cart_id: secondCart.id,
|
||||
amount: 0,
|
||||
currency_code: secondCart.currency_code,
|
||||
})
|
||||
).data.payment_collection
|
||||
|
||||
@@ -2008,9 +1993,6 @@ medusaIntegrationTestRunner({
|
||||
const paymentCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
cart_id: cart.id,
|
||||
region_id: region.id,
|
||||
currency_code: region.currency_code,
|
||||
amount: cart.total,
|
||||
})
|
||||
).data.payment_collection
|
||||
|
||||
@@ -2140,9 +2122,6 @@ medusaIntegrationTestRunner({
|
||||
|
||||
await api.post(`/store/payment-collections`, {
|
||||
cart_id: cart.id,
|
||||
region_id: region.id,
|
||||
currency_code: region.currency_code,
|
||||
amount: cart.total,
|
||||
})
|
||||
|
||||
const error = await api
|
||||
@@ -2192,9 +2171,6 @@ medusaIntegrationTestRunner({
|
||||
const paymentCollection = (
|
||||
await api.post(`/store/payment-collections`, {
|
||||
cart_id: cart.id,
|
||||
region_id: region.id,
|
||||
currency_code: region.currency_code,
|
||||
amount: cart.total,
|
||||
})
|
||||
).data.payment_collection
|
||||
|
||||
|
||||
Reference in new issue
Block a user