fix(pricing): PriceLists of type Sale should not override lower prices (#10882)
Resolves CMRC-840
This commit is contained in:
@@ -1172,6 +1172,89 @@ medusaIntegrationTestRunner({
|
||||
expect(response.data.products).toEqual(expectation)
|
||||
})
|
||||
|
||||
it("should list products with prices with a default price when the price list price is higher and the price list is of type SALE", async () => {
|
||||
const priceList = (
|
||||
await api.post(
|
||||
`/admin/price-lists`,
|
||||
{
|
||||
title: "test price list",
|
||||
description: "test",
|
||||
status: PriceListStatus.ACTIVE,
|
||||
type: PriceListType.SALE,
|
||||
prices: [
|
||||
{
|
||||
amount: 3500,
|
||||
currency_code: "usd",
|
||||
variant_id: product.variants[0].id,
|
||||
},
|
||||
],
|
||||
rules: { "customer.groups.id": [customerGroup.id] },
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
).data.price_list
|
||||
|
||||
let response = await api.get(
|
||||
`/store/products?fields=*variants.calculated_price®ion_id=${region.id}`,
|
||||
storeHeadersWithCustomer
|
||||
)
|
||||
|
||||
const expectation = expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: product.id,
|
||||
variants: [
|
||||
expect.objectContaining({
|
||||
calculated_price: {
|
||||
id: expect.any(String),
|
||||
is_calculated_price_price_list: false,
|
||||
is_calculated_price_tax_inclusive: false,
|
||||
calculated_amount: 3000,
|
||||
raw_calculated_amount: {
|
||||
value: "3000",
|
||||
precision: 20,
|
||||
},
|
||||
is_original_price_price_list: false,
|
||||
is_original_price_tax_inclusive: false,
|
||||
original_amount: 3000,
|
||||
raw_original_amount: {
|
||||
value: "3000",
|
||||
precision: 20,
|
||||
},
|
||||
currency_code: "usd",
|
||||
calculated_price: {
|
||||
id: expect.any(String),
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
},
|
||||
original_price: {
|
||||
id: expect.any(String),
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
])
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(3)
|
||||
expect(response.data.products).toEqual(expectation)
|
||||
|
||||
// with only region_id
|
||||
response = await api.get(
|
||||
`/store/products?region_id=${region.id}`,
|
||||
storeHeadersWithCustomer
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toEqual(expectation)
|
||||
})
|
||||
|
||||
it("should list products with prices with a override price list price", async () => {
|
||||
const priceList = (
|
||||
await api.post(
|
||||
@@ -1254,6 +1337,89 @@ medusaIntegrationTestRunner({
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toEqual(expectation)
|
||||
})
|
||||
|
||||
it("should list products with prices with a override price list price even if the price list price is higher than the default price", async () => {
|
||||
const priceList = (
|
||||
await api.post(
|
||||
`/admin/price-lists`,
|
||||
{
|
||||
title: "test price list",
|
||||
description: "test",
|
||||
status: PriceListStatus.ACTIVE,
|
||||
type: PriceListType.OVERRIDE,
|
||||
prices: [
|
||||
{
|
||||
amount: 35000,
|
||||
currency_code: "usd",
|
||||
variant_id: product.variants[0].id,
|
||||
},
|
||||
],
|
||||
rules: { "customer.groups.id": [customerGroup.id] },
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
).data.price_list
|
||||
|
||||
let response = await api.get(
|
||||
`/store/products?fields=*variants.calculated_price®ion_id=${region.id}`,
|
||||
storeHeadersWithCustomer
|
||||
)
|
||||
|
||||
const expectation = expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: product.id,
|
||||
variants: [
|
||||
expect.objectContaining({
|
||||
calculated_price: {
|
||||
id: expect.any(String),
|
||||
is_calculated_price_price_list: true,
|
||||
is_calculated_price_tax_inclusive: false,
|
||||
calculated_amount: 35000,
|
||||
raw_calculated_amount: {
|
||||
value: "35000",
|
||||
precision: 20,
|
||||
},
|
||||
is_original_price_price_list: true,
|
||||
is_original_price_tax_inclusive: false,
|
||||
original_amount: 35000,
|
||||
raw_original_amount: {
|
||||
value: "35000",
|
||||
precision: 20,
|
||||
},
|
||||
currency_code: "usd",
|
||||
calculated_price: {
|
||||
id: expect.any(String),
|
||||
price_list_id: priceList.id,
|
||||
price_list_type: "override",
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
},
|
||||
original_price: {
|
||||
id: expect.any(String),
|
||||
price_list_id: priceList.id,
|
||||
price_list_type: "override",
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
])
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(3)
|
||||
expect(response.data.products).toEqual(expectation)
|
||||
|
||||
// with only region_id
|
||||
response = await api.get(
|
||||
`/store/products?region_id=${region.id}`,
|
||||
storeHeadersWithCustomer
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toEqual(expectation)
|
||||
})
|
||||
})
|
||||
|
||||
describe("with inventory items", () => {
|
||||
|
||||
Reference in New Issue
Block a user