fix: Allow filtering products by variant options in store (#7784)
This commit is contained in:
+38
-9
@@ -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(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user