@labdigital/commercetools-mock 2.2.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +366 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +366 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/category.ts +26 -0
- package/src/repositories/product.ts +484 -20
- package/src/services/category.test.ts +99 -0
- package/src/services/product.test.ts +898 -7
|
@@ -1,26 +1,110 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
Category,
|
|
3
|
+
CategoryDraft,
|
|
2
4
|
Image,
|
|
3
5
|
PriceDraft,
|
|
4
6
|
Product,
|
|
5
7
|
ProductData,
|
|
6
8
|
ProductDraft,
|
|
9
|
+
ProductType,
|
|
10
|
+
ProductTypeDraft,
|
|
11
|
+
State,
|
|
12
|
+
StateDraft,
|
|
13
|
+
TaxCategory,
|
|
14
|
+
TaxCategoryDraft,
|
|
7
15
|
} from '@commercetools/platform-sdk'
|
|
8
16
|
import assert from 'assert'
|
|
9
17
|
import supertest from 'supertest'
|
|
10
|
-
import { beforeEach, describe, expect, test } from 'vitest'
|
|
18
|
+
import { beforeAll, beforeEach, describe, expect, test } from 'vitest'
|
|
11
19
|
import { CommercetoolsMock } from '../index.js'
|
|
12
20
|
|
|
13
|
-
const
|
|
21
|
+
const productTypeDraft: ProductTypeDraft = {
|
|
22
|
+
key: 'test-product-type',
|
|
23
|
+
name: 'Test Product Type',
|
|
24
|
+
description: 'Test Product Type description',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const categoryDraft1: CategoryDraft = {
|
|
28
|
+
key: 'category-1',
|
|
29
|
+
name: {
|
|
30
|
+
'nl-NL': 'Category One',
|
|
31
|
+
},
|
|
32
|
+
slug: {
|
|
33
|
+
'nl-NL': 'category_1',
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const categoryDraft2: CategoryDraft = {
|
|
38
|
+
key: 'category-2',
|
|
39
|
+
name: {
|
|
40
|
+
'nl-NL': 'Category Two',
|
|
41
|
+
},
|
|
42
|
+
slug: {
|
|
43
|
+
'nl-NL': 'category_2',
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const taxcategoryDraft1: TaxCategoryDraft = {
|
|
48
|
+
name: 'Tax category 1',
|
|
49
|
+
key: 'tax-category-1',
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const taxcategoryDraft2: TaxCategoryDraft = {
|
|
53
|
+
name: 'Tax category 2',
|
|
54
|
+
key: 'tax-category-2',
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const productState1Draft: StateDraft = {
|
|
58
|
+
key: 'initial-state',
|
|
59
|
+
type: 'ProductState',
|
|
60
|
+
initial: true,
|
|
61
|
+
name: {
|
|
62
|
+
'nl-NL': 'Initial state',
|
|
63
|
+
},
|
|
64
|
+
description: {
|
|
65
|
+
'nl-NL': 'Product initial state',
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const productState2Draft: StateDraft = {
|
|
70
|
+
key: 'another-state',
|
|
71
|
+
type: 'ProductState',
|
|
72
|
+
initial: true,
|
|
73
|
+
name: {
|
|
74
|
+
'nl-NL': 'Another state',
|
|
75
|
+
},
|
|
76
|
+
description: {
|
|
77
|
+
'nl-NL': 'Product another state',
|
|
78
|
+
},
|
|
79
|
+
}
|
|
14
80
|
|
|
15
81
|
const publishedProductDraft: ProductDraft = {
|
|
16
82
|
name: {
|
|
17
83
|
'nl-NL': 'test published product',
|
|
18
84
|
},
|
|
85
|
+
description: {
|
|
86
|
+
'nl-NL': 'Test published product description',
|
|
87
|
+
},
|
|
19
88
|
productType: {
|
|
20
89
|
typeId: 'product-type',
|
|
21
|
-
|
|
90
|
+
key: 'test-product-type',
|
|
91
|
+
},
|
|
92
|
+
categories: [
|
|
93
|
+
{
|
|
94
|
+
typeId: 'category',
|
|
95
|
+
key: 'category-1',
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
taxCategory: {
|
|
99
|
+
typeId: 'tax-category',
|
|
100
|
+
key: taxcategoryDraft1.key,
|
|
101
|
+
},
|
|
102
|
+
state: {
|
|
103
|
+
typeId: 'state',
|
|
104
|
+
key: 'initial-state',
|
|
22
105
|
},
|
|
23
106
|
masterVariant: {
|
|
107
|
+
key: 'master-variant-key',
|
|
24
108
|
sku: '1337',
|
|
25
109
|
attributes: [
|
|
26
110
|
{
|
|
@@ -30,6 +114,7 @@ const publishedProductDraft: ProductDraft = {
|
|
|
30
114
|
],
|
|
31
115
|
prices: [
|
|
32
116
|
{
|
|
117
|
+
key: 'base_price_eur',
|
|
33
118
|
country: 'NL',
|
|
34
119
|
value: {
|
|
35
120
|
currencyCode: 'EUR',
|
|
@@ -40,6 +125,7 @@ const publishedProductDraft: ProductDraft = {
|
|
|
40
125
|
},
|
|
41
126
|
variants: [
|
|
42
127
|
{
|
|
128
|
+
key: 'variant-1-key',
|
|
43
129
|
sku: '1338',
|
|
44
130
|
attributes: [
|
|
45
131
|
{
|
|
@@ -49,6 +135,7 @@ const publishedProductDraft: ProductDraft = {
|
|
|
49
135
|
],
|
|
50
136
|
prices: [
|
|
51
137
|
{
|
|
138
|
+
key: 'base_price_eur',
|
|
52
139
|
country: 'NL',
|
|
53
140
|
value: {
|
|
54
141
|
currencyCode: 'EUR',
|
|
@@ -61,18 +148,46 @@ const publishedProductDraft: ProductDraft = {
|
|
|
61
148
|
slug: {
|
|
62
149
|
'nl-NL': 'test-published-product',
|
|
63
150
|
},
|
|
151
|
+
metaTitle: {
|
|
152
|
+
'nl-NL': 'Unpublished product (meta title)',
|
|
153
|
+
},
|
|
154
|
+
metaDescription: {
|
|
155
|
+
'nl-NL': 'Unpublished product description (meta description)',
|
|
156
|
+
},
|
|
157
|
+
metaKeywords: {
|
|
158
|
+
'nl-NL': 'Test product (meta Keywords)',
|
|
159
|
+
},
|
|
64
160
|
publish: true,
|
|
65
161
|
}
|
|
66
162
|
|
|
67
163
|
const unpublishedProductDraft: ProductDraft = {
|
|
164
|
+
key: 'test-unpublished-product',
|
|
68
165
|
name: {
|
|
69
166
|
'nl-NL': 'test unpublished product',
|
|
70
167
|
},
|
|
168
|
+
description: {
|
|
169
|
+
'nl-NL': 'Test published product description',
|
|
170
|
+
},
|
|
71
171
|
productType: {
|
|
72
172
|
typeId: 'product-type',
|
|
73
|
-
|
|
173
|
+
key: 'test-product-type',
|
|
174
|
+
},
|
|
175
|
+
categories: [
|
|
176
|
+
{
|
|
177
|
+
typeId: 'category',
|
|
178
|
+
key: 'category-1',
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
taxCategory: {
|
|
182
|
+
typeId: 'tax-category',
|
|
183
|
+
key: taxcategoryDraft1.key,
|
|
184
|
+
},
|
|
185
|
+
state: {
|
|
186
|
+
typeId: 'state',
|
|
187
|
+
key: 'initial-state',
|
|
74
188
|
},
|
|
75
189
|
masterVariant: {
|
|
190
|
+
key: 'master-variant-key',
|
|
76
191
|
sku: '2337',
|
|
77
192
|
attributes: [
|
|
78
193
|
{
|
|
@@ -80,9 +195,20 @@ const unpublishedProductDraft: ProductDraft = {
|
|
|
80
195
|
value: 'test',
|
|
81
196
|
},
|
|
82
197
|
],
|
|
198
|
+
prices: [
|
|
199
|
+
{
|
|
200
|
+
key: 'base_price_eur',
|
|
201
|
+
country: 'NL',
|
|
202
|
+
value: {
|
|
203
|
+
currencyCode: 'EUR',
|
|
204
|
+
centAmount: 1000,
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
],
|
|
83
208
|
},
|
|
84
209
|
variants: [
|
|
85
210
|
{
|
|
211
|
+
key: 'variant-1-key',
|
|
86
212
|
sku: '2338',
|
|
87
213
|
attributes: [
|
|
88
214
|
{
|
|
@@ -90,16 +216,109 @@ const unpublishedProductDraft: ProductDraft = {
|
|
|
90
216
|
value: 'test2',
|
|
91
217
|
},
|
|
92
218
|
],
|
|
219
|
+
prices: [
|
|
220
|
+
{
|
|
221
|
+
key: 'base_price_eur',
|
|
222
|
+
country: 'NL',
|
|
223
|
+
value: {
|
|
224
|
+
currencyCode: 'EUR',
|
|
225
|
+
centAmount: 2000,
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
],
|
|
93
229
|
},
|
|
94
230
|
],
|
|
95
231
|
slug: {
|
|
96
232
|
'nl-NL': 'test-unpublished-product',
|
|
97
233
|
},
|
|
234
|
+
metaTitle: {
|
|
235
|
+
'nl-NL': 'Unpublished product (meta title)',
|
|
236
|
+
},
|
|
237
|
+
metaDescription: {
|
|
238
|
+
'nl-NL': 'Unpublished product description (meta description)',
|
|
239
|
+
},
|
|
240
|
+
metaKeywords: {
|
|
241
|
+
'nl-NL': 'Test product (meta Keywords)',
|
|
242
|
+
},
|
|
98
243
|
publish: false,
|
|
99
244
|
}
|
|
100
245
|
|
|
246
|
+
let productType: ProductType
|
|
247
|
+
let category1: Category
|
|
248
|
+
let category2: Category
|
|
249
|
+
let taxCategory1: TaxCategory
|
|
250
|
+
let taxCategory2: TaxCategory
|
|
251
|
+
let productState1: State
|
|
252
|
+
let productState2: State
|
|
253
|
+
|
|
254
|
+
async function beforeAllProductTests(mock) {
|
|
255
|
+
let response
|
|
256
|
+
// Create Product Type
|
|
257
|
+
response = await supertest(mock.app)
|
|
258
|
+
.post('/dummy/product-types')
|
|
259
|
+
.send(productTypeDraft)
|
|
260
|
+
|
|
261
|
+
expect(response.status).toBe(201)
|
|
262
|
+
productType = response.body
|
|
263
|
+
|
|
264
|
+
// Create Category 1
|
|
265
|
+
response = await supertest(mock.app)
|
|
266
|
+
.post('/dummy/categories')
|
|
267
|
+
.send(categoryDraft1)
|
|
268
|
+
|
|
269
|
+
expect(response.status).toBe(201)
|
|
270
|
+
category1 = response.body
|
|
271
|
+
|
|
272
|
+
// Create Category 2
|
|
273
|
+
response = await supertest(mock.app)
|
|
274
|
+
.post('/dummy/categories')
|
|
275
|
+
.send(categoryDraft2)
|
|
276
|
+
|
|
277
|
+
expect(response.status).toBe(201)
|
|
278
|
+
category2 = response.body
|
|
279
|
+
|
|
280
|
+
// Create Tax Category 1
|
|
281
|
+
response = await supertest(mock.app)
|
|
282
|
+
.post('/dummy/tax-categories')
|
|
283
|
+
.send(taxcategoryDraft1)
|
|
284
|
+
|
|
285
|
+
expect(response.status).toBe(201)
|
|
286
|
+
taxCategory1 = response.body
|
|
287
|
+
|
|
288
|
+
// Create Tax Category 2
|
|
289
|
+
response = await supertest(mock.app)
|
|
290
|
+
.post('/dummy/tax-categories')
|
|
291
|
+
.send(taxcategoryDraft2)
|
|
292
|
+
|
|
293
|
+
expect(response.status).toBe(201)
|
|
294
|
+
taxCategory2 = response.body
|
|
295
|
+
|
|
296
|
+
// Create Product State 1
|
|
297
|
+
response = await supertest(mock.app)
|
|
298
|
+
.post('/dummy/states')
|
|
299
|
+
.send(productState1Draft)
|
|
300
|
+
|
|
301
|
+
expect(response.status).toBe(201)
|
|
302
|
+
productState1 = response.body
|
|
303
|
+
|
|
304
|
+
// Create Product State 2
|
|
305
|
+
response = await supertest(mock.app)
|
|
306
|
+
.post('/dummy/states')
|
|
307
|
+
.send(productState2Draft)
|
|
308
|
+
|
|
309
|
+
expect(response.status).toBe(201)
|
|
310
|
+
productState2 = response.body
|
|
311
|
+
}
|
|
312
|
+
|
|
101
313
|
describe('Product', () => {
|
|
314
|
+
const ctMock = new CommercetoolsMock()
|
|
315
|
+
beforeAll(async () => {
|
|
316
|
+
await beforeAllProductTests(ctMock)
|
|
317
|
+
})
|
|
318
|
+
|
|
102
319
|
test('Create product', async () => {
|
|
320
|
+
assert(productType, 'product type not created')
|
|
321
|
+
|
|
103
322
|
const response = await supertest(ctMock.app)
|
|
104
323
|
.post('/dummy/products')
|
|
105
324
|
.send(unpublishedProductDraft)
|
|
@@ -108,11 +327,30 @@ describe('Product', () => {
|
|
|
108
327
|
name: {
|
|
109
328
|
'nl-NL': 'test unpublished product',
|
|
110
329
|
},
|
|
330
|
+
description: {
|
|
331
|
+
'nl-NL': 'Test published product description',
|
|
332
|
+
},
|
|
111
333
|
slug: {
|
|
112
334
|
'nl-NL': 'test-unpublished-product',
|
|
113
335
|
},
|
|
114
|
-
categories: [
|
|
336
|
+
categories: [
|
|
337
|
+
{
|
|
338
|
+
id: category1.id,
|
|
339
|
+
typeId: 'category',
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
metaTitle: {
|
|
343
|
+
'nl-NL': 'Unpublished product (meta title)',
|
|
344
|
+
},
|
|
345
|
+
metaDescription: {
|
|
346
|
+
'nl-NL': 'Unpublished product description (meta description)',
|
|
347
|
+
},
|
|
348
|
+
metaKeywords: {
|
|
349
|
+
'nl-NL': 'Test product (meta Keywords)',
|
|
350
|
+
},
|
|
115
351
|
masterVariant: {
|
|
352
|
+
id: 1,
|
|
353
|
+
key: 'master-variant-key',
|
|
116
354
|
sku: '2337',
|
|
117
355
|
assets: [],
|
|
118
356
|
attributes: [
|
|
@@ -121,11 +359,24 @@ describe('Product', () => {
|
|
|
121
359
|
value: 'test',
|
|
122
360
|
},
|
|
123
361
|
],
|
|
124
|
-
|
|
362
|
+
prices: [
|
|
363
|
+
{
|
|
364
|
+
id: expect.anything(),
|
|
365
|
+
key: 'base_price_eur',
|
|
366
|
+
country: 'NL',
|
|
367
|
+
value: {
|
|
368
|
+
type: 'centPrecision',
|
|
369
|
+
centAmount: 1000,
|
|
370
|
+
currencyCode: 'EUR',
|
|
371
|
+
fractionDigits: 2,
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
],
|
|
125
375
|
images: [],
|
|
126
376
|
},
|
|
127
377
|
variants: [
|
|
128
378
|
{
|
|
379
|
+
key: 'variant-1-key',
|
|
129
380
|
sku: '2338',
|
|
130
381
|
assets: [],
|
|
131
382
|
id: 2,
|
|
@@ -136,6 +387,19 @@ describe('Product', () => {
|
|
|
136
387
|
value: 'test2',
|
|
137
388
|
},
|
|
138
389
|
],
|
|
390
|
+
prices: [
|
|
391
|
+
{
|
|
392
|
+
id: expect.anything(),
|
|
393
|
+
key: 'base_price_eur',
|
|
394
|
+
country: 'NL',
|
|
395
|
+
value: {
|
|
396
|
+
type: 'centPrecision',
|
|
397
|
+
centAmount: 2000,
|
|
398
|
+
currencyCode: 'EUR',
|
|
399
|
+
fractionDigits: 2,
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
],
|
|
139
403
|
},
|
|
140
404
|
],
|
|
141
405
|
searchKeywords: {},
|
|
@@ -145,6 +409,11 @@ describe('Product', () => {
|
|
|
145
409
|
createdAt: expect.anything(),
|
|
146
410
|
id: expect.anything(),
|
|
147
411
|
lastModifiedAt: expect.anything(),
|
|
412
|
+
key: 'test-unpublished-product',
|
|
413
|
+
taxCategory: {
|
|
414
|
+
typeId: 'tax-category',
|
|
415
|
+
id: taxCategory1.id,
|
|
416
|
+
},
|
|
148
417
|
masterData: {
|
|
149
418
|
staged: productData,
|
|
150
419
|
current: productData,
|
|
@@ -153,7 +422,11 @@ describe('Product', () => {
|
|
|
153
422
|
},
|
|
154
423
|
productType: {
|
|
155
424
|
typeId: 'product-type',
|
|
156
|
-
id:
|
|
425
|
+
id: productType.id,
|
|
426
|
+
},
|
|
427
|
+
state: {
|
|
428
|
+
typeId: 'state',
|
|
429
|
+
id: productState1.id,
|
|
157
430
|
},
|
|
158
431
|
version: 1,
|
|
159
432
|
} as Product)
|
|
@@ -163,6 +436,9 @@ describe('Product', () => {
|
|
|
163
436
|
describe('Product update actions', () => {
|
|
164
437
|
const ctMock = new CommercetoolsMock()
|
|
165
438
|
let productPublished: Product | undefined
|
|
439
|
+
beforeAll(async () => {
|
|
440
|
+
await beforeAllProductTests(ctMock)
|
|
441
|
+
})
|
|
166
442
|
|
|
167
443
|
beforeEach(async () => {
|
|
168
444
|
let response
|
|
@@ -318,6 +594,106 @@ describe('Product update actions', () => {
|
|
|
318
594
|
expect(attr).toEqual({ name: 'test', value: 'foo' })
|
|
319
595
|
})
|
|
320
596
|
|
|
597
|
+
test('setAttributeInAllVariants overwrite', async () => {
|
|
598
|
+
assert(productPublished, 'product not created')
|
|
599
|
+
const response = await supertest(ctMock.app)
|
|
600
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
601
|
+
.send({
|
|
602
|
+
version: 1,
|
|
603
|
+
actions: [
|
|
604
|
+
{
|
|
605
|
+
action: 'setAttributeInAllVariants',
|
|
606
|
+
name: 'test',
|
|
607
|
+
value: 'foo',
|
|
608
|
+
},
|
|
609
|
+
],
|
|
610
|
+
})
|
|
611
|
+
expect(response.status).toBe(200)
|
|
612
|
+
expect(response.body.version).toBe(2)
|
|
613
|
+
expect(
|
|
614
|
+
response.body.masterData.staged.masterVariant.attributes
|
|
615
|
+
).toHaveLength(1)
|
|
616
|
+
|
|
617
|
+
const masterVariantAttr1 =
|
|
618
|
+
response.body.masterData.staged.masterVariant.attributes[0]
|
|
619
|
+
expect(masterVariantAttr1).toEqual({ name: 'test', value: 'foo' })
|
|
620
|
+
|
|
621
|
+
response.body.masterData.staged.variants.forEach((variant) => {
|
|
622
|
+
expect(variant.attributes).toHaveLength(2)
|
|
623
|
+
expect(variant.attributes[1]).toEqual({
|
|
624
|
+
name: 'test',
|
|
625
|
+
value: 'foo',
|
|
626
|
+
})
|
|
627
|
+
})
|
|
628
|
+
})
|
|
629
|
+
|
|
630
|
+
test('setAttributeInAllVariants product staged', async () => {
|
|
631
|
+
assert(productPublished, 'product not created')
|
|
632
|
+
const response = await supertest(ctMock.app)
|
|
633
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
634
|
+
.send({
|
|
635
|
+
version: 1,
|
|
636
|
+
actions: [
|
|
637
|
+
{
|
|
638
|
+
action: 'setAttributeInAllVariants',
|
|
639
|
+
name: 'foo',
|
|
640
|
+
value: 'bar',
|
|
641
|
+
},
|
|
642
|
+
],
|
|
643
|
+
})
|
|
644
|
+
expect(response.status).toBe(200)
|
|
645
|
+
expect(response.body.version).toBe(2)
|
|
646
|
+
expect(
|
|
647
|
+
response.body.masterData.staged.masterVariant.attributes
|
|
648
|
+
).toHaveLength(2)
|
|
649
|
+
const masterVariantAttr1 =
|
|
650
|
+
response.body.masterData.staged.masterVariant.attributes[0]
|
|
651
|
+
expect(masterVariantAttr1).toEqual({ name: 'test', value: 'test' })
|
|
652
|
+
|
|
653
|
+
const masterVariantAttr2 =
|
|
654
|
+
response.body.masterData.staged.masterVariant.attributes[1]
|
|
655
|
+
expect(masterVariantAttr2).toEqual({
|
|
656
|
+
name: 'foo',
|
|
657
|
+
value: 'bar',
|
|
658
|
+
})
|
|
659
|
+
response.body.masterData.staged.variants.forEach((variant) => {
|
|
660
|
+
expect(variant.attributes).toHaveLength(2)
|
|
661
|
+
expect(variant.attributes[1]).toEqual({
|
|
662
|
+
name: 'foo',
|
|
663
|
+
value: 'bar',
|
|
664
|
+
})
|
|
665
|
+
})
|
|
666
|
+
})
|
|
667
|
+
|
|
668
|
+
test('setAttributeInAllVariants and publish', async () => {
|
|
669
|
+
assert(productPublished, 'product not created')
|
|
670
|
+
|
|
671
|
+
const response = await supertest(ctMock.app)
|
|
672
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
673
|
+
.send({
|
|
674
|
+
version: 1,
|
|
675
|
+
actions: [
|
|
676
|
+
{ action: 'setAttributeInAllVariants', name: 'foo', value: 'bar' },
|
|
677
|
+
{ action: 'publish' },
|
|
678
|
+
],
|
|
679
|
+
})
|
|
680
|
+
expect(response.status).toBe(200)
|
|
681
|
+
expect(response.body.version).toBe(3)
|
|
682
|
+
expect(
|
|
683
|
+
response.body.masterData.current.masterVariant.attributes
|
|
684
|
+
).toHaveLength(2)
|
|
685
|
+
const attr = response.body.masterData.current.masterVariant.attributes[1]
|
|
686
|
+
expect(attr).toEqual({ name: 'foo', value: 'bar' })
|
|
687
|
+
|
|
688
|
+
response.body.masterData.current.variants.forEach((variant) => {
|
|
689
|
+
expect(variant.attributes).toHaveLength(2)
|
|
690
|
+
expect(variant.attributes[1]).toEqual({
|
|
691
|
+
name: 'foo',
|
|
692
|
+
value: 'bar',
|
|
693
|
+
})
|
|
694
|
+
})
|
|
695
|
+
})
|
|
696
|
+
|
|
321
697
|
test('addExternalImage variant', async () => {
|
|
322
698
|
assert(productPublished, 'product not created')
|
|
323
699
|
|
|
@@ -441,6 +817,7 @@ describe('Product update actions', () => {
|
|
|
441
817
|
action: 'addPrice',
|
|
442
818
|
price: priceDraft,
|
|
443
819
|
variantId: 1,
|
|
820
|
+
staged: false,
|
|
444
821
|
},
|
|
445
822
|
],
|
|
446
823
|
})
|
|
@@ -462,6 +839,9 @@ describe('Product update actions', () => {
|
|
|
462
839
|
},
|
|
463
840
|
},
|
|
464
841
|
])
|
|
842
|
+
expect(response.body.masterData.staged.masterVariant.prices[1].id).toBe(
|
|
843
|
+
response.body.masterData.current.masterVariant.prices[1].id
|
|
844
|
+
)
|
|
465
845
|
})
|
|
466
846
|
|
|
467
847
|
test('changePrice variant', async () => {
|
|
@@ -525,4 +905,515 @@ describe('Product update actions', () => {
|
|
|
525
905
|
expect(response.body.version).toBe(2)
|
|
526
906
|
expect(response.body.masterData.staged.masterVariant.prices).toHaveLength(0)
|
|
527
907
|
})
|
|
908
|
+
|
|
909
|
+
test('changeName product', async () => {
|
|
910
|
+
assert(productPublished, 'product not created')
|
|
911
|
+
const response = await supertest(ctMock.app)
|
|
912
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
913
|
+
.send({
|
|
914
|
+
version: 1,
|
|
915
|
+
actions: [
|
|
916
|
+
{
|
|
917
|
+
action: 'changeName',
|
|
918
|
+
name: 'new test published product',
|
|
919
|
+
staged: false,
|
|
920
|
+
},
|
|
921
|
+
],
|
|
922
|
+
})
|
|
923
|
+
expect(response.status).toBe(200)
|
|
924
|
+
expect(response.body.version).toBe(2)
|
|
925
|
+
expect(response.body.masterData.staged.name).toBe(
|
|
926
|
+
'new test published product'
|
|
927
|
+
)
|
|
928
|
+
expect(response.body.masterData.current.name).toBe(
|
|
929
|
+
'new test published product'
|
|
930
|
+
)
|
|
931
|
+
})
|
|
932
|
+
|
|
933
|
+
test('changeSlug product', async () => {
|
|
934
|
+
assert(productPublished, 'product not created')
|
|
935
|
+
const response = await supertest(ctMock.app)
|
|
936
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
937
|
+
.send({
|
|
938
|
+
version: 1,
|
|
939
|
+
actions: [
|
|
940
|
+
{
|
|
941
|
+
action: 'changeSlug',
|
|
942
|
+
slug: {
|
|
943
|
+
'nl-NL': 'test-published-product-new',
|
|
944
|
+
},
|
|
945
|
+
staged: false,
|
|
946
|
+
},
|
|
947
|
+
],
|
|
948
|
+
})
|
|
949
|
+
expect(response.status).toBe(200)
|
|
950
|
+
expect(response.body.version).toBe(2)
|
|
951
|
+
expect(response.body.masterData.staged.slug).toMatchObject({
|
|
952
|
+
'nl-NL': 'test-published-product-new',
|
|
953
|
+
})
|
|
954
|
+
expect(response.body.masterData.current.slug).toMatchObject({
|
|
955
|
+
'nl-NL': 'test-published-product-new',
|
|
956
|
+
})
|
|
957
|
+
})
|
|
958
|
+
|
|
959
|
+
test('setMetaTitle product', async () => {
|
|
960
|
+
assert(productPublished, 'product not created')
|
|
961
|
+
const response = await supertest(ctMock.app)
|
|
962
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
963
|
+
.send({
|
|
964
|
+
version: 1,
|
|
965
|
+
actions: [
|
|
966
|
+
{
|
|
967
|
+
action: 'setMetaTitle',
|
|
968
|
+
metaTitle: {
|
|
969
|
+
'nl-NL': 'Unpublished product (new meta title)',
|
|
970
|
+
},
|
|
971
|
+
staged: false,
|
|
972
|
+
},
|
|
973
|
+
],
|
|
974
|
+
})
|
|
975
|
+
expect(response.status).toBe(200)
|
|
976
|
+
expect(response.body.version).toBe(2)
|
|
977
|
+
expect(response.body.masterData.staged.metaTitle).toMatchObject({
|
|
978
|
+
'nl-NL': 'Unpublished product (new meta title)',
|
|
979
|
+
})
|
|
980
|
+
expect(response.body.masterData.current.metaTitle).toMatchObject({
|
|
981
|
+
'nl-NL': 'Unpublished product (new meta title)',
|
|
982
|
+
})
|
|
983
|
+
})
|
|
984
|
+
|
|
985
|
+
test('setMetaDescription product', async () => {
|
|
986
|
+
assert(productPublished, 'product not created')
|
|
987
|
+
const response = await supertest(ctMock.app)
|
|
988
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
989
|
+
.send({
|
|
990
|
+
version: 1,
|
|
991
|
+
actions: [
|
|
992
|
+
{
|
|
993
|
+
action: 'setMetaDescription',
|
|
994
|
+
metaDescription: {
|
|
995
|
+
'nl-NL': 'Unpublished product description (new meta description)',
|
|
996
|
+
},
|
|
997
|
+
staged: false,
|
|
998
|
+
},
|
|
999
|
+
],
|
|
1000
|
+
})
|
|
1001
|
+
expect(response.status).toBe(200)
|
|
1002
|
+
expect(response.body.version).toBe(2)
|
|
1003
|
+
expect(response.body.masterData.staged.metaDescription).toMatchObject({
|
|
1004
|
+
'nl-NL': 'Unpublished product description (new meta description)',
|
|
1005
|
+
})
|
|
1006
|
+
expect(response.body.masterData.current.metaDescription).toMatchObject({
|
|
1007
|
+
'nl-NL': 'Unpublished product description (new meta description)',
|
|
1008
|
+
})
|
|
1009
|
+
})
|
|
1010
|
+
|
|
1011
|
+
test('setMetaKeywords product', async () => {
|
|
1012
|
+
assert(productPublished, 'product not created')
|
|
1013
|
+
const response = await supertest(ctMock.app)
|
|
1014
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1015
|
+
.send({
|
|
1016
|
+
version: 1,
|
|
1017
|
+
actions: [
|
|
1018
|
+
{
|
|
1019
|
+
action: 'setMetaKeywords',
|
|
1020
|
+
metaKeywords: {
|
|
1021
|
+
'nl-NL': 'Test product (newmeta Keywords)',
|
|
1022
|
+
},
|
|
1023
|
+
staged: false,
|
|
1024
|
+
},
|
|
1025
|
+
],
|
|
1026
|
+
})
|
|
1027
|
+
expect(response.status).toBe(200)
|
|
1028
|
+
expect(response.body.version).toBe(2)
|
|
1029
|
+
expect(response.body.masterData.staged.metaKeywords).toMatchObject({
|
|
1030
|
+
'nl-NL': 'Test product (newmeta Keywords)',
|
|
1031
|
+
})
|
|
1032
|
+
expect(response.body.masterData.current.metaKeywords).toMatchObject({
|
|
1033
|
+
'nl-NL': 'Test product (newmeta Keywords)',
|
|
1034
|
+
})
|
|
1035
|
+
})
|
|
1036
|
+
|
|
1037
|
+
test('addVariant product', async () => {
|
|
1038
|
+
assert(productPublished, 'product not created')
|
|
1039
|
+
const response = await supertest(ctMock.app)
|
|
1040
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1041
|
+
.send({
|
|
1042
|
+
version: 1,
|
|
1043
|
+
actions: [
|
|
1044
|
+
{
|
|
1045
|
+
action: 'addVariant',
|
|
1046
|
+
sku: '4567',
|
|
1047
|
+
key: 'variant-2-key',
|
|
1048
|
+
price: [
|
|
1049
|
+
{
|
|
1050
|
+
key: 'base_price_eur',
|
|
1051
|
+
country: 'NL',
|
|
1052
|
+
value: {
|
|
1053
|
+
currencyCode: 'EUR',
|
|
1054
|
+
centAmount: 3000,
|
|
1055
|
+
},
|
|
1056
|
+
},
|
|
1057
|
+
],
|
|
1058
|
+
images: [],
|
|
1059
|
+
attributes: [
|
|
1060
|
+
{
|
|
1061
|
+
name: 'test3',
|
|
1062
|
+
value: 'test3',
|
|
1063
|
+
},
|
|
1064
|
+
],
|
|
1065
|
+
assets: [],
|
|
1066
|
+
staged: false,
|
|
1067
|
+
},
|
|
1068
|
+
],
|
|
1069
|
+
})
|
|
1070
|
+
expect(response.status).toBe(200)
|
|
1071
|
+
expect(response.body.version).toBe(2)
|
|
1072
|
+
expect(response.body.masterData.staged.variants).toHaveLength(2)
|
|
1073
|
+
expect(response.body.masterData.current.variants).toHaveLength(2)
|
|
1074
|
+
expect(response.body.masterData.staged.variants[1].id).toBe(3)
|
|
1075
|
+
expect(response.body.masterData.current.variants[1].id).toBe(3)
|
|
1076
|
+
})
|
|
1077
|
+
|
|
1078
|
+
test('removeVariant by id', async () => {
|
|
1079
|
+
assert(productPublished, 'product not created')
|
|
1080
|
+
const response = await supertest(ctMock.app)
|
|
1081
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1082
|
+
.send({
|
|
1083
|
+
version: 1,
|
|
1084
|
+
actions: [
|
|
1085
|
+
{
|
|
1086
|
+
action: 'removeVariant',
|
|
1087
|
+
id: 2,
|
|
1088
|
+
staged: false,
|
|
1089
|
+
},
|
|
1090
|
+
],
|
|
1091
|
+
})
|
|
1092
|
+
expect(response.status).toBe(200)
|
|
1093
|
+
expect(response.body.version).toBe(2)
|
|
1094
|
+
expect(response.body.masterData.staged.variants).toHaveLength(0)
|
|
1095
|
+
expect(response.body.masterData.current.variants).toHaveLength(0)
|
|
1096
|
+
})
|
|
1097
|
+
|
|
1098
|
+
test('removeVariant by sku', async () => {
|
|
1099
|
+
assert(productPublished, 'product not created')
|
|
1100
|
+
const response = await supertest(ctMock.app)
|
|
1101
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1102
|
+
.send({
|
|
1103
|
+
version: 1,
|
|
1104
|
+
actions: [
|
|
1105
|
+
{
|
|
1106
|
+
action: 'removeVariant',
|
|
1107
|
+
sku: '1338',
|
|
1108
|
+
staged: false,
|
|
1109
|
+
},
|
|
1110
|
+
],
|
|
1111
|
+
})
|
|
1112
|
+
expect(response.status).toBe(200)
|
|
1113
|
+
expect(response.body.version).toBe(2)
|
|
1114
|
+
expect(response.body.masterData.staged.variants).toHaveLength(0)
|
|
1115
|
+
expect(response.body.masterData.current.variants).toHaveLength(0)
|
|
1116
|
+
})
|
|
1117
|
+
|
|
1118
|
+
test('removeVariant master', async () => {
|
|
1119
|
+
assert(productPublished, 'product not created')
|
|
1120
|
+
const response = await supertest(ctMock.app)
|
|
1121
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1122
|
+
.send({
|
|
1123
|
+
version: 1,
|
|
1124
|
+
actions: [
|
|
1125
|
+
{
|
|
1126
|
+
action: 'removeVariant',
|
|
1127
|
+
id: 1,
|
|
1128
|
+
staged: false,
|
|
1129
|
+
},
|
|
1130
|
+
],
|
|
1131
|
+
})
|
|
1132
|
+
expect(response.status).toBe(500)
|
|
1133
|
+
expect(response.body.error).toBe(
|
|
1134
|
+
`Can not remove the variant [ID:1] for [Product:${productPublished.id}] since it's the master variant`
|
|
1135
|
+
)
|
|
1136
|
+
})
|
|
1137
|
+
|
|
1138
|
+
test('changeMasterVariant', async () => {
|
|
1139
|
+
assert(productPublished, 'product not created')
|
|
1140
|
+
const response = await supertest(ctMock.app)
|
|
1141
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1142
|
+
.send({
|
|
1143
|
+
version: 1,
|
|
1144
|
+
actions: [
|
|
1145
|
+
{
|
|
1146
|
+
action: 'changeMasterVariant',
|
|
1147
|
+
sku: '1338',
|
|
1148
|
+
staged: false,
|
|
1149
|
+
},
|
|
1150
|
+
],
|
|
1151
|
+
})
|
|
1152
|
+
expect(response.status).toBe(200)
|
|
1153
|
+
expect(response.body.version).toBe(2)
|
|
1154
|
+
expect(response.body.masterData.staged.variants).toHaveLength(1)
|
|
1155
|
+
expect(response.body.masterData.staged.masterVariant.id).toBe(2)
|
|
1156
|
+
expect(response.body.masterData.staged.variants[0].id).toBe(1)
|
|
1157
|
+
|
|
1158
|
+
expect(response.body.masterData.current.variants).toHaveLength(1)
|
|
1159
|
+
expect(response.body.masterData.current.masterVariant.id).toBe(2)
|
|
1160
|
+
expect(response.body.masterData.current.variants[0].id).toBe(1)
|
|
1161
|
+
})
|
|
1162
|
+
|
|
1163
|
+
test('changeMasterVariant same master', async () => {
|
|
1164
|
+
assert(productPublished, 'product not created')
|
|
1165
|
+
const response = await supertest(ctMock.app)
|
|
1166
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1167
|
+
.send({
|
|
1168
|
+
version: 1,
|
|
1169
|
+
actions: [
|
|
1170
|
+
{
|
|
1171
|
+
action: 'changeMasterVariant',
|
|
1172
|
+
variantId: 1,
|
|
1173
|
+
staged: false,
|
|
1174
|
+
},
|
|
1175
|
+
],
|
|
1176
|
+
})
|
|
1177
|
+
expect(response.status).toBe(200)
|
|
1178
|
+
expect(response.body.version).toBe(1)
|
|
1179
|
+
expect(response.body.masterData.staged.variants).toHaveLength(1)
|
|
1180
|
+
expect(response.body.masterData.staged.masterVariant.id).toBe(1)
|
|
1181
|
+
expect(response.body.masterData.staged.variants[0].id).toBe(2)
|
|
1182
|
+
|
|
1183
|
+
expect(response.body.masterData.current.variants).toHaveLength(1)
|
|
1184
|
+
expect(response.body.masterData.current.masterVariant.id).toBe(1)
|
|
1185
|
+
expect(response.body.masterData.current.variants[0].id).toBe(2)
|
|
1186
|
+
})
|
|
1187
|
+
|
|
1188
|
+
test('setTaxCategory', async () => {
|
|
1189
|
+
assert(productPublished, 'product not created')
|
|
1190
|
+
const response = await supertest(ctMock.app)
|
|
1191
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1192
|
+
.send({
|
|
1193
|
+
version: 1,
|
|
1194
|
+
actions: [
|
|
1195
|
+
{
|
|
1196
|
+
action: 'setTaxCategory',
|
|
1197
|
+
taxCategory: {
|
|
1198
|
+
typeId: 'tax-category',
|
|
1199
|
+
id: taxCategory2.id,
|
|
1200
|
+
},
|
|
1201
|
+
},
|
|
1202
|
+
],
|
|
1203
|
+
})
|
|
1204
|
+
expect(response.status).toBe(200)
|
|
1205
|
+
expect(response.body.taxCategory.id).toBe(taxCategory2.id)
|
|
1206
|
+
})
|
|
1207
|
+
|
|
1208
|
+
test('setTaxCategory fail 1', async () => {
|
|
1209
|
+
assert(productPublished, 'product not created')
|
|
1210
|
+
const fakeTaxCategoryId = '00000000-0000-0000-0000-000000000000'
|
|
1211
|
+
const response = await supertest(ctMock.app)
|
|
1212
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1213
|
+
.send({
|
|
1214
|
+
version: 1,
|
|
1215
|
+
actions: [
|
|
1216
|
+
{
|
|
1217
|
+
action: 'setTaxCategory',
|
|
1218
|
+
taxCategory: {
|
|
1219
|
+
typeId: 'tax-category',
|
|
1220
|
+
id: fakeTaxCategoryId,
|
|
1221
|
+
},
|
|
1222
|
+
},
|
|
1223
|
+
],
|
|
1224
|
+
})
|
|
1225
|
+
expect(response.status).toBe(400)
|
|
1226
|
+
expect(response.body.errors[0].code).toBe('ReferencedResourceNotFound')
|
|
1227
|
+
})
|
|
1228
|
+
|
|
1229
|
+
test('setTaxCategory fail 2', async () => {
|
|
1230
|
+
assert(productPublished, 'product not created')
|
|
1231
|
+
const response = await supertest(ctMock.app)
|
|
1232
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1233
|
+
.send({
|
|
1234
|
+
version: 1,
|
|
1235
|
+
actions: [
|
|
1236
|
+
{
|
|
1237
|
+
action: 'setTaxCategory',
|
|
1238
|
+
taxCategory: {
|
|
1239
|
+
typeId: 'tax-category',
|
|
1240
|
+
},
|
|
1241
|
+
},
|
|
1242
|
+
],
|
|
1243
|
+
})
|
|
1244
|
+
expect(response.status).toBe(400)
|
|
1245
|
+
expect(response.body.errors[0].code).toBe('InvalidJsonInput')
|
|
1246
|
+
})
|
|
1247
|
+
|
|
1248
|
+
test('addToCategory by id', async () => {
|
|
1249
|
+
assert(productPublished, 'product not created')
|
|
1250
|
+
const response = await supertest(ctMock.app)
|
|
1251
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1252
|
+
.send({
|
|
1253
|
+
version: 1,
|
|
1254
|
+
actions: [
|
|
1255
|
+
{
|
|
1256
|
+
action: 'addToCategory',
|
|
1257
|
+
category: {
|
|
1258
|
+
typeId: 'category',
|
|
1259
|
+
id: category2.id,
|
|
1260
|
+
},
|
|
1261
|
+
staged: false,
|
|
1262
|
+
},
|
|
1263
|
+
],
|
|
1264
|
+
})
|
|
1265
|
+
expect(response.status).toBe(200)
|
|
1266
|
+
expect(response.body.masterData.staged.categories).toHaveLength(2)
|
|
1267
|
+
expect(response.body.masterData.current.categories).toHaveLength(2)
|
|
1268
|
+
})
|
|
1269
|
+
|
|
1270
|
+
test('addToCategory by key', async () => {
|
|
1271
|
+
assert(productPublished, 'product not created')
|
|
1272
|
+
const response = await supertest(ctMock.app)
|
|
1273
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1274
|
+
.send({
|
|
1275
|
+
version: 1,
|
|
1276
|
+
actions: [
|
|
1277
|
+
{
|
|
1278
|
+
action: 'addToCategory',
|
|
1279
|
+
category: {
|
|
1280
|
+
typeId: 'category',
|
|
1281
|
+
key: category2.key,
|
|
1282
|
+
},
|
|
1283
|
+
staged: true,
|
|
1284
|
+
},
|
|
1285
|
+
],
|
|
1286
|
+
})
|
|
1287
|
+
expect(response.status).toBe(200)
|
|
1288
|
+
expect(response.body.masterData.staged.categories).toHaveLength(2)
|
|
1289
|
+
expect(response.body.masterData.current.categories).toHaveLength(1)
|
|
1290
|
+
})
|
|
1291
|
+
|
|
1292
|
+
test('addToCategory fail 1', async () => {
|
|
1293
|
+
assert(productPublished, 'product not created')
|
|
1294
|
+
const fakeCategoryId = '00000000-0000-0000-0000-000000000000'
|
|
1295
|
+
const response = await supertest(ctMock.app)
|
|
1296
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1297
|
+
.send({
|
|
1298
|
+
version: 1,
|
|
1299
|
+
actions: [
|
|
1300
|
+
{
|
|
1301
|
+
action: 'addToCategory',
|
|
1302
|
+
category: {
|
|
1303
|
+
typeId: 'category',
|
|
1304
|
+
id: fakeCategoryId,
|
|
1305
|
+
},
|
|
1306
|
+
staged: true,
|
|
1307
|
+
},
|
|
1308
|
+
],
|
|
1309
|
+
})
|
|
1310
|
+
expect(response.status).toBe(400)
|
|
1311
|
+
expect(response.body.errors[0].code).toBe('ReferencedResourceNotFound')
|
|
1312
|
+
})
|
|
1313
|
+
|
|
1314
|
+
test('addToCategory fail 2', async () => {
|
|
1315
|
+
assert(productPublished, 'product not created')
|
|
1316
|
+
const response = await supertest(ctMock.app)
|
|
1317
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1318
|
+
.send({
|
|
1319
|
+
version: 1,
|
|
1320
|
+
actions: [
|
|
1321
|
+
{
|
|
1322
|
+
action: 'addToCategory',
|
|
1323
|
+
category: null,
|
|
1324
|
+
staged: true,
|
|
1325
|
+
},
|
|
1326
|
+
],
|
|
1327
|
+
})
|
|
1328
|
+
expect(response.status).toBe(400)
|
|
1329
|
+
expect(response.body.errors[0].code).toBe('InvalidJsonInput')
|
|
1330
|
+
})
|
|
1331
|
+
|
|
1332
|
+
test('removeFromCategory', async () => {
|
|
1333
|
+
assert(productPublished, 'product not created')
|
|
1334
|
+
const response = await supertest(ctMock.app)
|
|
1335
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1336
|
+
.send({
|
|
1337
|
+
version: 1,
|
|
1338
|
+
actions: [
|
|
1339
|
+
{
|
|
1340
|
+
action: 'removeFromCategory',
|
|
1341
|
+
category: {
|
|
1342
|
+
typeId: 'category',
|
|
1343
|
+
key: category1.key,
|
|
1344
|
+
},
|
|
1345
|
+
staged: false,
|
|
1346
|
+
},
|
|
1347
|
+
],
|
|
1348
|
+
})
|
|
1349
|
+
expect(response.status).toBe(200)
|
|
1350
|
+
expect(response.body.masterData.staged.categories).toHaveLength(0)
|
|
1351
|
+
expect(response.body.masterData.current.categories).toHaveLength(0)
|
|
1352
|
+
})
|
|
1353
|
+
|
|
1354
|
+
test('removeFromCategory fail 1', async () => {
|
|
1355
|
+
assert(productPublished, 'product not created')
|
|
1356
|
+
const response = await supertest(ctMock.app)
|
|
1357
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1358
|
+
.send({
|
|
1359
|
+
version: 1,
|
|
1360
|
+
actions: [
|
|
1361
|
+
{
|
|
1362
|
+
action: 'removeFromCategory',
|
|
1363
|
+
category: {
|
|
1364
|
+
typeId: 'category',
|
|
1365
|
+
id: 'fake-category-id',
|
|
1366
|
+
},
|
|
1367
|
+
staged: false,
|
|
1368
|
+
},
|
|
1369
|
+
],
|
|
1370
|
+
})
|
|
1371
|
+
expect(response.status).toBe(400)
|
|
1372
|
+
expect(response.body.errors[0].code).toBe('ReferencedResourceNotFound')
|
|
1373
|
+
})
|
|
1374
|
+
|
|
1375
|
+
test('removeFromCategory fail 2', async () => {
|
|
1376
|
+
assert(productPublished, 'product not created')
|
|
1377
|
+
const response = await supertest(ctMock.app)
|
|
1378
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1379
|
+
.send({
|
|
1380
|
+
version: 1,
|
|
1381
|
+
actions: [
|
|
1382
|
+
{
|
|
1383
|
+
action: 'removeFromCategory',
|
|
1384
|
+
category: {
|
|
1385
|
+
typeId: 'category',
|
|
1386
|
+
id: category2.id,
|
|
1387
|
+
},
|
|
1388
|
+
staged: false,
|
|
1389
|
+
},
|
|
1390
|
+
],
|
|
1391
|
+
})
|
|
1392
|
+
expect(response.status).toBe(400)
|
|
1393
|
+
expect(response.body.errors[0].code).toBe('InvalidOperation')
|
|
1394
|
+
})
|
|
1395
|
+
|
|
1396
|
+
test('transitionState', async () => {
|
|
1397
|
+
assert(productPublished, 'product not created')
|
|
1398
|
+
const response = await supertest(ctMock.app)
|
|
1399
|
+
.post(`/dummy/products/${productPublished.id}`)
|
|
1400
|
+
.send({
|
|
1401
|
+
version: 1,
|
|
1402
|
+
actions: [
|
|
1403
|
+
{
|
|
1404
|
+
action: 'transitionState',
|
|
1405
|
+
state: {
|
|
1406
|
+
typeId: 'state',
|
|
1407
|
+
id: productState2.id,
|
|
1408
|
+
},
|
|
1409
|
+
force: false,
|
|
1410
|
+
},
|
|
1411
|
+
],
|
|
1412
|
+
})
|
|
1413
|
+
expect(response.status).toBe(200)
|
|
1414
|
+
expect(response.body.state).toMatchObject({
|
|
1415
|
+
typeId: 'state',
|
|
1416
|
+
id: productState2.id,
|
|
1417
|
+
})
|
|
1418
|
+
})
|
|
528
1419
|
})
|