fix(product): returned updates order in upsertWithReplace (#12486)

* add failing test for upsertWithReplace order

* reproduce prices update shuffling issue

* fix: fix order of returned updates in updateMany

* fix: fix order of returned updates in ProductService

* fix: reset test count to 1

* Create tame-insects-marry.md

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Pedro Guzman
2025-05-15 09:22:24 +02:00
committed by GitHub
parent c661e06488
commit 142a1f0a5b
5 changed files with 182 additions and 16 deletions

View File

@@ -3325,6 +3325,130 @@ medusaIntegrationTestRunner({
})
)
})
// https://linear.app/medusajs/issue/SUP-1631/price-differences
it("should successfully handle successive updates on prices", async () => {
const response = await api.post(
"/admin/products/batch",
{
create: [
getProductFixture({
title: "title1",
variants: [
{
title: "variant1",
prices: [{ currency_code: "usd", amount: 100 }],
},
],
}),
getProductFixture({
title: "title2",
variants: [
{
title: "variant2",
prices: [{ currency_code: "usd", amount: 200 }],
},
],
}),
getProductFixture({
title: "title3",
variants: [
{
title: "variant3",
prices: [{ currency_code: "usd", amount: 300 }],
},
],
}),
],
update: [],
delete: [baseProduct.id],
},
adminHeaders
)
const created = response.data.created
const created1 = created.find((p) => p.title === "title1")
const created2 = created.find((p) => p.title === "title2")
const created3 = created.find((p) => p.title === "title3")
// Update the first and third product price to shuffle their order in the DB
await api.post(
`/admin/products/batch`,
{
update: [
{
id: created1.id,
variants: [
{
id: created1.variants[0].id,
prices: [{ currency_code: "usd", amount: 101 }],
},
],
},
{
id: created3.id,
variants: [
{
id: created3.variants[0].id,
prices: [{ currency_code: "usd", amount: 301 }],
},
],
},
],
},
adminHeaders
)
// Update all products now
await api.post(
`/admin/products/batch`,
{
update: [
{
id: created1.id,
variants: [
{
id: created1.variants[0].id,
prices: [{ currency_code: "usd", amount: 102 }],
},
],
},
{
id: created2.id,
variants: [
{
id: created2.variants[0].id,
prices: [{ currency_code: "usd", amount: 202 }],
},
],
},
{
id: created3.id,
variants: [
{
id: created3.variants[0].id,
prices: [{ currency_code: "usd", amount: 302 }],
},
],
},
],
},
adminHeaders
)
// Get the first product
const product1 = (
await api.get(`/admin/products/${created1.id}`, adminHeaders)
).data.product
const product2 = (
await api.get(`/admin/products/${created2.id}`, adminHeaders)
).data.product
const product3 = (
await api.get(`/admin/products/${created3.id}`, adminHeaders)
).data.product
expect(product1.variants[0].prices[0].amount).toEqual(102)
expect(product2.variants[0].prices[0].amount).toEqual(202)
expect(product3.variants[0].prices[0].amount).toEqual(302)
})
})
// TODO: Discuss how this should be handled