@labdigital/commercetools-mock 0.7.1 → 0.8.0
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/index.d.ts +25 -1
- package/dist/index.global.js +273 -60
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +270 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +270 -57
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -1
- package/src/helpers.ts +24 -0
- package/src/lib/projectionSearchFilter.test.ts +6 -0
- package/src/lib/projectionSearchFilter.ts +173 -74
- package/src/product-projection-search.ts +206 -10
- package/src/repositories/product-projection.ts +1 -0
- package/src/services/product-projection.test.ts +170 -3
|
@@ -50,10 +50,29 @@ beforeEach(async () => {
|
|
|
50
50
|
attributes: [
|
|
51
51
|
{
|
|
52
52
|
name: 'number',
|
|
53
|
-
value:
|
|
53
|
+
value: 4 as any,
|
|
54
54
|
},
|
|
55
55
|
],
|
|
56
56
|
},
|
|
57
|
+
variants: [
|
|
58
|
+
{
|
|
59
|
+
sku: 'my-other-sku',
|
|
60
|
+
prices: [
|
|
61
|
+
{
|
|
62
|
+
value: {
|
|
63
|
+
currencyCode: 'EUR',
|
|
64
|
+
centAmount: 91789,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
attributes: [
|
|
69
|
+
{
|
|
70
|
+
name: 'number',
|
|
71
|
+
value: 50 as any,
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
],
|
|
57
76
|
name: {
|
|
58
77
|
'nl-NL': 'test product',
|
|
59
78
|
},
|
|
@@ -96,7 +115,26 @@ beforeEach(async () => {
|
|
|
96
115
|
images: [],
|
|
97
116
|
attributes: productDraft.masterVariant?.attributes,
|
|
98
117
|
},
|
|
99
|
-
variants: [
|
|
118
|
+
variants: [
|
|
119
|
+
{
|
|
120
|
+
id: 2,
|
|
121
|
+
sku: 'my-other-sku',
|
|
122
|
+
prices: [
|
|
123
|
+
{
|
|
124
|
+
id: product.masterData.current.variants[0].prices[0].id,
|
|
125
|
+
value: {
|
|
126
|
+
type: 'centPrecision',
|
|
127
|
+
currencyCode: 'EUR',
|
|
128
|
+
centAmount: 91789,
|
|
129
|
+
fractionDigits: 2,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
assets: [],
|
|
134
|
+
images: [],
|
|
135
|
+
attributes: productDraft.variants![0].attributes,
|
|
136
|
+
},
|
|
137
|
+
],
|
|
100
138
|
name: productDraft.name,
|
|
101
139
|
slug: productDraft.slug,
|
|
102
140
|
categories: [],
|
|
@@ -210,7 +248,7 @@ describe('Product Projection Search - Filters', () => {
|
|
|
210
248
|
const response = await supertest(ctMock.app)
|
|
211
249
|
.get('/dummy/product-projections/search')
|
|
212
250
|
.query({
|
|
213
|
-
filter: ['variants.attributes.number:range(
|
|
251
|
+
filter: ['variants.attributes.number:range(5 TO 10)'],
|
|
214
252
|
})
|
|
215
253
|
|
|
216
254
|
const result: ProductProjectionPagedSearchResponse = response.body
|
|
@@ -220,3 +258,132 @@ describe('Product Projection Search - Filters', () => {
|
|
|
220
258
|
})
|
|
221
259
|
})
|
|
222
260
|
})
|
|
261
|
+
|
|
262
|
+
describe('Product Projection Search - Facets', () => {
|
|
263
|
+
test('termExpr - variants.attributes.number', async () => {
|
|
264
|
+
const response = await supertest(ctMock.app)
|
|
265
|
+
.get('/dummy/product-projections/search')
|
|
266
|
+
.query({
|
|
267
|
+
facet: ['variants.attributes.number'],
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
const result: ProductProjectionPagedSearchResponse = response.body
|
|
271
|
+
expect(result).toMatchObject({
|
|
272
|
+
count: 1,
|
|
273
|
+
facets: {
|
|
274
|
+
'variants.attributes.number': {
|
|
275
|
+
type: 'terms',
|
|
276
|
+
dataType: 'text',
|
|
277
|
+
missing: 0,
|
|
278
|
+
total: 2,
|
|
279
|
+
terms: [
|
|
280
|
+
{
|
|
281
|
+
term: '4.0',
|
|
282
|
+
count: 1,
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
term: '50.0',
|
|
286
|
+
count: 1,
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
results: [
|
|
292
|
+
{
|
|
293
|
+
masterVariant: { sku: 'my-sku' },
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
})
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
test('filterExpr - variants.attributes.number', async () => {
|
|
300
|
+
const response = await supertest(ctMock.app)
|
|
301
|
+
.get('/dummy/product-projections/search')
|
|
302
|
+
.query({
|
|
303
|
+
facet: ['variants.attributes.number:3,4'],
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
const result: ProductProjectionPagedSearchResponse = response.body
|
|
307
|
+
expect(result).toMatchObject({
|
|
308
|
+
count: 1,
|
|
309
|
+
facets: {
|
|
310
|
+
'variants.attributes.number': {
|
|
311
|
+
type: 'filter',
|
|
312
|
+
count: 1,
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
results: [
|
|
316
|
+
{
|
|
317
|
+
masterVariant: { sku: 'my-sku' },
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
})
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
test('rangeExpr - variants.attributes.number', async () => {
|
|
324
|
+
const response = await supertest(ctMock.app)
|
|
325
|
+
.get('/dummy/product-projections/search')
|
|
326
|
+
.query({
|
|
327
|
+
facet: [
|
|
328
|
+
'variants.attributes.number:range(* TO 5), (5 TO 25), (25 TO 100)',
|
|
329
|
+
],
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
const result: ProductProjectionPagedSearchResponse = response.body
|
|
333
|
+
expect(result).toMatchObject({
|
|
334
|
+
count: 1,
|
|
335
|
+
facets: {
|
|
336
|
+
'variants.attributes.number': {
|
|
337
|
+
type: 'range',
|
|
338
|
+
dataType: 'number',
|
|
339
|
+
ranges: [
|
|
340
|
+
{
|
|
341
|
+
type: 'double',
|
|
342
|
+
from: 0.0,
|
|
343
|
+
fromStr: '',
|
|
344
|
+
to: 5.0,
|
|
345
|
+
toStr: '5.0',
|
|
346
|
+
count: 1,
|
|
347
|
+
// totalCount: 1,
|
|
348
|
+
total: 4.0,
|
|
349
|
+
min: 4.0,
|
|
350
|
+
max: 4.0,
|
|
351
|
+
mean: 4.0,
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
type: 'double',
|
|
355
|
+
from: 5.0,
|
|
356
|
+
fromStr: '5.0',
|
|
357
|
+
to: 25.0,
|
|
358
|
+
toStr: '25.0',
|
|
359
|
+
count: 0,
|
|
360
|
+
// totalCount: 0,
|
|
361
|
+
total: 0.0,
|
|
362
|
+
min: 0.0,
|
|
363
|
+
max: 0.0,
|
|
364
|
+
mean: 0.0,
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
type: 'double',
|
|
368
|
+
from: 25.0,
|
|
369
|
+
fromStr: '25.0',
|
|
370
|
+
to: 100.0,
|
|
371
|
+
toStr: '100.0',
|
|
372
|
+
count: 1,
|
|
373
|
+
// totalCount: 1,
|
|
374
|
+
total: 50,
|
|
375
|
+
min: 50.0,
|
|
376
|
+
max: 50.0,
|
|
377
|
+
mean: 50.0,
|
|
378
|
+
},
|
|
379
|
+
],
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
results: [
|
|
383
|
+
{
|
|
384
|
+
masterVariant: { sku: 'my-sku' },
|
|
385
|
+
},
|
|
386
|
+
],
|
|
387
|
+
})
|
|
388
|
+
})
|
|
389
|
+
})
|