@labdigital/commercetools-mock 1.5.0 → 1.6.1

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 +117 -17
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +30 -7
  5. package/dist/index.d.ts +30 -7
  6. package/dist/index.js +117 -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 +135 -50
  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 +502 -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,513 @@ 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
+ // Test the general product projection implementation
203
+ describe('Product Projection Get By ID', () => {
204
+ test('Get By ID', async () => {
205
+ const response = await supertest(ctMock.app).get(
206
+ `/dummy/product-projections/${publishedProduct.id}`
207
+ )
208
+
209
+ const result: ProductProjection = response.body
210
+ expect(result).toBeDefined()
211
+ expect(result.id).toBe(publishedProduct.id)
212
+ })
213
+ })
214
+
215
+ // Test the general product projection implementation
216
+ describe('Product Projection Query - Generic', () => {
217
+ test('Filter out staged', async () => {
218
+ const response = await supertest(ctMock.app)
219
+ .get('/dummy/product-projections')
220
+ .query({
221
+ limit: 50,
222
+ })
223
+
224
+ const result: ProductProjectionPagedSearchResponse = response.body
225
+ expect(result).toEqual({
226
+ count: 1,
227
+ limit: 50,
228
+ offset: 0,
229
+ total: 1,
230
+ results: [productProjection],
231
+ })
232
+ })
233
+
234
+ test('Filter on valid slug', async () => {
235
+ {
236
+ const response = await supertest(ctMock.app)
237
+ .get('/dummy/product-projections')
238
+ .query({
239
+ limit: 50,
240
+ where: ['slug(nl-NL=:slug)'],
241
+ 'var.slug': 'test-product',
242
+ })
243
+
244
+ const result: ProductProjectionPagedSearchResponse = response.body
245
+ expect(result).toEqual({
246
+ count: 1,
247
+ limit: 50,
248
+ offset: 0,
249
+ total: 1,
250
+ results: [productProjection],
251
+ })
252
+ }
253
+ })
254
+
255
+ test('Filter on invalid slug', async () => {
256
+ {
257
+ const response = await supertest(ctMock.app)
258
+ .get('/dummy/product-projections')
259
+ .query({
260
+ limit: 50,
261
+ where: ['slug(nl-NL=:slug)'],
262
+ 'var.slug': 'missing-product',
263
+ })
264
+
265
+ const result: ProductProjectionPagedSearchResponse = response.body
266
+ expect(result).toEqual({
267
+ count: 0,
268
+ limit: 50,
269
+ offset: 0,
270
+ total: 0,
271
+ results: [],
272
+ })
273
+ }
274
+ })
201
275
  })
202
276
 
203
277
  // Test the general product projection implementation
204
278
  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
- })
279
+ test('Pagination', async () => {
280
+ {
281
+ const response = await supertest(ctMock.app)
282
+ .get('/dummy/product-projections/search')
283
+ .query({
284
+ limit: 50,
285
+ })
286
+
287
+ const result: ProductProjectionPagedSearchResponse = response.body
288
+ expect(result).toEqual({
289
+ count: 1,
290
+ limit: 50,
291
+ offset: 0,
292
+ total: 1,
293
+ facets: {},
294
+ results: [productProjection],
295
+ })
296
+ }
297
+ {
298
+ const response = await supertest(ctMock.app)
299
+ .get('/dummy/product-projections/search')
300
+ .query({
301
+ limit: 50,
302
+ offset: 50,
303
+ })
304
+
305
+ const projection: ProductProjection = response.body
306
+ expect(projection).toEqual({
307
+ count: 1,
308
+ limit: 50,
309
+ offset: 50,
310
+ total: 0,
311
+ facets: {},
312
+ results: [],
313
+ })
314
+ }
315
+ })
316
+
317
+ test('Search - unpublished', async () => {
318
+ {
319
+ const response = await supertest(ctMock.app)
320
+ .get('/dummy/product-projections/search')
321
+ .query({
322
+ limit: 50,
323
+ staged: true,
324
+ })
325
+
326
+ const result: ProductProjectionPagedSearchResponse = response.body
327
+
328
+ expect(result).toMatchObject({
329
+ count: 2,
330
+ limit: 50,
331
+ offset: 0,
332
+ total: 2,
333
+ facets: {},
334
+ results: [
335
+ { id: unpublishedProduct.id, published: false },
336
+ { id: publishedProduct.id, published: true },
337
+ ],
338
+ })
339
+ }
340
+ })
341
+
342
+ test('Get 404 when not found by key with expand', async () => {
343
+ const response = await supertest(ctMock.app)
344
+ .get('/dummy/product-projections/key=DOESNOTEXIST')
345
+ .query({
346
+ expand: ['categories[*]'],
347
+ })
348
+
349
+ expect(response.status).toBe(404)
350
+ })
277
351
  })
278
352
 
279
353
  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
