@labdigital/commercetools-mock 1.5.0 → 1.6.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.
Files changed (129) hide show
  1. package/README.md +5 -4
  2. package/dist/index.cjs +105 -17
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +29 -7
  5. package/dist/index.d.ts +29 -7
  6. package/dist/index.js +105 -17
  7. package/dist/index.js.map +1 -1
  8. package/package.json +4 -3
  9. package/src/constants.ts +2 -2
  10. package/src/ctMock.ts +176 -176
  11. package/src/exceptions.ts +10 -10
  12. package/src/helpers.ts +26 -26
  13. package/src/index.test.ts +173 -173
  14. package/src/index.ts +3 -3
  15. package/src/lib/expandParser.ts +19 -19
  16. package/src/lib/haversine.test.ts +13 -13
  17. package/src/lib/haversine.ts +14 -14
  18. package/src/lib/masking.ts +15 -15
  19. package/src/lib/parser.ts +2 -2
  20. package/src/lib/predicateParser.test.ts +204 -204
  21. package/src/lib/predicateParser.ts +398 -398
  22. package/src/lib/projectionSearchFilter.test.ts +168 -168
  23. package/src/lib/projectionSearchFilter.ts +272 -269
  24. package/src/lib/proxy.ts +8 -8
  25. package/src/oauth/errors.ts +4 -4
  26. package/src/oauth/helpers.ts +6 -6
  27. package/src/oauth/server.ts +103 -101
  28. package/src/oauth/store.ts +27 -27
  29. package/src/priceSelector.test.ts +68 -68
  30. package/src/priceSelector.ts +70 -70
  31. package/src/product-projection-search.ts +296 -296
  32. package/src/projectAPI.test.ts +3 -3
  33. package/src/projectAPI.ts +46 -46
  34. package/src/repositories/abstract.ts +190 -190
  35. package/src/repositories/associate-role.ts +10 -7
  36. package/src/repositories/attribute-group.ts +63 -8
  37. package/src/repositories/business-unit.ts +10 -7
  38. package/src/repositories/cart-discount.ts +134 -134
  39. package/src/repositories/cart.ts +517 -514
  40. package/src/repositories/category.ts +170 -167
  41. package/src/repositories/channel.ts +114 -111
  42. package/src/repositories/custom-object.ts +66 -63
  43. package/src/repositories/customer-group.ts +72 -69
  44. package/src/repositories/customer.ts +90 -90
  45. package/src/repositories/discount-code.ts +171 -168
  46. package/src/repositories/errors.ts +15 -15
  47. package/src/repositories/extension.ts +79 -76
  48. package/src/repositories/helpers.ts +180 -180
  49. package/src/repositories/index.ts +39 -39
  50. package/src/repositories/inventory-entry.ts +98 -95
  51. package/src/repositories/my-order.ts +11 -11
  52. package/src/repositories/order-edit.ts +29 -29
  53. package/src/repositories/order.test.ts +191 -191
  54. package/src/repositories/order.ts +393 -393
  55. package/src/repositories/payment.ts +155 -155
  56. package/src/repositories/product-discount.ts +149 -149
  57. package/src/repositories/product-projection.ts +116 -52
  58. package/src/repositories/product-selection.ts +31 -31
  59. package/src/repositories/product-type.ts +156 -156
  60. package/src/repositories/product.ts +600 -597
  61. package/src/repositories/project.ts +136 -135
  62. package/src/repositories/quote-request.ts +19 -19
  63. package/src/repositories/quote.ts +19 -19
  64. package/src/repositories/review.ts +24 -24
  65. package/src/repositories/shipping-method.ts +217 -217
  66. package/src/repositories/shopping-list.ts +49 -49
  67. package/src/repositories/staged-quote.ts +20 -20
  68. package/src/repositories/standalone-price.ts +72 -61
  69. package/src/repositories/state.ts +84 -84
  70. package/src/repositories/store.ts +114 -114
  71. package/src/repositories/subscription.ts +40 -40
  72. package/src/repositories/tax-category.ts +98 -98
  73. package/src/repositories/type.ts +157 -157
  74. package/src/repositories/zone.ts +71 -71
  75. package/src/server.ts +2 -2
  76. package/src/services/abstract.ts +173 -173
  77. package/src/services/attribute-group.ts +16 -0
  78. package/src/services/cart-discount.ts +8 -8
  79. package/src/services/cart.test.ts +409 -409
  80. package/src/services/cart.ts +50 -50
  81. package/src/services/category.test.ts +25 -25
  82. package/src/services/category.ts +8 -8
  83. package/src/services/channel.ts +8 -8
  84. package/src/services/custom-object.test.ts +184 -184
  85. package/src/services/custom-object.ts +48 -48
  86. package/src/services/customer-group.ts +8 -8
  87. package/src/services/customer.test.ts +151 -151
  88. package/src/services/customer.ts +27 -27
  89. package/src/services/discount-code.ts +8 -8
  90. package/src/services/extension.ts +8 -8
  91. package/src/services/index.ts +52 -44
  92. package/src/services/inventory-entry.test.ts +162 -162
  93. package/src/services/inventory-entry.ts +8 -8
  94. package/src/services/my-cart.test.ts +78 -78
  95. package/src/services/my-cart.ts +28 -28
  96. package/src/services/my-customer.test.ts +44 -44
  97. package/src/services/my-customer.ts +53 -53
  98. package/src/services/my-order.ts +20 -20
  99. package/src/services/my-payment.test.ts +65 -65
  100. package/src/services/my-payment.ts +8 -8
  101. package/src/services/order.test.ts +527 -527
  102. package/src/services/order.ts +31 -31
  103. package/src/services/payment.test.ts +65 -65
  104. package/src/services/payment.ts +8 -8
  105. package/src/services/product-discount.ts +8 -8
  106. package/src/services/product-projection.test.ts +492 -428
  107. package/src/services/product-projection.ts +32 -18
  108. package/src/services/product-type.test.ts +56 -56
  109. package/src/services/product-type.ts +8 -8
  110. package/src/services/product.test.ts +510 -510
  111. package/src/services/product.ts +8 -8
  112. package/src/services/project.ts +34 -34
  113. package/src/services/shipping-method.test.ts +81 -81
  114. package/src/services/shipping-method.ts +12 -12
  115. package/src/services/shopping-list.ts +8 -8
  116. package/src/services/standalone-price.test.ts +256 -256
  117. package/src/services/standalone-price.ts +8 -8
  118. package/src/services/state.test.ts +42 -42
  119. package/src/services/state.ts +8 -8
  120. package/src/services/store.test.ts +57 -57
  121. package/src/services/store.ts +8 -8
  122. package/src/services/subscription.ts +8 -8
  123. package/src/services/tax-category.test.ts +61 -61
  124. package/src/services/tax-category.ts +8 -8
  125. package/src/services/type.ts +8 -8
  126. package/src/services/zone.ts +8 -8
  127. package/src/storage/abstract.ts +58 -58
  128. package/src/storage/in-memory.ts +419 -419
  129. package/src/types.ts +82 -82
