fix: Allow filtering products by variant options in store (#7784)

This commit is contained in:
Stevche Radevski
2024-06-21 10:42:09 +02:00
committed by GitHub
parent ee35379e21
commit 944051a951
6 changed files with 246 additions and 508 deletions
@@ -803,6 +803,8 @@ moduleIntegrationTestRunner<IProductModuleService>({
})
describe("list", function () {
let productOneData
let productTwoData
beforeEach(async () => {
const collections = await createCollections(
MikroOrmWrapper.forkManager(),
@@ -812,16 +814,20 @@ moduleIntegrationTestRunner<IProductModuleService>({
productCollectionOne = collections[0]
productCollectionTwo = collections[1]
const productOneData = buildProductAndRelationsData({
collection_id: productCollectionOne.id,
})
const resp = await service.createProducts([
buildProductAndRelationsData({
collection_id: productCollectionOne.id,
options: [{ title: "size", values: ["large", "small"] }],
variants: [{ title: "variant 1", options: { size: "small" } }],
}),
buildProductAndRelationsData({
collection_id: productCollectionTwo.id,
tags: [],
}),
])
const productTwoData = buildProductAndRelationsData({
collection_id: productCollectionTwo.id,
tags: [],
})
await service.createProducts([productOneData, productTwoData])
productOneData = resp[0]
productTwoData = resp[1]
})
it("should return a list of products scoped by collection id", async () => {
@@ -843,6 +849,29 @@ moduleIntegrationTestRunner<IProductModuleService>({
])
})
it("should return a list of products scoped by variant options", async () => {
const productsWithVariants = await service.listProducts(
{
variants: {
options: {
option_id: productOneData.options[0].id,
value: "small",
},
},
},
{
relations: ["variants", "variants.options"],
}
)
expect(productsWithVariants).toHaveLength(1)
expect(productsWithVariants).toEqual([
expect.objectContaining({
id: productOneData.id,
}),
])
})
it("should return empty array when querying for a collection that doesnt exist", async () => {
const products = await service.listProducts(
{