fix(dashboard, product): product attributes update with a relation update (#13019)
* fix(dashboard, product): product attributes update with a relation update * fix: rm log * chore: refactor
This commit is contained in:
@@ -1813,6 +1813,110 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
|
||||
it("updates products relations and attributes", async () => {
|
||||
const shortsCategory = (
|
||||
await api.post(
|
||||
"/admin/product-categories",
|
||||
{ name: "Shorts", is_internal: false, is_active: true },
|
||||
adminHeaders
|
||||
)
|
||||
).data.product_category
|
||||
|
||||
const pantsCategory = (
|
||||
await api.post(
|
||||
"/admin/product-categories",
|
||||
{ name: "Pants", is_internal: false, is_active: true },
|
||||
adminHeaders
|
||||
)
|
||||
).data.product_category
|
||||
|
||||
const payload = {
|
||||
title: "Test an update",
|
||||
weight: 100,
|
||||
length: 100,
|
||||
width: 100,
|
||||
height: 100,
|
||||
options: [{ title: "size", values: ["large", "small"] }],
|
||||
variants: [
|
||||
{
|
||||
options: { size: "large" },
|
||||
title: "New variant",
|
||||
prices: [
|
||||
{
|
||||
currency_code: "usd",
|
||||
amount: 200,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const createdProduct = (
|
||||
await api.post("/admin/products", payload, adminHeaders)
|
||||
).data.product
|
||||
|
||||
let updatedProduct = (
|
||||
await api.post(
|
||||
`/admin/products/${createdProduct.id}`,
|
||||
{ weight: 20, length: null },
|
||||
adminHeaders
|
||||
)
|
||||
).data.product
|
||||
|
||||
expect(updatedProduct).toEqual(
|
||||
expect.objectContaining({
|
||||
weight: "20",
|
||||
length: null,
|
||||
width: "100",
|
||||
height: "100",
|
||||
})
|
||||
)
|
||||
|
||||
updatedProduct = (
|
||||
await api.post(
|
||||
`/admin/products/${createdProduct.id}?fields=+categories.id`,
|
||||
{ categories: [{ id: pantsCategory.id }] },
|
||||
adminHeaders
|
||||
)
|
||||
).data.product
|
||||
|
||||
expect(updatedProduct).toEqual(
|
||||
expect.objectContaining({
|
||||
weight: "20",
|
||||
length: null,
|
||||
width: "100",
|
||||
height: "100",
|
||||
categories: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: pantsCategory.id,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
updatedProduct = (
|
||||
await api.post(
|
||||
`/admin/products/${createdProduct.id}?fields=+categories.id`,
|
||||
{ weight: null, length: 20, width: 50 },
|
||||
adminHeaders
|
||||
)
|
||||
).data.product
|
||||
|
||||
expect(updatedProduct).toEqual(
|
||||
expect.objectContaining({
|
||||
weight: null,
|
||||
length: "20",
|
||||
width: "50",
|
||||
height: "100",
|
||||
categories: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: pantsCategory.id,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("updates a product (update prices, tags, update status, delete collection, delete type, replaces images)", async () => {
|
||||
const payload = {
|
||||
collection_id: null,
|
||||
|
||||
Reference in New Issue
Block a user