@@ -1,10 +1,10 @@
1
1
  import type {
2
- Product,
3
- ProductDraft,
4
- ProductProjection,
5
- ProductProjectionPagedSearchResponse,
6
- ProductType,
7
- ProductTypeDraft,
2
+ Product,
3
+ ProductDraft,
4
+ ProductProjection,
5
+ ProductProjectionPagedSearchResponse,
6
+ ProductType,
7
+ ProductTypeDraft,
8
8
  } from '@commercetools/platform-sdk'
9
9
  import supertest from 'supertest'
10
10
  import * as timekeeper from 'timekeeper'
@@ -20,439 +20,503 @@ let publishedProduct: Product
20
20
  let unpublishedProduct: Product
21
21
 
22
22
  beforeEach(async () => {
23
- timekeeper.freeze(new Date('2022-07-22T13:31:49.840Z'))
24
-
25
- // Create the product type
26
- {
27
- const draft: ProductTypeDraft = {
28
- name: 'Default Product Type',
29
- description: 'Product type for testing',
30
- }
31
- const response = await supertest(ctMock.app)
32
- .post('/dummy/product-types')
33
- .send(draft)
34
-
35
- expect(response.ok).toBe(true)
36
- productType = response.body
37
- }
38
-
39
- // Create an unpublished product
40
- {
41
- const productDraft: Writable<ProductDraft> = {
42
- publish: false,
43
- key: 'my-unpublished-product',
44
- masterVariant: {
45
- sku: 'my-unpub-sku',
46
- prices: [
47
- {
48
- value: {
49
- currencyCode: 'EUR',
50
- centAmount: 189,
51
- },
52
- },
53
- ],
54
- attributes: [
55
- {
56
- name: 'number',
57
- value: 1 as any,
58
- },
59
- ],
60
- },
61
- name: {
62
- 'nl-NL': 'test unpublished product',
63
- },
64
- productType: {
65
- typeId: 'product-type',
66
- id: productType.id,
67
- },
68
- slug: {
69
- 'nl-NL': 'test-unpublished-product',
70
- },
71
- }
72
-
73
- const response = await supertest(ctMock.app)
74
- .post('/dummy/products')
75
- .send(productDraft)
76
- expect(response.ok).toBe(true)
77
- unpublishedProduct = response.body
78
- }
79
-
80
- // Create a published product
81
- {
82
- const productDraft: Writable<ProductDraft> = {
83
- publish: true,
84
- key: 'my-product-key',
85
- masterVariant: {
86
- sku: 'my-sku',
87
- prices: [
88
- {
89
- value: {
90
- currencyCode: 'EUR',
91
- centAmount: 1789,
92
- },
93
- },
94
- ],
95
- attributes: [
96
- {
97
- name: 'number',
98
- value: 4 as any,
99
- },
100
- ],
101
- },
102
- variants: [
103
- {
104
- sku: 'my-other-sku',
105
- prices: [
106
- {
107
- value: {
108
- currencyCode: 'EUR',
109
- centAmount: 91789,
110
- },
111
- },
112
- ],
113
- attributes: [
114
- {
115
- name: 'number',
116
- value: 50 as any,
117
- },
118
- ],
119
- },
120
- ],
121
- name: {
122
- 'nl-NL': 'test product',
123
- },
124
- productType: {
125
- typeId: 'product-type',
126
- id: productType.id,
127
- },
128
- slug: {
129
- 'nl-NL': 'test-product',
130
- },
131
- }
132
-
133
- const response = await supertest(ctMock.app)
134
- .post('/dummy/products')
135
- .send(productDraft)
136
- expect(response.ok).toBe(true)
137
- const product = response.body
138
- publishedProduct = response.body
139
-
140
- // Create the expected ProductProjection object
141
- productProjection = {
142
- id: product.id,
143
- createdAt: '2022-07-22T13:31:49.840Z',
144
- lastModifiedAt: '2022-07-22T13:31:49.840Z',
145
- version: 1,
146
- key: 'my-product-key',
147
- published: true,
148
- hasStagedChanges: false,
149
- masterVariant: {
150
- id: 1,
151
- sku: 'my-sku',
152
- prices: [
153
- {
154
- id: product.masterData.current.masterVariant.prices[0].id,
155
- value: {
156
- type: 'centPrecision',
157
- currencyCode: 'EUR',
158
- centAmount: 1789,
159
- fractionDigits: 2,
160
- },
161
- },
162
- ],
163
- assets: [],
164
- images: [],
165
- attributes: productDraft.masterVariant?.attributes,
166
- },
167
- variants: [
168
- {
169
- id: 2,
170
- sku: 'my-other-sku',
171
- prices: [
172
- {
173
- id: product.masterData.current.variants[0].prices[0].id,
174
- value: {
175
- type: 'centPrecision',
176
- currencyCode: 'EUR',
177
- centAmount: 91789,
178
- fractionDigits: 2,
179
- },
180
- },
181
- ],
182
- assets: [],
183
- images: [],
184
- attributes: productDraft.variants![0].attributes,
185
- },
186
- ],
187
- name: productDraft.name,
188
- slug: productDraft.slug,
189
- categories: [],
190
- productType: {
191
- typeId: 'product-type',
192
- id: productType.id,
193
- },
194
- }
195
- }
23
+ timekeeper.freeze(new Date('2022-07-22T13:31:49.840Z'))
24
+
25
+ // Create the product type
26
+ {
27
+ const draft: ProductTypeDraft = {
28
+ name: 'Default Product Type',
29
+ description: 'Product type for testing',
30
+ }
31
+ const response = await supertest(ctMock.app)
32
+ .post('/dummy/product-types')
33
+ .send(draft)
34
+
35
+ expect(response.ok).toBe(true)
36
+ productType = response.body
37
+ }
38
+
39
+ // Create an unpublished product
40
+ {
41
+ const productDraft: Writable<ProductDraft> = {
42
+ publish: false,
43
+ key: 'my-unpublished-product',
44
+ masterVariant: {
45
+ sku: 'my-unpub-sku',
46
+ prices: [
47
+ {
48
+ value: {
49
+ currencyCode: 'EUR',
50
+ centAmount: 189,
51
+ },
52
+ },
53
+ ],
54
+ attributes: [
55
+ {
56
+ name: 'number',
57
+ value: 1 as any,
58
+ },
59
+ ],
60
+ },
61
+ name: {
62
+ 'nl-NL': 'test unpublished product',
63
+ },
64
+ productType: {
65
+ typeId: 'product-type',
66
+ id: productType.id,
67
+ },
68
+ slug: {
69
+ 'nl-NL': 'test-unpublished-product',
70
+ },
71
+ }
72
+
73
+ const response = await supertest(ctMock.app)
74
+ .post('/dummy/products')
75
+ .send(productDraft)
76
+ expect(response.ok).toBe(true)
77
+ unpublishedProduct = response.body
78
+ }
79
+
80
+ // Create a published product
81
+ {
82
+ const productDraft: Writable<ProductDraft> = {
83
+ publish: true,
84
+ key: 'my-product-key',
85
+ masterVariant: {
86
+ sku: 'my-sku',
87
+ prices: [
88
+ {
89
+ value: {
90
+ currencyCode: 'EUR',
91
+ centAmount: 1789,
92
+ },
93
+ },
94
+ ],
95
+ attributes: [
96
+ {
97
+ name: 'number',
98
+ value: 4 as any,
99
+ },
100
+ ],
101
+ },
102
+ variants: [
103
+ {
104
+ sku: 'my-other-sku',
105
+ prices: [
106
+ {
107
+ value: {
108
+ currencyCode: 'EUR',
109
+ centAmount: 91789,
110
+ },
111
+ },
112
+ ],
113
+ attributes: [
114
+ {
115
+ name: 'number',
116
+ value: 50 as any,
117
+ },
118
+ ],
119
+ },
120
+ ],
121
+ name: {
122
+ 'nl-NL': 'test product',
123
+ },
124
+ productType: {
125
+ typeId: 'product-type',
126
+ id: productType.id,
127
+ },
128
+ slug: {
129
+ 'nl-NL': 'test-product',
130
+ },
131
+ }
132
+
133
+ const response = await supertest(ctMock.app)
134
+ .post('/dummy/products')
135
+ .send(productDraft)
136
+ expect(response.ok).toBe(true)
137
+ const product = response.body
138
+ publishedProduct = response.body
139
+
140
+ // Create the expected ProductProjection object
141
+ productProjection = {
142
+ id: product.id,
143
+ createdAt: '2022-07-22T13:31:49.840Z',
144
+ lastModifiedAt: '2022-07-22T13:31:49.840Z',
145
+ version: 1,
146
+ key: 'my-product-key',
147
+ published: true,
148
+ hasStagedChanges: false,
149
+ masterVariant: {
150
+ id: 1,
151
+ sku: 'my-sku',
152
+ prices: [
153
+ {
154
+ id: product.masterData.current.masterVariant.prices[0].id,
155
+ value: {
156
+ type: 'centPrecision',
157
+ currencyCode: 'EUR',
158
+ centAmount: 1789,
159
+ fractionDigits: 2,
160
+ },
161
+ },
162
+ ],
163
+ assets: [],
164
+ images: [],
165
+ attributes: productDraft.masterVariant?.attributes,
166
+ },
167
+ variants: [
168
+ {
169
+ id: 2,
170
+ sku: 'my-other-sku',
171
+ prices: [
172
+ {
173
+ id: product.masterData.current.variants[0].prices[0].id,
174
+ value: {
175
+ type: 'centPrecision',
176
+ currencyCode: 'EUR',
177
+ centAmount: 91789,
178
+ fractionDigits: 2,
179
+ },
180
+ },
181
+ ],
182
+ assets: [],
183
+ images: [],
184
+ attributes: productDraft.variants![0].attributes,
185
+ },
186
+ ],
187
+ name: productDraft.name,
188
+ slug: productDraft.slug,
189
+ categories: [],
190
+ productType: {
191
+ typeId: 'product-type',
192
+ id: productType.id,
193
+ },
194
+ }
195
+ }
196
196
  })
