@labdigital/commercetools-mock 1.4.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.
- package/README.md +5 -4
- package/dist/index.cjs +116 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -7
- package/dist/index.d.ts +30 -7
- package/dist/index.js +116 -18
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/constants.ts +2 -2
- package/src/ctMock.ts +176 -176
- package/src/exceptions.ts +10 -10
- package/src/helpers.ts +26 -26
- package/src/index.test.ts +173 -173
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +19 -19
- package/src/lib/haversine.test.ts +13 -13
- package/src/lib/haversine.ts +14 -14
- package/src/lib/masking.ts +15 -15
- package/src/lib/parser.ts +2 -2
- package/src/lib/predicateParser.test.ts +204 -204
- package/src/lib/predicateParser.ts +398 -398
- package/src/lib/projectionSearchFilter.test.ts +168 -168
- package/src/lib/projectionSearchFilter.ts +272 -269
- package/src/lib/proxy.ts +8 -8
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.ts +103 -101
- package/src/oauth/store.ts +27 -27
- package/src/priceSelector.test.ts +68 -68
- package/src/priceSelector.ts +70 -70
- package/src/product-projection-search.ts +296 -296
- package/src/projectAPI.test.ts +3 -3
- package/src/projectAPI.ts +46 -46
- package/src/repositories/abstract.ts +190 -190
- package/src/repositories/associate-role.ts +10 -7
- package/src/repositories/attribute-group.ts +63 -8
- package/src/repositories/business-unit.ts +10 -7
- package/src/repositories/cart-discount.ts +134 -134
- package/src/repositories/cart.ts +517 -514
- package/src/repositories/category.ts +170 -167
- package/src/repositories/channel.ts +114 -111
- package/src/repositories/custom-object.ts +66 -63
- package/src/repositories/customer-group.ts +72 -69
- package/src/repositories/customer.ts +93 -79
- package/src/repositories/discount-code.ts +171 -168
- package/src/repositories/errors.ts +15 -15
- package/src/repositories/extension.ts +79 -76
- package/src/repositories/helpers.ts +180 -180
- package/src/repositories/index.ts +39 -39
- package/src/repositories/inventory-entry.ts +98 -95
- package/src/repositories/my-order.ts +11 -11
- package/src/repositories/order-edit.ts +29 -29
- package/src/repositories/order.test.ts +191 -191
- package/src/repositories/order.ts +393 -389
- package/src/repositories/payment.ts +155 -155
- package/src/repositories/product-discount.ts +149 -149
- package/src/repositories/product-projection.ts +116 -52
- package/src/repositories/product-selection.ts +31 -31
- package/src/repositories/product-type.ts +156 -156
- package/src/repositories/product.ts +600 -597
- package/src/repositories/project.ts +136 -135
- package/src/repositories/quote-request.ts +19 -19
- package/src/repositories/quote.ts +19 -19
- package/src/repositories/review.ts +24 -24
- package/src/repositories/shipping-method.ts +217 -217
- package/src/repositories/shopping-list.ts +49 -49
- package/src/repositories/staged-quote.ts +20 -20
- package/src/repositories/standalone-price.ts +72 -61
- package/src/repositories/state.ts +84 -84
- package/src/repositories/store.ts +114 -114
- package/src/repositories/subscription.ts +40 -40
- package/src/repositories/tax-category.ts +98 -98
- package/src/repositories/type.ts +157 -157
- package/src/repositories/zone.ts +71 -71
- package/src/server.ts +2 -2
- package/src/services/abstract.ts +173 -173
- package/src/services/attribute-group.ts +16 -0
- package/src/services/cart-discount.ts +8 -8
- package/src/services/cart.test.ts +409 -409
- package/src/services/cart.ts +50 -50
- package/src/services/category.test.ts +25 -25
- package/src/services/category.ts +8 -8
- package/src/services/channel.ts +8 -8
- package/src/services/custom-object.test.ts +184 -184
- package/src/services/custom-object.ts +48 -48
- package/src/services/customer-group.ts +8 -8
- package/src/services/customer.test.ts +151 -129
- package/src/services/customer.ts +27 -27
- package/src/services/discount-code.ts +8 -8
- package/src/services/extension.ts +8 -8
- package/src/services/index.ts +52 -44
- package/src/services/inventory-entry.test.ts +162 -162
- package/src/services/inventory-entry.ts +8 -8
- package/src/services/my-cart.test.ts +78 -78
- package/src/services/my-cart.ts +28 -28
- package/src/services/my-customer.test.ts +44 -44
- package/src/services/my-customer.ts +53 -53
- package/src/services/my-order.ts +20 -20
- package/src/services/my-payment.test.ts +65 -65
- package/src/services/my-payment.ts +8 -8
- package/src/services/order.test.ts +527 -527
- package/src/services/order.ts +31 -31
- package/src/services/payment.test.ts +65 -65
- package/src/services/payment.ts +8 -8
- package/src/services/product-discount.ts +8 -8
- package/src/services/product-projection.test.ts +492 -428
- package/src/services/product-projection.ts +32 -18
- package/src/services/product-type.test.ts +56 -56
- package/src/services/product-type.ts +8 -8
- package/src/services/product.test.ts +510 -510
- package/src/services/product.ts +8 -8
- package/src/services/project.ts +34 -34
- package/src/services/shipping-method.test.ts +81 -81
- package/src/services/shipping-method.ts +12 -12
- package/src/services/shopping-list.ts +8 -8
- package/src/services/standalone-price.test.ts +256 -256
- package/src/services/standalone-price.ts +8 -8
- package/src/services/state.test.ts +42 -42
- package/src/services/state.ts +8 -8
- package/src/services/store.test.ts +57 -57
- package/src/services/store.ts +8 -8
- package/src/services/subscription.ts +8 -8
- package/src/services/tax-category.test.ts +61 -61
- package/src/services/tax-category.ts +8 -8
- package/src/services/type.ts +8 -8
- package/src/services/zone.ts +8 -8
- package/src/storage/abstract.ts +58 -58
- package/src/storage/in-memory.ts +419 -419
- package/src/types.ts +82 -82
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
200
|
-
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
})
|