feat:Allow updating prices through product update workflow (#8316)

* feat:Allow updating prices through product update workflow

* fix:Changes based on PR feedback
This commit is contained in:
Stevche Radevski
2024-07-29 19:56:03 +03:00
committed by GitHub
parent ed67d44d28
commit e98012a858
9 changed files with 382 additions and 27 deletions
@@ -217,7 +217,20 @@ medusaIntegrationTestRunner({
title: "Test variant 2",
allow_backorder: false,
manage_inventory: true,
// TODO: Since we are doing a product update, there won't be any prices created for the variant
prices: [
expect.objectContaining({
currency_code: "usd",
amount: 200,
}),
expect.objectContaining({
currency_code: "eur",
amount: 65,
}),
expect.objectContaining({
currency_code: "dkk",
amount: 50,
}),
],
options: [
expect.objectContaining({
value: "small",
@@ -1390,7 +1390,20 @@ medusaIntegrationTestRunner({
barcode: "test-barcode",
ean: "test-ean",
upc: "test-upc",
// BREAKING: Price updates are no longer supported through the product update endpoint. There is a batch variants endpoint for this purpose
prices: [
{
currency_code: "usd",
amount: 200,
},
{
currency_code: "eur",
amount: 65,
},
{
currency_code: "dkk",
amount: 50,
},
],
},
],
tags: [{ value: "123" }],
@@ -1478,10 +1491,20 @@ medusaIntegrationTestRunner({
origin_country: null,
prices: expect.arrayContaining([
expect.objectContaining({
amount: 100,
amount: 200,
created_at: expect.any(String),
currency_code: "usd",
}),
expect.objectContaining({
amount: 65,
created_at: expect.any(String),
currency_code: "eur",
}),
expect.objectContaining({
amount: 50,
created_at: expect.any(String),
currency_code: "dkk",
}),
]),
product_id: baseProduct.id,
title: "New variant",
@@ -1492,6 +1515,88 @@ medusaIntegrationTestRunner({
)
})
it("updates product variants (update price on existing variant, create new variant)", async () => {
const payload = {
variants: [
{
id: baseProduct.variants[0].id,
prices: [
{
currency_code: "usd",
amount: 200,
},
{
currency_code: "dkk",
amount: 50,
},
],
},
{
title: "New variant",
prices: [
{
currency_code: "usd",
amount: 150,
},
{
currency_code: "dkk",
amount: 20,
},
],
},
],
}
const response = await api
.post(`/admin/products/${baseProduct.id}`, payload, adminHeaders)
.catch((err) => {
console.log(err)
})
expect(response.status).toEqual(200)
expect(response.data.product).toEqual(
expect.objectContaining({
id: baseProduct.id,
variants: expect.arrayContaining([
expect.objectContaining({
id: baseProduct.variants[0].id,
prices: expect.arrayContaining([
expect.objectContaining({
amount: 200,
created_at: expect.any(String),
currency_code: "usd",
}),
expect.objectContaining({
amount: 50,
created_at: expect.any(String),
currency_code: "dkk",
}),
]),
product_id: baseProduct.id,
}),
expect.objectContaining({
id: expect.any(String),
title: "New variant",
prices: expect.arrayContaining([
expect.objectContaining({
amount: 150,
created_at: expect.any(String),
currency_code: "usd",
}),
expect.objectContaining({
amount: 20,
created_at: expect.any(String),
currency_code: "dkk",
}),
]),
product_id: baseProduct.id,
}),
]),
})
)
})
it("updates product (removes images when empty array included)", async () => {
const payload = {
images: [],