fix:Product options were not preserved over updates (#8267)
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user