197
197
 
198
198
  afterEach(async () => {
199
- timekeeper.reset()
200
- ctMock.clear()
199
+ timekeeper.reset()
200
+ ctMock.clear()
201
+ })
202
+
203
+ // Test the general product projection implementation
204
+ describe('Product Projection Query - Generic', () => {
205
+ test('Filter out staged', async () => {
206
+ {
207
+ const response = await supertest(ctMock.app)
208
+ .get('/dummy/product-projections')
209
+ .query({
210
+ limit: 50,
211
+ })
212
+
213
+ const result: ProductProjectionPagedSearchResponse = response.body
214
+ expect(result).toEqual({
215
+ count: 1,
216
+ limit: 50,
217
+ offset: 0,
218
+ total: 1,
219
+ results: [productProjection],
220
+ })
221
+ }
222
+ })
223
+
224
+ test('Filter on valid slug', async () => {
225
+ {
226
+ const response = await supertest(ctMock.app)
227
+ .get('/dummy/product-projections')
228
+ .query({
229
+ limit: 50,
230
+ where: ['slug(nl-NL=:slug)'],
231
+ 'var.slug': 'test-product',
232
+ })
233
+
234
+ const result: ProductProjectionPagedSearchResponse = response.body
235
+ expect(result).toEqual({
236
+ count: 1,
237
+ limit: 50,
238
+ offset: 0,
239
+ total: 1,
240
+ results: [productProjection],
241
+ })
242
+ }
243
+ })
244
+
245
+ test('Filter on invalid slug', async () => {
246
+ {
247
+ const response = await supertest(ctMock.app)
248
+ .get('/dummy/product-projections')
249
+ .query({
250
+ limit: 50,
251
+ where: ['slug(nl-NL=:slug)'],
252
+ 'var.slug': 'missing-product',
253
+ })
254
+
255
+ const result: ProductProjectionPagedSearchResponse = response.body
256
+ expect(result).toEqual({
257
+ count: 0,
258
+ limit: 50,
259
+ offset: 0,
260
+ total: 0,
261
+ results: [],
262
+ })
263
+ }
264
+ })
201
265
  })
