fix(medusa): allow price list prices update when region_id is provided (#1472)

This commit is contained in:
Frane Polić
2022-05-11 07:43:19 +02:00
committed by GitHub
parent 327614e126
commit 03c5617896
4 changed files with 279 additions and 4 deletions
@@ -149,6 +149,37 @@ Object {
}
`;
exports[`/admin/price-lists POST /admin/price-lists/:id updates price list prices (inser a new MA for a specific region) 1`] = `
Array [
Object {
"amount": 101,
"created_at": Any<String>,
"currency_code": "eur",
"deleted_at": null,
"id": Any<String>,
"max_quantity": null,
"min_quantity": null,
"price_list_id": "pl_with_some_ma",
"region_id": "region-pl",
"updated_at": Any<String>,
"variant_id": "test-variant",
},
Object {
"amount": 1001,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": "ma_test_4",
"max_quantity": null,
"min_quantity": null,
"price_list_id": "pl_with_some_ma",
"region_id": null,
"updated_at": Any<String>,
"variant_id": "test-variant",
},
]
`;
exports[`/admin/price-lists POST /admin/price-lists/:id updates the amount and currency of a price in the price list 1`] = `
Object {
"amount": 250,
@@ -291,3 +322,47 @@ Array [
},
]
`;
exports[`/admin/price-lists POST /admin/price-lists/:id/prices/batch Adds a batch of new prices where a MA record have a \`region_id\` instead of \`currency_code\` 1`] = `
Array [
Object {
"amount": 70,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": "ma_test_4",
"max_quantity": null,
"min_quantity": null,
"price_list_id": "pl_with_some_ma",
"region_id": null,
"updated_at": Any<String>,
"variant_id": "test-variant",
},
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "eur",
"deleted_at": null,
"id": Any<String>,
"max_quantity": null,
"min_quantity": null,
"price_list_id": "pl_with_some_ma",
"region_id": "region-pl",
"updated_at": Any<String>,
"variant_id": "test-variant",
},
Object {
"amount": 200,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": Any<String>,
"max_quantity": null,
"min_quantity": null,
"price_list_id": "pl_with_some_ma",
"region_id": null,
"updated_at": Any<String>,
"variant_id": "test-variant",
},
]
`;
@@ -509,6 +509,68 @@ describe("/admin/price-lists", () => {
updated_at: expect.any(String),
})
})
it("updates price list prices (inser a new MA for a specific region)", async () => {
const api = useApi()
const payload = {
prices: [
// update MA
{
id: "ma_test_4",
amount: 1001,
currency_code: "usd",
variant_id: "test-variant",
},
// create MA
{
amount: 101,
variant_id: "test-variant",
region_id: "region-pl",
},
],
}
const response = await api
.post("/admin/price-lists/pl_with_some_ma", payload, {
headers: {
Authorization: "Bearer test_token",
},
})
.catch((err) => {
console.warn(err.response.data)
})
expect(response.status).toEqual(200)
expect(response.data.price_list.prices.length).toEqual(2)
expect(response.data.price_list.prices).toMatchSnapshot([
{
id: expect.any(String),
currency_code: "eur",
amount: 101,
min_quantity: null,
max_quantity: null,
price_list_id: "pl_with_some_ma",
variant_id: "test-variant",
region_id: "region-pl",
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
},
{
id: "ma_test_4",
currency_code: "usd",
amount: 1001,
price_list_id: "pl_with_some_ma",
variant_id: "test-variant",
region_id: null,
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
},
])
})
})
describe("POST /admin/price-lists/:id/prices/batch", () => {
@@ -573,7 +635,9 @@ describe("/admin/price-lists", () => {
expect(response.status).toEqual(200)
expect(response.data.price_list.prices.length).toEqual(6)
expect(response.data.price_list.prices).toMatchSnapshot([
expect(
response.data.price_list.prices.sort((a, b) => b.amount - a.amount)
).toMatchSnapshot([
{
id: expect.any(String),
price_list_id: "pl_no_customer_groups",
@@ -725,6 +789,78 @@ describe("/admin/price-lists", () => {
},
])
})
it("Adds a batch of new prices where a MA record have a `region_id` instead of `currency_code`", async () => {
const api = useApi()
const payload = {
prices: [
{
amount: 100,
variant_id: "test-variant",
region_id: "region-pl",
},
{
amount: 200,
variant_id: "test-variant",
currency_code: "usd",
},
],
}
const response = await api
.post("/admin/price-lists/pl_with_some_ma/prices/batch", payload, {
headers: {
Authorization: "Bearer test_token",
},
})
.catch((err) => {
console.warn(err.response.data)
})
expect(response.status).toEqual(200)
expect(response.data.price_list.prices.length).toEqual(3) // initially this PL has 1 MA record
expect(response.data.price_list.prices).toMatchSnapshot([
{
id: "ma_test_4",
currency_code: "usd",
amount: 70,
price_list_id: "pl_with_some_ma",
variant_id: "test-variant",
region_id: null,
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
},
{
id: expect.any(String),
currency_code: "eur",
amount: 100,
min_quantity: null,
max_quantity: null,
price_list_id: "pl_with_some_ma",
variant_id: "test-variant",
region_id: "region-pl",
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
},
{
id: expect.any(String),
currency_code: "usd",
amount: 200,
min_quantity: null,
max_quantity: null,
price_list_id: "pl_with_some_ma",
variant_id: "test-variant",
region_id: null,
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
},
])
})
})
describe("DELETE /admin/price-lists/:id", () => {