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
This commit is contained in:
Riqwan Thamir
2024-06-18 11:51:20 +00:00
committed by GitHub
parent cfa983001b
commit 288e41856b
18 changed files with 350 additions and 135 deletions
@@ -0,0 +1,65 @@
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,
}),
])
})
})
},
})