- })
354
+ test('variants.sku', async () => {
355
+ const response = await supertest(ctMock.app)
356
+ .get('/dummy/product-projections/search')
357
+ .query({
358
+ filter: ['variants.sku:"my-sku"'],
359
+ })
360
+
361
+ const result: ProductProjectionPagedSearchResponse = response.body
362
+ expect(result).toMatchObject({
363
+ count: 1,
364
+ results: [
365
+ {
366
+ masterVariant: { sku: 'my-sku' },
367
+ },
368
+ ],
369
+ })
370
+ })
371
+
372
+ test('variants.attributes.range - match', async () => {
373
+ const response = await supertest(ctMock.app)
374
+ .get('/dummy/product-projections/search')
375
+ .query({
376
+ filter: ['variants.attributes.number:range(0 TO 10)'],
377
+ })
378
+
379
+ const result: ProductProjectionPagedSearchResponse = response.body
380
+ expect(result).toMatchObject({
381
+ count: 1,
382
+ results: [
383
+ {
384
+ masterVariant: { sku: 'my-sku' },
385
+ },
386
+ ],
387
+ })
388
+ })
389
+
390
+ test('variants.attributes.range - mismatch', async () => {
391
+ const response = await supertest(ctMock.app)
392
+ .get('/dummy/product-projections/search')
393
+ .query({
394
+ filter: ['variants.attributes.number:range(5 TO 10)'],
395
+ })
396
+
397
+ const result: ProductProjectionPagedSearchResponse = response.body
398
+ expect(result).toMatchObject({
399
+ count: 0,
400
+ results: [],
401
+ })
402
+ })
329
403
  })
330
404
 
331
405
  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
- })
406
+ test('termExpr - variants.attributes.number', async () => {
407
+ const response = await supertest(ctMock.app)
408
+ .get('/dummy/product-projections/search')
409
+ .query({
410
+ facet: ['variants.attributes.number'],
411
+ })
412
+
413
+ const result: ProductProjectionPagedSearchResponse = response.body
414
+ expect(result).toMatchObject({
415
+ count: 1,
416
+ facets: {
417
+ 'variants.attributes.number': {
418
+ type: 'terms',
419
+ dataType: 'text',
420
+ missing: 0,
421
+ total: 2,
422
+ terms: [
423
+ {
424
+ term: '4.0',
425
+ count: 1,
426
+ },
427
+ {
428
+ term: '50.0',
429
+ count: 1,
430
+ },
431
+ ],
432
+ },
433
+ },
434
+ results: [
435
+ {
436
+ masterVariant: { sku: 'my-sku' },
437
+ },
438
+ ],
439
+ })
440
+ })
441
+
442
+ test('filterExpr - variants.attributes.number', async () => {
443
+ const response = await supertest(ctMock.app)
444
+ .get('/dummy/product-projections/search')
445
+ .query({
446
+ facet: ['variants.attributes.number:3,4'],
447
+ })
448
+
449
+ const result: ProductProjectionPagedSearchResponse = response.body
450
+ expect(result).toMatchObject({
451
+ count: 1,
452
+ facets: {
453
+ 'variants.attributes.number': {
454
+ type: 'filter',
455
+ count: 1,
456
+ },
457
+ },
458
+ results: [
459
+ {
460
+ masterVariant: { sku: 'my-sku' },
461
+ },
462
+ ],
463
+ })
464
+ })
465
+
466
+ test('rangeExpr - variants.attributes.number', async () => {
467
+ const response = await supertest(ctMock.app)
468
+ .get('/dummy/product-projections/search')
469
+ .query({
470
+ facet: [
471
+ 'variants.attributes.number:range(* TO 5), (5 TO 25), (25 TO 100)',
472
+ ],
473
+ })
474
+
475
+ const result: ProductProjectionPagedSearchResponse = response.body
476
+ expect(result).toMatchObject({
477
+ count: 1,
478
+ facets: {
479
+ 'variants.attributes.number': {
480
+ type: 'range',
481
+ dataType: 'number',
482
+ ranges: [
483
+ {
484
+ type: 'double',
485
+ from: 0.0,
486
+ fromStr: '',
487
+ to: 5.0,
488
+ toStr: '5.0',
489
+ count: 1,
490
+ // totalCount: 1,
491
+ total: 4.0,
492
+ min: 4.0,
493
+ max: 4.0,
494
+ mean: 4.0,
495
+ },
496
+ {
497
+ type: 'double',
498
+ from: 5.0,
499
+ fromStr: '5.0',
500
+ to: 25.0,
501
+ toStr: '25.0',
502
+ count: 0,
503
+ // totalCount: 0,
504
+ total: 0.0,
505
+ min: 0.0,
506
+ max: 0.0,
507
+ mean: 0.0,
508
+ },
509
+ {
510
+ type: 'double',
511
+ from: 25.0,
512
+ fromStr: '25.0',
513
+ to: 100.0,
514
+ toStr: '100.0',
515
+ count: 1,
516
+ // totalCount: 1,
517
+ total: 50,
518
+ min: 50.0,
519
+ max: 50.0,
520
+ mean: 50.0,
521
+ },
522
+ ],
523
+ },
524
+ },
525
+ results: [
526
+ {
527
+ masterVariant: { sku: 'my-sku' },
528
+ },
529
+ ],
530
+ })
531
+ })
458
532
  })