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
@@ -27,18 +27,23 @@ medusaIntegrationTestRunner({
})
describe("createPaymentSessionWorkflow", () => {
it("should create payment sessions", async () => {
const region = await regionModule.create({
let region
let paymentCollection
beforeEach(async () => {
region = await regionModule.create({
currency_code: "usd",
name: "US",
})
let paymentCollection = await paymentModule.createPaymentCollections({
paymentCollection = await paymentModule.createPaymentCollections({
currency_code: "usd",
amount: 1000,
region_id: region.id,
})
})
it("should create payment sessions", async () => {
await createPaymentSessionsWorkflow(appContainer).run({
input: {
payment_collection_id: paymentCollection.id,
@@ -72,6 +77,47 @@ medusaIntegrationTestRunner({
)
})
it("should delete existing sessions when create payment sessions", async () => {
await createPaymentSessionsWorkflow(appContainer).run({
input: {
payment_collection_id: paymentCollection.id,
provider_id: "pp_system_default",
context: {},
data: {},
},
})
await createPaymentSessionsWorkflow(appContainer).run({
input: {
payment_collection_id: paymentCollection.id,
provider_id: "pp_system_default",
context: {},
data: {},
},
})
paymentCollection = await paymentModule.retrievePaymentCollection(
paymentCollection.id,
{ relations: ["payment_sessions"] }
)
expect(paymentCollection).toEqual(
expect.objectContaining({
id: paymentCollection.id,
currency_code: "usd",
amount: 1000,
region_id: region.id,
payment_sessions: [
expect.objectContaining({
amount: 1000,
currency_code: "usd",
provider_id: "pp_system_default",
}),
],
})
)
})
describe("compensation", () => {
it("should delete created payment collection if a subsequent step fails", async () => {
const workflow = createPaymentSessionsWorkflow(appContainer)