fix(core-flows): refresh payment collection inside updateCartPromotionsWorkflow (#13963)
* 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 --------- Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>
This commit is contained in:
@@ -5299,6 +5299,72 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
})
|
||||
|
||||
describe("DELETE /store/carts/:id/promotions", () => {
|
||||
it("should remove promotions and recalculate payment_collection amount", 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 }],
|
||||
promo_codes: [promotion.code],
|
||||
},
|
||||
storeHeaders
|
||||
)
|
||||
).data.cart
|
||||
|
||||
await api.post(
|
||||
`/store/payment-collections`,
|
||||
{ cart_id: cart.id },
|
||||
storeHeaders
|
||||
)
|
||||
|
||||
cart = (await api.get(`/store/carts/${cart.id}`, storeHeaders)).data
|
||||
.cart
|
||||
|
||||
expect(cart).toEqual(
|
||||
expect.objectContaining({
|
||||
id: cart.id,
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
adjustments: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "PROMOTION_APPLIED",
|
||||
promotion_id: promotion.id,
|
||||
amount: 100,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
const cartAfterDeletion = await api
|
||||
.delete(`/store/carts/${cart.id}/promotions`, {
|
||||
data: { promo_codes: [promotion.code] },
|
||||
...storeHeaders,
|
||||
})
|
||||
.then((response) => response.data.cart)
|
||||
|
||||
expect(cartAfterDeletion).toEqual(
|
||||
expect.objectContaining({
|
||||
id: cart.id,
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
adjustments: [],
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
expect(cartAfterDeletion.total).toEqual(1500)
|
||||
expect(cartAfterDeletion.discount_total).toEqual(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /store/carts/:id/customer", () => {
|
||||
beforeEach(async () => {
|
||||
cart = (
|
||||
|
||||
Reference in New Issue
Block a user