fix: Correctly associate options to variants (#8285)

This commit is contained in:
Stevche Radevski authored and GitHub committed 2024-07-25 17:56:13 +02:00
1 parent eb64ae75a6
commit 639ecdfd74
2 files changed
+67 -1

No files matched your search

@@ -328,6 +328,69 @@ moduleIntegrationTestRunner<IProductModuleService>({
}),
])
})
it("should correctly associate variants with own product options", async () => {
jest.clearAllMocks()
const productThree = await service.createProducts({
id: "product-3",
title: "product 3",
status: ProductStatus.PUBLISHED,
options: [
{
title: "size",
values: ["large", "small"],
},
{
title: "color",
values: ["red", "blue"],
},
],
} as CreateProductDTO)
const data: CreateProductVariantDTO[] = [
{
title: "new variant",
product_id: productOne.id,
options: { size: "small" },
},
{
title: "new variant",
product_id: productThree.id,
options: { size: "small" },
},
]
const variants = await service.createProductVariants(data)
expect(variants).toEqual(
expect.arrayContaining([
expect.objectContaining({
title: "new variant",
product_id: productOne.id,
options: expect.arrayContaining([
expect.objectContaining({
id: productOne.options
.find((o) => o.title === "size")
?.values?.find((v) => v.value === "small")?.id,
value: "small",
}),
]),
}),
expect.objectContaining({
title: "new variant",
product_id: productThree.id,
options: expect.arrayContaining([
expect.objectContaining({
id: productThree.options
.find((o) => o.title === "size")
?.values?.find((v) => v.value === "small")?.id,
value: "small",
}),
]),
}),
])
)
})
})
describe("softDelete variant", () => {