fix(core-flows): variants update unsets prices (#11349)
* fix: update variant flow for prices * fix: import add test * fix: test name
This commit is contained in:
@@ -3182,6 +3182,103 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
|
||||
it("should preserve variant prices when batch updating variants", async () => {
|
||||
const productWithMultipleVariants = getProductFixture({
|
||||
title: "Test batch variants",
|
||||
handle: "test-batch-variants",
|
||||
shipping_profile_id: shippingProfile.id,
|
||||
variants: [
|
||||
{
|
||||
title: "Variant 1",
|
||||
prices: [
|
||||
{
|
||||
currency_code: "usd",
|
||||
amount: 100,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Variant 2",
|
||||
prices: [
|
||||
{
|
||||
currency_code: "usd",
|
||||
amount: 200,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const createdProduct = (
|
||||
await api.post(
|
||||
"/admin/products",
|
||||
productWithMultipleVariants,
|
||||
adminHeaders
|
||||
)
|
||||
).data.product
|
||||
|
||||
const variant1Id = createdProduct.variants.find(
|
||||
(v) => v.title === "Variant 1"
|
||||
).id
|
||||
|
||||
const variant2Id = createdProduct.variants.find(
|
||||
(v) => v.title === "Variant 2"
|
||||
).id
|
||||
|
||||
const updatePayload1 = {
|
||||
id: variant1Id,
|
||||
title: "Test batch update variant",
|
||||
}
|
||||
|
||||
const updatePayload2 = {
|
||||
id: variant2Id,
|
||||
prices: [{ currency_code: "usd", amount: 300 }],
|
||||
}
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/products/${createdProduct.id}/variants/batch`,
|
||||
{
|
||||
update: [updatePayload1, updatePayload2],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const dbData = (
|
||||
await api.get(
|
||||
`/admin/products/${createdProduct.id}?fields=*variants.prices`,
|
||||
adminHeaders
|
||||
)
|
||||
).data.product.variants
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(dbData).toHaveLength(2)
|
||||
expect(dbData).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: variant1Id,
|
||||
title: "Test batch update variant",
|
||||
prices: expect.arrayContaining([
|
||||
// updated title but price remains the same
|
||||
expect.objectContaining({
|
||||
currency_code: "usd",
|
||||
amount: 100,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: variant2Id,
|
||||
prices: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
// updated price
|
||||
currency_code: "usd",
|
||||
amount: 300,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("successfully adds and removes products to a collection", async () => {
|
||||
const response = await api.post(
|
||||
`/admin/collections/${baseCollection.id}/products`,
|
||||
|
||||
Reference in New Issue
Block a user