fix(promotion, types): non discountable items check (#12644)

* fix(promotions): check if item is discountable

* fix: return earl yonly if non discountable

* fix: update test

* chore: add integration test
This commit is contained in:
Frane Polić
2025-06-12 10:23:06 +02:00
committed by GitHub
parent 6be5750fe8
commit bd6d9777c5
5 changed files with 175 additions and 1 deletions

View File

@@ -2621,6 +2621,96 @@ medusaIntegrationTestRunner({
)
})
it("should only apply promotion on discountable items", async () => {
const notDiscountableProduct = (
await api.post(
"/admin/products",
{
title: "Medusa T-Shirt not discountable",
handle: "t-shirt-not-discountable",
discountable: false,
options: [
{
title: "Size",
values: ["S"],
},
],
variants: [
{
title: "S",
sku: "s-shirt",
options: {
Size: "S",
},
manage_inventory: false,
prices: [
{
amount: 1000,
currency_code: "usd",
},
],
},
],
shipping_profile_id: shippingProfile.id,
},
adminHeaders
)
).data.product
const cartData = {
currency_code: "usd",
sales_channel_id: salesChannel.id,
region_id: region.id,
shipping_address: shippingAddressData,
items: [
{ variant_id: product.variants[0].id, quantity: 1 },
{
variant_id: notDiscountableProduct.variants[0].id,
quantity: 1,
},
],
promo_codes: [promotion.code],
}
const cart = (
await api.post(
`/store/carts?fields=+items.is_discountable,+items.total,+items.discount_total`,
cartData,
storeHeaders
)
).data.cart
expect(cart).toEqual(
expect.objectContaining({
discount_subtotal: 100,
items: expect.arrayContaining([
expect.objectContaining({
variant_id: product.variants[0].id,
is_discountable: true,
unit_price: 1500,
total: 1395,
discount_total: 100,
adjustments: [
expect.objectContaining({
promotion_id: promotion.id,
amount: 100,
}),
],
}),
expect.objectContaining({
variant_id: notDiscountableProduct.variants[0].id,
is_discountable: false,
total: 1000,
unit_price: 1000,
discount_total: 0,
adjustments: [],
}),
]),
})
)
})
it("should remove promotion adjustments when promotion is deleted", async () => {
let cartBeforeRemovingPromotion = (
await api.get(`/store/carts/${cart.id}`, storeHeaders)