fix:Product options were not preserved over updates (#8267)

This commit is contained in:
Stevche Radevski
2024-07-25 08:24:26 +02:00
committed by GitHub
parent f7d1cd259e
commit 44f593a7ca
3 changed files with 95 additions and 2 deletions

View File

@@ -264,6 +264,90 @@ moduleIntegrationTestRunner<IProductModuleService>({
)
})
it("should preserve option and value identity on update", async () => {
const productBefore = await service.retrieveProduct(productTwo.id, {
relations: [
"images",
"variants",
"options",
"options.values",
"variants.options",
"tags",
"type",
],
})
const updatedProducts = await service.upsertProducts([
{
id: productBefore.id,
title: "updated title",
options: [
{
title: "size",
values: ["large", "small"],
},
{
title: "color",
values: ["red"],
},
{
title: "material",
values: ["cotton"],
},
],
},
])
expect(updatedProducts).toHaveLength(1)
const product = await service.retrieveProduct(productBefore.id, {
relations: [
"images",
"variants",
"options",
"options.values",
"variants.options",
"tags",
"type",
],
})
const beforeOption = productBefore.options.find(
(opt) => opt.title === "size"
)!
expect(product.options).toHaveLength(3)
expect(product.options).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: beforeOption.id,
title: beforeOption.title,
values: expect.arrayContaining([
expect.objectContaining({
id: beforeOption.values[0].id,
value: beforeOption.values[0].value,
}),
]),
}),
expect.objectContaining({
title: "color",
values: expect.arrayContaining([
expect.objectContaining({
value: "red",
}),
]),
}),
expect.objectContaining({
id: expect.any(String),
title: "material",
values: expect.arrayContaining([
expect.objectContaining({
value: "cotton",
}),
]),
}),
])
)
})
it("should emit events through event bus", async () => {
const eventBusSpy = jest.spyOn(MockEventBusService.prototype, "emit")
const data = buildProductAndRelationsData({