fix(core-flows): refresh payment collection inside updateCartPromotionsWorkflow (patch) (#14274)
* Refresh payment collection after cart promotion update * Add missing test * Add changeset * Update changeset * Add force_refresh_payment_collection to updateCartPromotionsWorkflow to conditionally refresh payment collection * Prevent refreshing payment collection multiple times * Fix test * Formatting and unused vars * Force refresh payment collection on dedicated store cart promotion endpoints --------- Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
2 files changed
+89
-5
No files matched your search
@@ -5299,6 +5299,73 @@ medusaIntegrationTestRunner({
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("POST /store/carts/:id/promotions", () => {
|
||||||
|
it("should add promotions and refresh payment collection", async () => {
|
||||||
|
cart = (
|
||||||
|
await api.post(
|
||||||
|
`/store/carts`,
|
||||||
|
{
|
||||||
|
currency_code: "usd",
|
||||||
|
sales_channel_id: salesChannel.id,
|
||||||
|
region_id: region.id,
|
||||||
|
shipping_address: shippingAddressData,
|
||||||
|
items: [{ variant_id: product.variants[0].id, quantity: 1 }],
|
||||||
|
},
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
).data.cart
|
||||||
|
|
||||||
|
const paymentCollection = (
|
||||||
|
await api.post(
|
||||||
|
`/store/payment-collections`,
|
||||||
|
{ cart_id: cart.id },
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
).data.payment_collection
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/store/payment-collections/${paymentCollection.id}/payment-sessions`,
|
||||||
|
{ provider_id: "pp_system_default" },
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
cart = (await api.get(`/store/carts/${cart.id}`, storeHeaders)).data
|
||||||
|
.cart
|
||||||
|
expect(cart.total).toEqual(1500)
|
||||||
|
expect(cart.payment_collection.amount).toEqual(1500)
|
||||||
|
|
||||||
|
const cartAfterPromotion = (
|
||||||
|
await api.post(
|
||||||
|
`/store/carts/${cart.id}/promotions`,
|
||||||
|
{ promo_codes: [promotion.code] },
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
).data.cart
|
||||||
|
|
||||||
|
expect(cartAfterPromotion).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: cart.id,
|
||||||
|
total: 1395,
|
||||||
|
discount_total: 105,
|
||||||
|
payment_collection: expect.objectContaining({
|
||||||
|
amount: 1395,
|
||||||
|
}),
|
||||||
|
items: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
adjustments: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
code: "PROMOTION_APPLIED",
|
||||||
|
promotion_id: promotion.id,
|
||||||
|
amount: 100,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("DELETE /store/carts/:id/promotions", () => {
|
describe("DELETE /store/carts/:id/promotions", () => {
|
||||||
it("should remove promotions and recalculate payment_collection amount", async () => {
|
it("should remove promotions and recalculate payment_collection amount", async () => {
|
||||||
cart = (
|
cart = (
|
||||||
@@ -5316,9 +5383,17 @@ medusaIntegrationTestRunner({
|
|||||||
)
|
)
|
||||||
).data.cart
|
).data.cart
|
||||||
|
|
||||||
|
const paymentCollection = await api
|
||||||
|
.post(
|
||||||
|
`/store/payment-collections`,
|
||||||
|
{ cart_id: cart.id },
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
.then((response) => response.data.payment_collection)
|
||||||
|
|
||||||
await api.post(
|
await api.post(
|
||||||
`/store/payment-collections`,
|
`/store/payment-collections/${paymentCollection.id}/payment-sessions`,
|
||||||
{ cart_id: cart.id },
|
{ provider_id: "pp_system_default" },
|
||||||
storeHeaders
|
storeHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -5328,6 +5403,11 @@ medusaIntegrationTestRunner({
|
|||||||
expect(cart).toEqual(
|
expect(cart).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: cart.id,
|
id: cart.id,
|
||||||
|
total: 1395,
|
||||||
|
discount_total: 105,
|
||||||
|
payment_collection: expect.objectContaining({
|
||||||
|
amount: 1395,
|
||||||
|
}),
|
||||||
items: expect.arrayContaining([
|
items: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
adjustments: expect.arrayContaining([
|
adjustments: expect.arrayContaining([
|
||||||
@@ -5352,6 +5432,11 @@ medusaIntegrationTestRunner({
|
|||||||
expect(cartAfterDeletion).toEqual(
|
expect(cartAfterDeletion).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: cart.id,
|
id: cart.id,
|
||||||
|
total: 1500,
|
||||||
|
discount_total: 0,
|
||||||
|
payment_collection: expect.objectContaining({
|
||||||
|
amount: 1500,
|
||||||
|
}),
|
||||||
items: expect.arrayContaining([
|
items: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
adjustments: [],
|
adjustments: [],
|
||||||
@@ -5359,9 +5444,6 @@ medusaIntegrationTestRunner({
|
|||||||
]),
|
]),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(cartAfterDeletion.total).toEqual(1500)
|
|
||||||
expect(cartAfterDeletion.discount_total).toEqual(0)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export const POST = async (
|
|||||||
payload.promo_codes.length > 0
|
payload.promo_codes.length > 0
|
||||||
? PromotionActions.ADD
|
? PromotionActions.ADD
|
||||||
: PromotionActions.REPLACE,
|
: PromotionActions.REPLACE,
|
||||||
|
force_refresh_payment_collection: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -48,6 +49,7 @@ export const DELETE = async (
|
|||||||
promo_codes: payload.promo_codes,
|
promo_codes: payload.promo_codes,
|
||||||
cart_id: req.params.id,
|
cart_id: req.params.id,
|
||||||
action: PromotionActions.REMOVE,
|
action: PromotionActions.REMOVE,
|
||||||
|
force_refresh_payment_collection: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user