@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.
- package/README.md +5 -4
- package/dist/index.cjs +117 -17
- 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 +117 -17
- 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 +90 -90
- 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 -393
- package/src/repositories/payment.ts +155 -155
- package/src/repositories/product-discount.ts +149 -149
- package/src/repositories/product-projection.ts +135 -50
- 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 -151
- 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 +502 -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,9 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
Image,
|
|
3
|
+
PriceDraft,
|
|
4
|
+
Product,
|
|
5
|
+
ProductData,
|
|
6
|
+
ProductDraft,
|
|
7
7
|
} from '@commercetools/platform-sdk'
|
|
8
8
|
import assert from 'assert'
|
|
9
9
|
import supertest from 'supertest'
|
|
@@ -13,518 +13,518 @@ import { CommercetoolsMock } from '../index.js'
|
|
|
13
13
|
const ctMock = new CommercetoolsMock()
|
|
14
14
|
|
|
15
15
|
const publishedProductDraft: ProductDraft = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
16
|
+
name: {
|
|
17
|
+
'nl-NL': 'test published product',
|
|
18
|
+
},
|
|
19
|
+
productType: {
|
|
20
|
+
typeId: 'product-type',
|
|
21
|
+
id: 'some-uuid',
|
|
22
|
+
},
|
|
23
|
+
masterVariant: {
|
|
24
|
+
sku: '1337',
|
|
25
|
+
attributes: [
|
|
26
|
+
{
|
|
27
|
+
name: 'test',
|
|
28
|
+
value: 'test',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
prices: [
|
|
32
|
+
{
|
|
33
|
+
country: 'NL',
|
|
34
|
+
value: {
|
|
35
|
+
currencyCode: 'EUR',
|
|
36
|
+
centAmount: 1000,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
variants: [
|
|
42
|
+
{
|
|
43
|
+
sku: '1338',
|
|
44
|
+
attributes: [
|
|
45
|
+
{
|
|
46
|
+
name: 'test2',
|
|
47
|
+
value: 'test2',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
prices: [
|
|
51
|
+
{
|
|
52
|
+
country: 'NL',
|
|
53
|
+
value: {
|
|
54
|
+
currencyCode: 'EUR',
|
|
55
|
+
centAmount: 2000,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
slug: {
|
|
62
|
+
'nl-NL': 'test-published-product',
|
|
63
|
+
},
|
|
64
|
+
publish: true,
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
const unpublishedProductDraft: ProductDraft = {
|
|
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
|
-
|
|
68
|
+
name: {
|
|
69
|
+
'nl-NL': 'test unpublished product',
|
|
70
|
+
},
|
|
71
|
+
productType: {
|
|
72
|
+
typeId: 'product-type',
|
|
73
|
+
id: 'some-uuid',
|
|
74
|
+
},
|
|
75
|
+
masterVariant: {
|
|
76
|
+
sku: '2337',
|
|
77
|
+
attributes: [
|
|
78
|
+
{
|
|
79
|
+
name: 'test',
|
|
80
|
+
value: 'test',
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
variants: [
|
|
85
|
+
{
|
|
86
|
+
sku: '2338',
|
|
87
|
+
attributes: [
|
|
88
|
+
{
|
|
89
|
+
name: 'test2',
|
|
90
|
+
value: 'test2',
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
slug: {
|
|
96
|
+
'nl-NL': 'test-unpublished-product',
|
|
97
|
+
},
|
|
98
|
+
publish: false,
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
describe('Product', () => {
|
|
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
|
-
|
|
102
|
+
test('Create product', async () => {
|
|
103
|
+
const response = await supertest(ctMock.app)
|
|
104
|
+
.post('/dummy/products')
|
|
105
|
+
.send(unpublishedProductDraft)
|
|
106
|
+
|
|
107
|
+
const productData: ProductData = {
|
|
108
|
+
name: {
|
|
109
|
+
'nl-NL': 'test unpublished product',
|
|
110
|
+
},
|
|
111
|
+
slug: {
|
|
112
|
+
'nl-NL': 'test-unpublished-product',
|
|
113
|
+
},
|
|
114
|
+
categories: [],
|
|
115
|
+
masterVariant: {
|
|
116
|
+
sku: '2337',
|
|
117
|
+
assets: [],
|
|
118
|
+
attributes: [
|
|
119
|
+
{
|
|
120
|
+
name: 'test',
|
|
121
|
+
value: 'test',
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
id: 1,
|
|
125
|
+
images: [],
|
|
126
|
+
},
|
|
127
|
+
variants: [
|
|
128
|
+
{
|
|
129
|
+
sku: '2338',
|
|
130
|
+
assets: [],
|
|
131
|
+
id: 2,
|
|
132
|
+
images: [],
|
|
133
|
+
attributes: [
|
|
134
|
+
{
|
|
135
|
+
name: 'test2',
|
|
136
|
+
value: 'test2',
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
searchKeywords: {},
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
expect(response.body).toEqual({
|
|
145
|
+
createdAt: expect.anything(),
|
|
146
|
+
id: expect.anything(),
|
|
147
|
+
lastModifiedAt: expect.anything(),
|
|
148
|
+
masterData: {
|
|
149
|
+
staged: productData,
|
|
150
|
+
current: productData,
|
|
151
|
+
hasStagedChanges: false,
|
|
152
|
+
published: false,
|
|
153
|
+
},
|
|
154
|
+
productType: {
|
|
155
|
+
typeId: 'product-type',
|
|
156
|
+
id: 'some-uuid',
|
|
157
|
+
},
|
|
158
|
+
version: 1,
|
|
159
|
+
} as Product)
|
|
160
|
+
})
|
|
161
161
|
})
|
|
162
162
|
|
|
163
163
|
describe('Product update actions', () => {
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
164
|
+
const ctMock = new CommercetoolsMock()
|
|
165
|
+
let productPublished: Product | undefined
|
|
166
|
+
let productUnpublished: Product | undefined
|
|
167
|
+
|
|
168
|
+
beforeEach(async () => {
|
|
169
|
+
let response
|
|
170
|
+
response = await supertest(ctMock.app)
|
|
171
|
+
.post('/dummy/products')
|
|
172
|
+
.send(publishedProductDraft)
|
|
173
|
+
|
|
174
|
+
expect(response.status).toBe(201)
|
|
175
|
+
productPublished = response.body
|
|
176
|
+
|
|
177
|
+
response = await supertest(ctMock.app)
|
|
178
|
+
.post('/dummy/products')
|
|
179
|
+
.send(unpublishedProductDraft)
|
|
180
|
+
|
|
181
|
+
expect(response.status).toBe(201)
|
|
182
|
+
productUnpublished = response.body
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test('setAttribute masterVariant (staged)', async () => {
|
|
186
|
+
assert(productPublished, 'product not created')
|
|
187
|
+
|
|
188
|
+
{
|
|
189
|
+
const response = await supertest(ctMock.app)
|
|
190
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
191
|
+
.send({
|
|
192
|
+
version: 1,
|
|
193
|
+
actions: [
|
|
194
|
+
{ action: 'setAttribute', sku: '1337', name: 'foo', value: 'bar' },
|
|
195
|
+
],
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
expect(response.status).toBe(200)
|
|
199
|
+
const product: Product = response.body
|
|
200
|
+
expect(product.version).toBe(2)
|
|
201
|
+
expect(product.masterData.hasStagedChanges).toBeTruthy()
|
|
202
|
+
expect(product.masterData.current.masterVariant.attributes).toHaveLength(
|
|
203
|
+
1
|
|
204
|
+
)
|
|
205
|
+
expect(product.masterData.staged.masterVariant.attributes).toHaveLength(2)
|
|
206
|
+
|
|
207
|
+
const attr = response.body.masterData.staged.masterVariant.attributes[1]
|
|
208
|
+
expect(attr).toEqual({ name: 'foo', value: 'bar' })
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Publish
|
|
212
|
+
{
|
|
213
|
+
const response = await supertest(ctMock.app)
|
|
214
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
215
|
+
.send({
|
|
216
|
+
version: 2,
|
|
217
|
+
actions: [{ action: 'publish', scope: 'All' }],
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
expect(response.status).toBe(200)
|
|
221
|
+
const product: Product = response.body
|
|
222
|
+
expect(product.version).toBe(3)
|
|
223
|
+
expect(product.masterData.hasStagedChanges).toBeFalsy()
|
|
224
|
+
expect(product.masterData.current.masterVariant.attributes).toHaveLength(
|
|
225
|
+
2
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
test('setAttribute masterVariant (published)', async () => {
|
|
231
|
+
assert(productPublished, 'product not created')
|
|
232
|
+
|
|
233
|
+
const response = await supertest(ctMock.app)
|
|
234
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
235
|
+
.send({
|
|
236
|
+
version: 1,
|
|
237
|
+
actions: [
|
|
238
|
+
{
|
|
239
|
+
action: 'setAttribute',
|
|
240
|
+
sku: '1337',
|
|
241
|
+
name: 'foo',
|
|
242
|
+
value: 'bar',
|
|
243
|
+
staged: false,
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
expect(response.status).toBe(200)
|
|
249
|
+
const product: Product = response.body
|
|
250
|
+
|
|
251
|
+
// TODO: Since we auto publish it actually does two version updates. So the
|
|
252
|
+
// version should be 3
|
|
253
|
+
expect(product.version).toBe(2)
|
|
254
|
+
expect(product.masterData.hasStagedChanges).toBeFalsy()
|
|
255
|
+
expect(product.masterData.current.masterVariant.attributes).toHaveLength(2)
|
|
256
|
+
expect(product.masterData.staged.masterVariant.attributes).toHaveLength(2)
|
|
257
|
+
|
|
258
|
+
const attr = response.body.masterData.staged.masterVariant.attributes[1]
|
|
259
|
+
expect(attr).toEqual({ name: 'foo', value: 'bar' })
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
test('setAttribute variant', async () => {
|
|
263
|
+
assert(productPublished, 'product not created')
|
|
264
|
+
|
|
265
|
+
const response = await supertest(ctMock.app)
|
|
266
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
267
|
+
.send({
|
|
268
|
+
version: 1,
|
|
269
|
+
actions: [
|
|
270
|
+
{ action: 'setAttribute', sku: '1338', name: 'foo', value: 'bar' },
|
|
271
|
+
],
|
|
272
|
+
})
|
|
273
|
+
expect(response.status).toBe(200)
|
|
274
|
+
expect(response.body.version).toBe(2)
|
|
275
|
+
expect(response.body.masterData.staged.variants[0].attributes).toHaveLength(
|
|
276
|
+
2
|
|
277
|
+
)
|
|
278
|
+
const attr = response.body.masterData.staged.variants[0].attributes[1]
|
|
279
|
+
expect(attr).toEqual({ name: 'foo', value: 'bar' })
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
test('setAttribute variant and publish', async () => {
|
|
283
|
+
assert(productPublished, 'product not created')
|
|
284
|
+
|
|
285
|
+
const response = await supertest(ctMock.app)
|
|
286
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
287
|
+
.send({
|
|
288
|
+
version: 1,
|
|
289
|
+
actions: [
|
|
290
|
+
{ action: 'setAttribute', sku: '1338', name: 'foo', value: 'bar' },
|
|
291
|
+
{ action: 'publish' },
|
|
292
|
+
],
|
|
293
|
+
})
|
|
294
|
+
expect(response.status).toBe(200)
|
|
295
|
+
expect(response.body.version).toBe(3)
|
|
296
|
+
expect(
|
|
297
|
+
response.body.masterData.current.variants[0].attributes
|
|
298
|
+
).toHaveLength(2)
|
|
299
|
+
const attr = response.body.masterData.current.variants[0].attributes[1]
|
|
300
|
+
expect(attr).toEqual({ name: 'foo', value: 'bar' })
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
test('setAttribute overwrite', async () => {
|
|
304
|
+
assert(productPublished, 'product not created')
|
|
305
|
+
|
|
306
|
+
const response = await supertest(ctMock.app)
|
|
307
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
308
|
+
.send({
|
|
309
|
+
version: 1,
|
|
310
|
+
actions: [
|
|
311
|
+
{ action: 'setAttribute', sku: '1337', name: 'test', value: 'foo' },
|
|
312
|
+
],
|
|
313
|
+
})
|
|
314
|
+
expect(response.status).toBe(200)
|
|
315
|
+
expect(response.body.version).toBe(2)
|
|
316
|
+
expect(
|
|
317
|
+
response.body.masterData.staged.masterVariant.attributes
|
|
318
|
+
).toHaveLength(1)
|
|
319
|
+
const attr = response.body.masterData.staged.masterVariant.attributes[0]
|
|
320
|
+
expect(attr).toEqual({ name: 'test', value: 'foo' })
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
test('addExternalImage variant', async () => {
|
|
324
|
+
assert(productPublished, 'product not created')
|
|
325
|
+
|
|
326
|
+
const image: Image = {
|
|
327
|
+
url: 'http://example.com/image',
|
|
328
|
+
dimensions: { w: 100, h: 100 },
|
|
329
|
+
}
|
|
330
|
+
const response = await supertest(ctMock.app)
|
|
331
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
332
|
+
.send({
|
|
333
|
+
version: 1,
|
|
334
|
+
actions: [{ action: 'addExternalImage', sku: '1338', image }],
|
|
335
|
+
})
|
|
336
|
+
expect(response.status).toBe(200)
|
|
337
|
+
expect(response.body.version).toBe(2)
|
|
338
|
+
expect(response.body.masterData.staged.variants[0].images).toHaveLength(1)
|
|
339
|
+
const attr = response.body.masterData.staged.variants[0].images[0]
|
|
340
|
+
expect(attr).toEqual(image)
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
test('removeImage variant', async () => {
|
|
344
|
+
assert(productPublished, 'product not created')
|
|
345
|
+
|
|
346
|
+
const image: Image = {
|
|
347
|
+
url: 'http://example.com/image',
|
|
348
|
+
dimensions: { w: 100, h: 100 },
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
{
|
|
352
|
+
const response = await supertest(ctMock.app)
|
|
353
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
354
|
+
.send({
|
|
355
|
+
version: 1,
|
|
356
|
+
actions: [{ action: 'addExternalImage', sku: '1338', image }],
|
|
357
|
+
})
|
|
358
|
+
expect(response.status).toBe(200)
|
|
359
|
+
expect(response.body.version).toBe(2)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const response = await supertest(ctMock.app)
|
|
363
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
364
|
+
.send({
|
|
365
|
+
version: 2,
|
|
366
|
+
actions: [
|
|
367
|
+
{
|
|
368
|
+
action: 'removeImage',
|
|
369
|
+
sku: '1338',
|
|
370
|
+
imageUrl: image.url,
|
|
371
|
+
},
|
|
372
|
+
],
|
|
373
|
+
})
|
|
374
|
+
expect(response.status).toBe(200)
|
|
375
|
+
expect(response.body.version).toBe(3)
|
|
376
|
+
expect(response.body.masterData.staged.variants[0].images).toHaveLength(0)
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
test('moveImageToPosition variant', async () => {
|
|
380
|
+
assert(productPublished, 'product not created')
|
|
381
|
+
|
|
382
|
+
const image1: Image = {
|
|
383
|
+
url: 'http://example.com/image1',
|
|
384
|
+
dimensions: { w: 100, h: 100 },
|
|
385
|
+
}
|
|
386
|
+
const image2: Image = {
|
|
387
|
+
url: 'http://example.com/image2',
|
|
388
|
+
dimensions: { w: 100, h: 100 },
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
{
|
|
392
|
+
const response = await supertest(ctMock.app)
|
|
393
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
394
|
+
.send({
|
|
395
|
+
version: 1,
|
|
396
|
+
actions: [
|
|
397
|
+
{ action: 'addExternalImage', sku: '1338', image: image1 },
|
|
398
|
+
{ action: 'addExternalImage', sku: '1338', image: image2 },
|
|
399
|
+
],
|
|
400
|
+
})
|
|
401
|
+
expect(response.status).toBe(200)
|
|
402
|
+
expect(response.body.version).toBe(3)
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const response = await supertest(ctMock.app)
|
|
406
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
407
|
+
.send({
|
|
408
|
+
version: 3,
|
|
409
|
+
actions: [
|
|
410
|
+
{
|
|
411
|
+
action: 'moveImageToPosition',
|
|
412
|
+
sku: '1338',
|
|
413
|
+
imageUrl: image2.url,
|
|
414
|
+
position: 0,
|
|
415
|
+
},
|
|
416
|
+
],
|
|
417
|
+
})
|
|
418
|
+
expect(response.status).toBe(200)
|
|
419
|
+
expect(response.body.version).toBe(4)
|
|
420
|
+
expect(response.body.masterData.staged.variants[0].images).toEqual([
|
|
421
|
+
{ url: 'http://example.com/image2', dimensions: { w: 100, h: 100 } },
|
|
422
|
+
{ url: 'http://example.com/image1', dimensions: { w: 100, h: 100 } },
|
|
423
|
+
])
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
test('addPrice variant', async () => {
|
|
427
|
+
assert(productPublished, 'product not created')
|
|
428
|
+
|
|
429
|
+
const priceDraft: PriceDraft = {
|
|
430
|
+
country: 'BE',
|
|
431
|
+
value: {
|
|
432
|
+
currencyCode: 'EUR',
|
|
433
|
+
centAmount: 3000,
|
|
434
|
+
},
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
const response = await supertest(ctMock.app)
|
|
438
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
439
|
+
.send({
|
|
440
|
+
version: 1,
|
|
441
|
+
actions: [
|
|
442
|
+
{
|
|
443
|
+
action: 'addPrice',
|
|
444
|
+
price: priceDraft,
|
|
445
|
+
variantId: 1,
|
|
446
|
+
},
|
|
447
|
+
],
|
|
448
|
+
})
|
|
449
|
+
expect(response.status).toBe(200)
|
|
450
|
+
expect(response.body.version).toBe(2)
|
|
451
|
+
expect(response.body.masterData.staged.masterVariant.prices).toMatchObject([
|
|
452
|
+
{
|
|
453
|
+
country: 'NL',
|
|
454
|
+
value: {
|
|
455
|
+
currencyCode: 'EUR',
|
|
456
|
+
centAmount: 1000,
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
country: 'BE',
|
|
461
|
+
value: {
|
|
462
|
+
currencyCode: 'EUR',
|
|
463
|
+
centAmount: 3000,
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
])
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
test('changePrice variant', async () => {
|
|
470
|
+
assert(productPublished, 'product not created')
|
|
471
|
+
const priceId =
|
|
472
|
+
productPublished?.masterData.current.masterVariant.prices?.[0].id
|
|
473
|
+
assert(priceId)
|
|
474
|
+
|
|
475
|
+
const priceDraft: PriceDraft = {
|
|
476
|
+
country: 'BE',
|
|
477
|
+
value: {
|
|
478
|
+
currencyCode: 'EUR',
|
|
479
|
+
centAmount: 3000,
|
|
480
|
+
},
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const response = await supertest(ctMock.app)
|
|
484
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
485
|
+
.send({
|
|
486
|
+
version: 1,
|
|
487
|
+
actions: [
|
|
488
|
+
{
|
|
489
|
+
action: 'changePrice',
|
|
490
|
+
priceId,
|
|
491
|
+
price: priceDraft,
|
|
492
|
+
},
|
|
493
|
+
],
|
|
494
|
+
})
|
|
495
|
+
expect(response.status).toBe(200)
|
|
496
|
+
expect(response.body.version).toBe(2)
|
|
497
|
+
expect(response.body.masterData.staged.masterVariant.prices).toMatchObject([
|
|
498
|
+
{
|
|
499
|
+
id: priceId,
|
|
500
|
+
country: 'BE',
|
|
501
|
+
value: {
|
|
502
|
+
currencyCode: 'EUR',
|
|
503
|
+
centAmount: 3000,
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
])
|
|
507
|
+
})
|
|
508
|
+
|
|
509
|
+
test('removePrice variant', async () => {
|
|
510
|
+
assert(productPublished, 'product not created')
|
|
511
|
+
const priceId =
|
|
512
|
+
productPublished?.masterData.current.masterVariant.prices?.[0].id
|
|
513
|
+
assert(priceId)
|
|
514
|
+
|
|
515
|
+
const response = await supertest(ctMock.app)
|
|
516
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
517
|
+
.send({
|
|
518
|
+
version: 1,
|
|
519
|
+
actions: [
|
|
520
|
+
{
|
|
521
|
+
action: 'removePrice',
|
|
522
|
+
priceId,
|
|
523
|
+
},
|
|
524
|
+
],
|
|
525
|
+
})
|
|
526
|
+
expect(response.status).toBe(200)
|
|
527
|
+
expect(response.body.version).toBe(2)
|
|
528
|
+
expect(response.body.masterData.staged.masterVariant.prices).toHaveLength(0)
|
|
529
|
+
})
|
|
530
530
|
})
|