202
266
 
203
267
  // Test the general product projection implementation
204
268
  describe('Product Projection Search - Generic', () => {
205
- test('Pagination', async () => {
206
- {
207
- const response = await supertest(ctMock.app)
208
- .get('/dummy/product-projections/search')
209
- .query({
210
- limit: 50,
211
- })
212
-
213
- const result: ProductProjectionPagedSearchResponse = response.body
214
- expect(result).toEqual({
215
- count: 1,
216
- limit: 50,
217
- offset: 0,
218
- total: 1,
219
- facets: {},
220
- results: [productProjection],
221
- })
222
- }
223
- {
224
- const response = await supertest(ctMock.app)
225
- .get('/dummy/product-projections/search')
226
- .query({
227
- limit: 50,
228
- offset: 50,
229
- })
230
-
231
- const projection: ProductProjection = response.body
232
- expect(projection).toEqual({
233
- count: 1,
234
- limit: 50,
235
- offset: 50,
236
- total: 0,
237
- facets: {},
238
- results: [],
239
- })
240
- }
241
- })
242
-
243
- test('Search - unpublished', async () => {
244
- {
245
- const response = await supertest(ctMock.app)
246
- .get('/dummy/product-projections/search')
247
- .query({
248
- limit: 50,
249
- staged: true,
250
- })
251
-
252
- const result: ProductProjectionPagedSearchResponse = response.body
253
-
254
- expect(result).toMatchObject({
255
- count: 2,
256
- limit: 50,
257
- offset: 0,
258
- total: 2,
259
- facets: {},
260
- results: [
261
- { id: unpublishedProduct.id, published: false },
262
- { id: publishedProduct.id, published: true },
263
- ],
264
- })
265
- }
266
- })
267
-
268
- test('Get 404 when not found by key with expand', async () => {
269
- const response = await supertest(ctMock.app)
270
- .get('/dummy/product-projections/key=DOESNOTEXIST')
271
- .query({
272
- expand: ['categories[*]'],
273
- })
274
-
275
- expect(response.status).toBe(404)
276
- })
269
+ test('Pagination', async () => {
270
+ {
271
+ const response = await supertest(ctMock.app)
272
+ .get('/dummy/product-projections/search')
273
+ .query({
274
+ limit: 50,
275
+ })
276
+
277
+ const result: ProductProjectionPagedSearchResponse = response.body
278
+ expect(result).toEqual({
279
+ count: 1,
280
+ limit: 50,
281
+ offset: 0,
282
+ total: 1,
283
+ facets: {},
284
+ results: [productProjection],
285
+ })
286
+ }
287
+ {
288
+ const response = await supertest(ctMock.app)
289
+ .get('/dummy/product-projections/search')
290
+ .query({
291
+ limit: 50,
292
+ offset: 50,
293
+ })
294
+
295
+ const projection: ProductProjection = response.body
296
+ expect(projection).toEqual({
297
+ count: 1,
298
+ limit: 50,
299
+ offset: 50,
300
+ total: 0,
301
+ facets: {},
302
+ results: [],
303
+ })
304
+ }
305
+ })
306
+
307
+ test('Search - unpublished', async () => {
308
+ {
309
+ const response = await supertest(ctMock.app)
310
+ .get('/dummy/product-projections/search')
311
+ .query({
312
+ limit: 50,
313
+ staged: true,
314
+ })
315
+
316
+ const result: ProductProjectionPagedSearchResponse = response.body
317
+
318
+ expect(result).toMatchObject({
319
+ count: 2,
320
+ limit: 50,
321
+ offset: 0,
322
+ total: 2,
323
+ facets: {},
324
+ results: [
325
+ { id: unpublishedProduct.id, published: false },
326
+ { id: publishedProduct.id, published: true },
327
+ ],
328
+ })
329
+ }
330
+ })
331
+
332
+ test('Get 404 when not found by key with expand', async () => {
333
+ const response = await supertest(ctMock.app)
334
+ .get('/dummy/product-projections/key=DOESNOTEXIST')
335
+ .query({
336
+ expand: ['categories[*]'],
337
+ })
338
+
339
+ expect(response.status).toBe(404)
340
+ })
277
341
  })
