Skip to content

Commit 894042b

Browse files
authored
Merge pull request #21 from labd/feature/product-projection-search-without-filter
fix productProjection search without filters
2 parents 9d0b64e + 40b5716 commit 894042b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/repositories/product-projection.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export class ProductProjectionRepository extends AbstractResourceRepository {
5050
}
5151

5252
search(projectKey: string, query: ParsedQs) {
53-
const wherePredicate = parseFilterExpression(query.filter as any)
53+
const filter = (query['filter.query'] ?? query.filter) as any
54+
const wherePredicate = filter ? parseFilterExpression(filter) : undefined
5455

5556
const results = this._storage.query(projectKey, this.getTypeId(), {
5657
where: wherePredicate,

src/services/product-projection.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ describe('Product Projection', () => {
6666

6767
expect(response.status).toBe(404)
6868
})
69+
})
6970

70-
test('Search product projection', async () => {
71+
describe('Product Projection Search', () => {
72+
beforeAll(() => {
7173
ctMock.project('dummy').add('product-projection', {
7274
id: '',
7375
version: 1,
@@ -83,7 +85,9 @@ describe('Product Projection', () => {
8385
lastModifiedAt: '',
8486
categories: [],
8587
})
88+
})
8689

90+
test('Search product projection', async () => {
8791
const response = await supertest(ctMock.app).get(
8892
'/dummy/product-projections/search?' +
8993
qs.stringify({
@@ -113,4 +117,31 @@ describe('Product Projection', () => {
113117
],
114118
})
115119
})
120+
121+
test('Search product projection with query.filter', async () => {
122+
const response = await supertest(ctMock.app).get(
123+
'/dummy/product-projections/search?' +
124+
qs.stringify({
125+
'query.filter': ['masterVariant.sku:"1337"'],
126+
})
127+
)
128+
129+
const projection: ProductProjection = response.body
130+
expect(projection).toMatchObject({
131+
count: 1,
132+
results: [{ masterVariant: { id: 1, sku: '1337' } }],
133+
})
134+
})
135+
136+
test('Search product projection without filter', async () => {
137+
const response = await supertest(ctMock.app).get(
138+
'/dummy/product-projections/search'
139+
)
140+
141+
const projection: ProductProjection = response.body
142+
expect(projection).toMatchObject({
143+
count: 1,
144+
results: [{ masterVariant: { id: 1, sku: '1337' } }],
145+
})
146+
})
116147
})

0 commit comments

Comments
 (0)