fix: Fixes to product module and improving tests (#6898)

This commit is contained in:
Stevche Radevski
2024-04-02 07:13:46 +00:00
committed by GitHub
parent b2763647f7
commit b3ce13d61e
8 changed files with 133 additions and 251 deletions
@@ -19,35 +19,38 @@ moduleIntegrationTestRunner({
let productTwo: Product
beforeEach(async () => {
const testManager = await MikroOrmWrapper.forkManager()
productOne = testManager.create(Product, {
productOne = await service.create({
id: "product-1",
title: "product 1",
status: ProductTypes.ProductStatus.PUBLISHED,
options: [
{
title: "size",
values: ["large"],
},
],
})
productTwo = testManager.create(Product, {
productTwo = await service.create({
id: "product-2",
title: "product 2",
status: ProductTypes.ProductStatus.PUBLISHED,
})
variantOne = testManager.create(ProductVariant, {
variantOne = await service.createVariants({
id: "test-1",
title: "variant 1",
inventory_quantity: 10,
product: productOne,
product_id: productOne.id,
options: { size: "large" },
})
variantTwo = testManager.create(ProductVariant, {
variantTwo = await service.createVariants({
id: "test-2",
title: "variant",
inventory_quantity: 10,
product: productTwo,
product_id: productTwo.id,
})
await testManager.persistAndFlush([variantOne, variantTwo])
})
describe("listAndCountVariants", () => {
@@ -165,6 +168,35 @@ moduleIntegrationTestRunner({
)
})
})
describe("softDelete variant", () => {
it("should soft delete a variant and its relations", async () => {
const beforeDeletedVariants = await service.listVariants(
{ id: variantOne.id },
{
relations: ["options", "options.option_value", "options.variant"],
}
)
await service.softDeleteVariants([variantOne.id])
const deletedVariants = await service.listVariants(
{ id: variantOne.id },
{
relations: ["options", "options.option_value", "options.variant"],
withDeleted: true,
}
)
expect(deletedVariants).toHaveLength(1)
expect(deletedVariants[0].deleted_at).not.toBeNull()
for (const variantOption of deletedVariants[0].options) {
expect(variantOption.deleted_at).not.toBeNull()
// The value itself should not be affected
expect(variantOption?.option_value?.deleted_at).toBeNull()
}
})
})
})
},
})
@@ -738,7 +738,6 @@ moduleIntegrationTestRunner({
relations: [
"variants",
"variants.options",
"variants.options",
"options",
"options.values",
],