chore: adds test for inventory item creation as part of product creation (#5312)

* chore: adds test for inventory item creation as part of product creation

* chore: remove only
This commit is contained in:
Sebastian Rindom
2023-10-09 14:24:11 -07:00
committed by GitHub
parent 074055acbb
commit 4ebcd3af6a

View File

@@ -370,5 +370,62 @@ describe("/admin/products", () => {
})
)
})
it("should create variants with inventory items", async () => {
const api = useApi()! as AxiosInstance
const response = await api.post(
`/admin/products`,
{
title: "Test product - 1",
description: "test-product-description 1",
type: { value: "test-type 1" },
images: ["test-image.png", "test-image-2.png"],
collection_id: "test-collection",
tags: [{ value: "123" }, { value: "456" }],
options: [{ title: "size" }, { title: "color" }],
variants: [
{
title: "Test variant 1",
inventory_quantity: 10,
prices: [{ currency_code: "usd", amount: 100 }],
options: [{ value: "large" }, { value: "green" }],
},
{
title: "Test variant 2",
inventory_quantity: 10,
prices: [{ currency_code: "usd", amount: 100 }],
options: [{ value: "large" }, { value: "green" }],
},
],
},
{ headers: { "x-medusa-access-token": "test_token" } }
)
expect(response.status).toEqual(200)
const variantIds = response.data.product.variants.map(
(v: { id: string }) => v.id
)
const variantInventoryService = medusaContainer.resolve(
"productVariantInventoryService"
)
const inventory = await variantInventoryService.listByVariant(variantIds)
expect(inventory).toHaveLength(2)
expect(inventory).toContainEqual(
expect.objectContaining({
variant_id: variantIds[0],
required_quantity: 1,
})
)
expect(inventory).toContainEqual(
expect.objectContaining({
variant_id: variantIds[1],
required_quantity: 1,
})
)
})
})
})