feat(medusa,core-flows): update cart adjustments on item updates (#6539)

This commit is contained in:
Riqwan Thamir
2024-02-29 00:05:24 +05:30
committed by GitHub
parent adad66e13f
commit 557d86afbf
10 changed files with 145 additions and 61 deletions

View File

@@ -134,7 +134,6 @@ describe("Store Carts API: Add promotions to cart", () => {
id: "item-1",
adjustments: expect.arrayContaining([
expect.objectContaining({
promotion_id: createdPromotion.id,
code: createdPromotion.code,
amount: 1000,
}),
@@ -144,7 +143,6 @@ describe("Store Carts API: Add promotions to cart", () => {
adjustments: expect.arrayContaining([
expect.objectContaining({
id: expect.not.stringContaining(lineItemAdjustment.id),
promotion_id: appliedPromotion.id,
code: appliedPromotion.code,
amount: 300,
}),

View File

@@ -557,10 +557,6 @@ describe("Store Carts API", () => {
describe("POST /store/carts/:id/line-items", () => {
it("should add item to cart", async () => {
const cart = await cartModuleService.create({
currency_code: "usd",
})
const [product] = await productModule.create([
{
title: "Test product",
@@ -572,6 +568,48 @@ describe("Store Carts API", () => {
},
])
const cart = await cartModuleService.create({
currency_code: "usd",
items: [
{
id: "item-1",
unit_price: 2000,
quantity: 1,
title: "Test item",
product_id: "prod_mat",
} as any,
],
})
const appliedPromotion = await promotionModule.create({
code: "PROMOTION_APPLIED",
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "items",
allocation: "across",
value: "300",
apply_to_quantity: 2,
target_rules: [
{
attribute: "product_id",
operator: "in",
values: ["prod_mat", product.id],
},
],
},
})
const [lineItemAdjustment] =
await cartModuleService.addLineItemAdjustments([
{
code: appliedPromotion.code!,
amount: 300,
item_id: "item-1",
promotion_id: appliedPromotion.id,
},
])
const priceSet = await pricingModule.create({
prices: [
{
@@ -608,6 +646,24 @@ describe("Store Carts API", () => {
unit_price: 3000,
quantity: 1,
title: "Test variant",
adjustments: [
expect.objectContaining({
code: "PROMOTION_APPLIED",
amount: 180,
}),
],
}),
expect.objectContaining({
unit_price: 2000,
quantity: 1,
title: "Test item",
adjustments: [
expect.objectContaining({
id: expect.not.stringContaining(lineItemAdjustment.id),
code: "PROMOTION_APPLIED",
amount: 120,
}),
],
}),
]),
})