278
342
 
279
343
  describe('Product Projection Search - Filters', () => {
280
- test('variants.sku', async () => {
281
- const response = await supertest(ctMock.app)
282
- .get('/dummy/product-projections/search')
283
- .query({
284
- filter: ['variants.sku:"my-sku"'],
285
- })
286
-
287
- const result: ProductProjectionPagedSearchResponse = response.body
288
- expect(result).toMatchObject({
289
- count: 1,
290
- results: [
291
- {
292
- masterVariant: { sku: 'my-sku' },
293
- },
294
- ],
295
- })
296
- })
297
-
298
- test('variants.attributes.range - match', async () => {
299
- const response = await supertest(ctMock.app)
300
- .get('/dummy/product-projections/search')
301
- .query({
302
- filter: ['variants.attributes.number:range(0 TO 10)'],
303
- })
304
-
305
- const result: ProductProjectionPagedSearchResponse = response.body
306
- expect(result).toMatchObject({
307
- count: 1,
308
- results: [
309
- {
310
- masterVariant: { sku: 'my-sku' },
311
- },
312
- ],
313
- })
314
- })
315
-
316
- test('variants.attributes.range - mismatch', async () => {
317
- const response = await supertest(ctMock.app)
318
- .get('/dummy/product-projections/search')
319
- .query({
320
- filter: ['variants.attributes.number:range(5 TO 10)'],
321
- })
322
-
323
- const result: ProductProjectionPagedSearchResponse = response.body
324
- expect(result).toMatchObject({
325
- count: 0,
326
- results: [],
327
- })
328
- })
344
+ test('variants.sku', async () => {
345
+ const response = await supertest(ctMock.app)
346
+ .get('/dummy/product-projections/search')
347
+ .query({
348
+ filter: ['variants.sku:"my-sku"'],
349
+ })
350
+
351
+ const result: ProductProjectionPagedSearchResponse = response.body
352
+ expect(result).toMatchObject({
353
+ count: 1,
354
+ results: [
355
+ {
356
+ masterVariant: { sku: 'my-sku' },
357
+ },
358
+ ],
359
+ })
360
+ })
361
+
362
+ test('variants.attributes.range - match', async () => {
363
+ const response = await supertest(ctMock.app)
364
+ .get('/dummy/product-projections/search')
365
+ .query({
366
+ filter: ['variants.attributes.number:range(0 TO 10)'],
367
+ })
368
+
369
+ const result: ProductProjectionPagedSearchResponse = response.body
370
+ expect(result).toMatchObject({
371
+ count: 1,
372
+ results: [
373
+ {
374
+ masterVariant: { sku: 'my-sku' },
375
+ },
376
+ ],
377
+ })
378
+ })
379
+
380
+ test('variants.attributes.range - mismatch', async () => {
381
+ const response = await supertest(ctMock.app)
382
+ .get('/dummy/product-projections/search')
383
+ .query({
384
+ filter: ['variants.attributes.number:range(5 TO 10)'],
385
+ })
386
+
387
+ const result: ProductProjectionPagedSearchResponse = response.body
388
+ expect(result).toMatchObject({
389
+ count: 0,
390
+ results: [],
391
+ })
392
+ })
329
393
  })
