@labdigital/commercetools-mock 0.5.16 → 0.5.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commercetools-mock.cjs.development.js +13 -3
- package/dist/commercetools-mock.cjs.development.js.map +1 -1
- package/dist/commercetools-mock.cjs.production.min.js +1 -1
- package/dist/commercetools-mock.cjs.production.min.js.map +1 -1
- package/dist/commercetools-mock.esm.js +13 -3
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/dist/repositories/abstract.d.ts +2 -0
- package/package.json +1 -1
- package/src/repositories/abstract.ts +4 -0
- package/src/repositories/product-projection.ts +2 -0
- package/src/services/abstract.ts +5 -0
- package/src/services/product-projection.test.ts +20 -0
package/package.json
CHANGED
|
@@ -14,6 +14,8 @@ import { CommercetoolsError } from '../exceptions'
|
|
|
14
14
|
export type QueryParams = {
|
|
15
15
|
expand?: string[]
|
|
16
16
|
where?: string[]
|
|
17
|
+
offset?: number
|
|
18
|
+
limit?: number
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export type GetParams = {
|
|
@@ -69,6 +71,8 @@ export abstract class AbstractResourceRepository extends AbstractRepository {
|
|
|
69
71
|
return this._storage.query(projectKey, this.getTypeId(), {
|
|
70
72
|
expand: params.expand,
|
|
71
73
|
where: params.where,
|
|
74
|
+
offset: params.offset,
|
|
75
|
+
limit: params.limit,
|
|
72
76
|
})
|
|
73
77
|
}
|
|
74
78
|
|
|
@@ -55,6 +55,8 @@ export class ProductProjectionRepository extends AbstractResourceRepository {
|
|
|
55
55
|
|
|
56
56
|
const results = this._storage.query(projectKey, this.getTypeId(), {
|
|
57
57
|
where: wherePredicate,
|
|
58
|
+
offset: query.offset ? Number(query.offset) : undefined,
|
|
59
|
+
limit: query.limit ? Number(query.limit) : undefined,
|
|
58
60
|
}) //TODO: this is a partial implementation, but I don't really have the time to implement an actual search API right now
|
|
59
61
|
|
|
60
62
|
return results
|
package/src/services/abstract.ts
CHANGED
|
@@ -37,9 +37,14 @@ export default abstract class AbstractService {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
get(request: Request, response: Response) {
|
|
40
|
+
const limit = this._parseParam(request.query.limit)
|
|
41
|
+
const offset = this._parseParam(request.query.offset)
|
|
42
|
+
|
|
40
43
|
const result = this.repository.query(request.params.projectKey, {
|
|
41
44
|
expand: this._parseParam(request.query.expand),
|
|
42
45
|
where: this._parseParam(request.query.where),
|
|
46
|
+
limit: limit !== undefined ? Number(limit) : undefined,
|
|
47
|
+
offset: offset !== undefined ? Number(offset) : undefined,
|
|
43
48
|
})
|
|
44
49
|
return response.status(200).send(result)
|
|
45
50
|
}
|
|
@@ -118,6 +118,26 @@ describe('Product Projection Search', () => {
|
|
|
118
118
|
})
|
|
119
119
|
})
|
|
120
120
|
|
|
121
|
+
test('Search product projection page 2', async () => {
|
|
122
|
+
const response = await supertest(ctMock.app).get(
|
|
123
|
+
'/dummy/product-projections/search?' +
|
|
124
|
+
qs.stringify({
|
|
125
|
+
filter: ['masterVariant.sku:"1337"'],
|
|
126
|
+
limit: 50,
|
|
127
|
+
offset: 100,
|
|
128
|
+
})
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
const projection: ProductProjection = response.body
|
|
132
|
+
expect(projection).toEqual({
|
|
133
|
+
count: 1,
|
|
134
|
+
limit: 50,
|
|
135
|
+
offset: 100,
|
|
136
|
+
total: 0,
|
|
137
|
+
results: [],
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
|
|
121
141
|
test('Search product projection with query.filter', async () => {
|
|
122
142
|
const response = await supertest(ctMock.app).get(
|
|
123
143
|
'/dummy/product-projections/search?' +
|