Files
medusa-store/integration-tests/http/__tests__/payment-collection/admin/payment-sessions.spec.ts
Riqwan Thamir 288e41856b fix(core-flows): delete existing payment session before creating new (#7751)
what:

Multiple active sessions are used for split payments. We don't currently support split payments. Until we have that implemented, this change is to ensure that whenever we create a new payment session, we delete an existing session if present. 

RESOLVES CORE-2284
2024-06-18 11:51:20 +00:00

66 lines
1.8 KiB
TypeScript

import { medusaIntegrationTestRunner } from "medusa-test-utils"
import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
jest.setTimeout(30000)
medusaIntegrationTestRunner({
testSuite: ({ dbConnection, getContainer, api }) => {
beforeAll(() => {})
beforeEach(async () => {
const container = getContainer()
await createAdminUser(dbConnection, adminHeaders, container)
})
describe("POST /admin/payment-collections/:id/payment-sessions", () => {
let region
beforeEach(async () => {
region = (
await api.post(
"/admin/regions",
{ name: "United States", currency_code: "usd", countries: ["us"] },
adminHeaders
)
).data.region
})
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",
})
).data.payment_collection
await api.post(
`/store/payment-collections/${paymentCollection.id}/payment-sessions`,
{ provider_id: "pp_system_default" }
)
// Adding a second payment session to ensure only one session gets created
const {
data: { payment_collection },
} = await api.post(
`/store/payment-collections/${paymentCollection.id}/payment-sessions`,
{ provider_id: "pp_system_default" }
)
expect(payment_collection.payment_sessions).toEqual([
expect.objectContaining({
currency_code: "usd",
provider_id: "pp_system_default",
status: "pending",
amount: 150,
}),
])
})
})
},
})