Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Jan 10, 2023
1 parent f9c3d09 commit 5aeb5fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/medusa/src/services/__tests__/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ describe("CartService", () => {
{
id: IdMap.getId("test-session"),
provider_id: "test-provider",
is_selected: true,
is_initiated: true,
},
],
})
Expand Down Expand Up @@ -1559,7 +1559,7 @@ describe("CartService", () => {
shipping_methods: [],
payment_sessions: [
{ provider_id: provider1Id, is_initiated: true },
{ provider_id: provider2Id, is_selected: true },
{ provider_id: provider2Id, is_selected: true, is_initiated: true },
],
region: {
payment_providers: [{ id: provider1Id }, { id: provider2Id }],
Expand Down
19 changes: 16 additions & 3 deletions packages/medusa/src/services/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,7 @@ class CartService extends TransactionBaseService {
alreadyConsumedProviderIds.add(session.provider_id)

// Update remotely
if (session.is_selected) {
if (session.is_selected && session.is_initiated) {
const paymentSessionInput = {
...partialSessionInput,
provider_id: session.provider_id,
Expand All @@ -1857,8 +1857,21 @@ class CartService extends TransactionBaseService {
)
}

session.amount = total
return psRepo.save(session)
let updatedSession: PaymentSession

// At this stage the session is not selected. Delete it remotely if there is some
// external provider data and create the session locally only. Otherwise, update the existing local session.
if (session.is_initiated) {
await paymentProviderServiceTx.deleteSession(session)
updatedSession = psRepo.create({
...partialPaymentSessionData,
provider_id: session.provider_id,
})
} else {
updatedSession = { ...session, amount: total } as PaymentSession
}

return psRepo.save(updatedSession)
})
)

Expand Down

0 comments on commit 5aeb5fb

Please sign in to comment.