feat: Add variant creation and editing in the products UI (#6997)

This commit is contained in:
Stevche Radevski authored and GitHub committed 2024-04-08 09:32:12 +02:00
1 parent 5e953f8cf3
commit 2a0e010f73
6 files changed
+496 -176

No files matched your search

@@ -26,7 +26,7 @@ moduleIntegrationTestRunner({
options: [
{
title: "size",
values: ["large"],
values: ["large", "small"],
},
],
})
@@ -169,6 +169,54 @@ moduleIntegrationTestRunner({
})
})
describe("updateVariants", () => {
it("should update the title of the variant successfully", async () => {
await service.upsertVariants([
{
id: variantOne.id,
title: "new test",
},
])
const productVariant = await service.retrieveVariant(variantOne.id)
expect(productVariant.title).toEqual("new test")
})
it("should update the options of a variant successfully", async () => {
await service.upsertVariants([
{
id: variantOne.id,
options: { size: "small" },
},
])
const productVariant = await service.retrieveVariant(variantOne.id, {
relations: ["options", "options.option_value", "options.variant"],
})
expect(productVariant.options).toEqual(
expect.arrayContaining([
expect.objectContaining({
option_value: expect.objectContaining({ value: "small" }),
}),
])
)
})
it("should throw an error when an id does not exist", async () => {
let error
try {
await service.updateVariants("does-not-exist", {})
} catch (e) {
error = e
}
expect(error.message).toEqual(
`Cannot update non-existing variants with ids: does-not-exist`
)
})
})
describe("softDelete variant", () => {
it("should soft delete a variant and its relations", async () => {
const beforeDeletedVariants = await service.listVariants(
@@ -385,7 +385,7 @@ export default class ProductModuleService<
new Set(variantsWithProductId.map((v) => v.product_id!))
),
},
{ take: null },
{ take: null, relations: ["values"] },
sharedContext
)
@@ -1204,7 +1204,7 @@ export default class ProductModuleService<
if (product.variants?.length) {
allOptions = await this.productOptionService_.list(
{ product_id: upsertedProduct.id },
{ take: null },
{ take: null, relations: ["values"] },
sharedContext
)
}