330
394
 
331
395
  describe('Product Projection Search - Facets', () => {
332
- test('termExpr - variants.attributes.number', async () => {
333
- const response = await supertest(ctMock.app)
334
- .get('/dummy/product-projections/search')
335
- .query({
336
- facet: ['variants.attributes.number'],
337
- })
338
-
339
- const result: ProductProjectionPagedSearchResponse = response.body
340
- expect(result).toMatchObject({
341
- count: 1,
342
- facets: {
343
- 'variants.attributes.number': {
344
- type: 'terms',
345
- dataType: 'text',
346
- missing: 0,
347
- total: 2,
348
- terms: [
349
- {
350
- term: '4.0',
351
- count: 1,
352
- },
353
- {
354
- term: '50.0',
355
- count: 1,
356
- },
357
- ],
358
- },
359
- },
360
- results: [
361
- {
362
- masterVariant: { sku: 'my-sku' },
363
- },
364
- ],
365
- })
366
- })
367
-
368
- test('filterExpr - variants.attributes.number', async () => {
369
- const response = await supertest(ctMock.app)
370
- .get('/dummy/product-projections/search')
371
- .query({
372
- facet: ['variants.attributes.number:3,4'],
373
- })
374
-
375
- const result: ProductProjectionPagedSearchResponse = response.body
376
- expect(result).toMatchObject({
377
- count: 1,
378
- facets: {
379
- 'variants.attributes.number': {
380
- type: 'filter',
381
- count: 1,
382
- },
383
- },
384
- results: [
385
- {
386
- masterVariant: { sku: 'my-sku' },
387
- },
388
- ],
389
- })
390
- })
391
-
392
- test('rangeExpr - variants.attributes.number', async () => {
393
- const response = await supertest(ctMock.app)
394
- .get('/dummy/product-projections/search')
395
- .query({
396
- facet: [
397
- 'variants.attributes.number:range(* TO 5), (5 TO 25), (25 TO 100)',
398
- ],
399
- })
400
-
401
- const result: ProductProjectionPagedSearchResponse = response.body
402
- expect(result).toMatchObject({
403
- count: 1,
404
- facets: {
405
- 'variants.attributes.number': {
406
- type: 'range',
407
- dataType: 'number',
408
- ranges: [
409
- {
410
- type: 'double',
411
- from: 0.0,
412
- fromStr: '',
413
- to: 5.0,
414
- toStr: '5.0',
415
- count: 1,
416
- // totalCount: 1,
417
- total: 4.0,
418
- min: 4.0,
419
- max: 4.0,
420
- mean: 4.0,
421
- },
422
- {
423
- type: 'double',
424
- from: 5.0,
425
- fromStr: '5.0',
426
- to: 25.0,
427
- toStr: '25.0',
428
- count: 0,
429
- // totalCount: 0,
430
- total: 0.0,
431
- min: 0.0,
432
- max: 0.0,
433
- mean: 0.0,
434
- },
435
- {
436
- type: 'double',
437
- from: 25.0,
438
- fromStr: '25.0',
439
- to: 100.0,
440
- toStr: '100.0',
441
- count: 1,
442
- // totalCount: 1,
443
- total: 50,
444
- min: 50.0,
445
- max: 50.0,
446
- mean: 50.0,
447
- },
448
- ],
449
- },
450
- },
451
- results: [
452
- {
453
- masterVariant: { sku: 'my-sku' },
454
- },
455
- ],
456
- })
457
- })
396
+ test('termExpr - variants.attributes.number', async () => {
397
+ const response = await supertest(ctMock.app)
398
+ .get('/dummy/product-projections/search')
399
+ .query({
400
+ facet: ['variants.attributes.number'],
401
+ })
402
+
403
+ const result: ProductProjectionPagedSearchResponse = response.body
404
+ expect(result).toMatchObject({
405
+ count: 1,
406
+ facets: {
407
+ 'variants.attributes.number': {
408
+ type: 'terms',
409
+ dataType: 'text',
410
+ missing: 0,
411
+ total: 2,
412
+ terms: [
413
+ {
414
+ term: '4.0',
415
+ count: 1,
416
+ },
417
+ {
418
+ term: '50.0',
419
+ count: 1,
420
+ },
421
+ ],
422
+ },
423
+ },
424
+ results: [
425
+ {
426
+ masterVariant: { sku: 'my-sku' },
427
+ },
428
+ ],
429
+ })
430
+ })
431
+
432
+ test('filterExpr - variants.attributes.number', async () => {
433
+ const response = await supertest(ctMock.app)
434
+ .get('/dummy/product-projections/search')
435
+ .query({
436
+ facet: ['variants.attributes.number:3,4'],
437
+ })
438
+
439
+ const result: ProductProjectionPagedSearchResponse = response.body
440
+ expect(result).toMatchObject({
441
+ count: 1,
442
+ facets: {
443
+ 'variants.attributes.number': {
444
+ type: 'filter',
445
+ count: 1,
446
+ },
447
+ },
448
+ results: [
449
+ {
450
+ masterVariant: { sku: 'my-sku' },
451
+ },
452
+ ],
453
+ })
454
+ })
455
+
456
+ test('rangeExpr - variants.attributes.number', async () => {
457
+ const response = await supertest(ctMock.app)
458
+ .get('/dummy/product-projections/search')
459
+ .query({
460
+ facet: [
461
+ 'variants.attributes.number:range(* TO 5), (5 TO 25), (25 TO 100)',
462
+ ],
463
+ })
464
+
465
+ const result: ProductProjectionPagedSearchResponse = response.body
466
+ expect(result).toMatchObject({
467
+ count: 1,
468
+ facets: {
469
+ 'variants.attributes.number': {
470
+ type: 'range',
471
+ dataType: 'number',
472
+ ranges: [
473
+ {
474
+ type: 'double',
475
+ from: 0.0,
476
+ fromStr: '',
477
+ to: 5.0,
478
+ toStr: '5.0',
479
+ count: 1,
480
+ // totalCount: 1,
481
+ total: 4.0,
482
+ min: 4.0,
483
+ max: 4.0,
484
+ mean: 4.0,
485
+ },
486
+ {
487
+ type: 'double',
488
+ from: 5.0,
489
+ fromStr: '5.0',
490
+ to: 25.0,
491
+ toStr: '25.0',
492
+ count: 0,
493
+ // totalCount: 0,
494
+ total: 0.0,
495
+ min: 0.0,
496
+ max: 0.0,
497
+ mean: 0.0,
498
+ },
499
+ {
500
+ type: 'double',
501
+ from: 25.0,
502
+ fromStr: '25.0',
503
+ to: 100.0,
504
+ toStr: '100.0',
505
+ count: 1,
506
+ // totalCount: 1,
507
+ total: 50,
508
+ min: 50.0,
509
+ max: 50.0,
510
+ mean: 50.0,
511
+ },
512
+ ],
513
+ },
514
+ },
515
+ results: [
516
+ {
517
+ masterVariant: { sku: 'my-sku' },
518
+ },
519
+ ],
520
+ })
521
+ })
458
522
  })