@labdigital/commercetools-mock 2.53.1 → 2.54.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.js +52 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/predicateParser.test.ts +39 -0
- package/src/lib/predicateParser.ts +2 -0
- package/src/repositories/business-unit.ts +157 -2
- package/src/services/business-units.test.ts +586 -15
- package/src/testing/business-unit.ts +48 -0
- package/src/testing/type.ts +20 -0
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
import type { BusinessUnit } from "@commercetools/platform-sdk";
|
|
1
|
+
import type { BusinessUnit, CompanyDraft } from "@commercetools/platform-sdk";
|
|
2
2
|
import supertest from "supertest";
|
|
3
3
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
4
|
+
import { businessUnitDraftFactory } from "~src/testing/business-unit";
|
|
5
|
+
import { customerDraftFactory } from "~src/testing/customer";
|
|
6
|
+
import { typeDraftFactory } from "~src/testing/type";
|
|
4
7
|
import { CommercetoolsMock } from "../ctMock";
|
|
5
8
|
|
|
6
9
|
describe("Business units query", () => {
|
|
7
10
|
const ctMock = new CommercetoolsMock();
|
|
8
11
|
let businessUnit: BusinessUnit | undefined;
|
|
9
12
|
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
ctMock.clear();
|
|
15
|
+
});
|
|
16
|
+
|
|
10
17
|
beforeEach(async () => {
|
|
18
|
+
const draft = businessUnitDraftFactory(ctMock).build();
|
|
19
|
+
|
|
11
20
|
const response = await supertest(ctMock.app)
|
|
12
21
|
.post("/dummy/business-units")
|
|
13
|
-
.send(
|
|
14
|
-
key: "example-business-unit",
|
|
15
|
-
status: "Active",
|
|
16
|
-
name: "Example Business Unit",
|
|
17
|
-
unitType: "Company",
|
|
18
|
-
});
|
|
19
|
-
|
|
22
|
+
.send(draft);
|
|
20
23
|
expect(response.status).toBe(201);
|
|
21
|
-
|
|
22
24
|
businessUnit = response.body as BusinessUnit;
|
|
23
25
|
});
|
|
24
26
|
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
ctMock.clear();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
27
|
test("no filter", async () => {
|
|
30
28
|
const response = await supertest(ctMock.app)
|
|
31
29
|
.get("/dummy/business-units")
|
|
@@ -34,9 +32,582 @@ describe("Business units query", () => {
|
|
|
34
32
|
|
|
35
33
|
expect(response.status).toBe(200);
|
|
36
34
|
expect(response.body.count).toBe(1);
|
|
37
|
-
|
|
38
35
|
businessUnit = response.body.results[0] as BusinessUnit;
|
|
36
|
+
expect(businessUnit.key).toBe("test-business-unit");
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("Business Unit Update Actions", () => {
|
|
41
|
+
const ctMock = new CommercetoolsMock();
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
ctMock.clear();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("addAddress", async () => {
|
|
48
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
49
|
+
|
|
50
|
+
const response = await supertest(ctMock.app)
|
|
51
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
52
|
+
.send({
|
|
53
|
+
version: 1,
|
|
54
|
+
actions: [
|
|
55
|
+
{
|
|
56
|
+
action: "addAddress",
|
|
57
|
+
address: {
|
|
58
|
+
firstName: "Foo",
|
|
59
|
+
lastName: "Bar",
|
|
60
|
+
streetName: "Baz Street",
|
|
61
|
+
streetNumber: "99",
|
|
62
|
+
postalCode: "12ab",
|
|
63
|
+
country: "NL",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
expect(response.status).toBe(200);
|
|
69
|
+
expect(response.body.version).toBe(2);
|
|
70
|
+
expect(response.body.addresses).toHaveLength(2);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("removeAddress by ID", async () => {
|
|
74
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
75
|
+
|
|
76
|
+
const response = await supertest(ctMock.app)
|
|
77
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
78
|
+
.send({
|
|
79
|
+
version: 1,
|
|
80
|
+
actions: [
|
|
81
|
+
{
|
|
82
|
+
action: "removeAddress",
|
|
83
|
+
addressId: businessUnit.addresses[0].id,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
expect(response.status, JSON.stringify(response.body)).toBe(200);
|
|
88
|
+
expect(response.body.version).toBe(2);
|
|
89
|
+
expect(response.body.addresses).toHaveLength(0);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("changeAddress by ID", async () => {
|
|
93
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
94
|
+
|
|
95
|
+
const addressId = businessUnit.addresses[0].id;
|
|
96
|
+
|
|
97
|
+
const response = await supertest(ctMock.app)
|
|
98
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
99
|
+
.send({
|
|
100
|
+
version: 1,
|
|
101
|
+
actions: [
|
|
102
|
+
{
|
|
103
|
+
action: "changeAddress",
|
|
104
|
+
addressId: addressId,
|
|
105
|
+
address: {
|
|
106
|
+
firstName: "Foo",
|
|
107
|
+
lastName: "Bar",
|
|
108
|
+
streetName: "Baz Street",
|
|
109
|
+
streetNumber: "99",
|
|
110
|
+
postalCode: "12ab",
|
|
111
|
+
country: "NL",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
});
|
|
116
|
+
expect(response.status, JSON.stringify(response.body)).toBe(200);
|
|
117
|
+
const result = response.body as BusinessUnit;
|
|
118
|
+
expect(result.version).toBe(2);
|
|
119
|
+
expect(result.addresses).toHaveLength(1);
|
|
120
|
+
expect(result.addresses).toStrictEqual([
|
|
121
|
+
{
|
|
122
|
+
id: addressId,
|
|
123
|
+
firstName: "Foo",
|
|
124
|
+
lastName: "Bar",
|
|
125
|
+
streetName: "Baz Street",
|
|
126
|
+
streetNumber: "99",
|
|
127
|
+
postalCode: "12ab",
|
|
128
|
+
country: "NL",
|
|
129
|
+
},
|
|
130
|
+
]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("addShippingAddressId", async () => {
|
|
134
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
135
|
+
|
|
136
|
+
const response = await supertest(ctMock.app)
|
|
137
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
138
|
+
.send({
|
|
139
|
+
version: 1,
|
|
140
|
+
actions: [
|
|
141
|
+
{
|
|
142
|
+
action: "addShippingAddressId",
|
|
143
|
+
addressId: businessUnit.addresses[0].id,
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
});
|
|
147
|
+
expect(response.status).toBe(200);
|
|
148
|
+
expect(response.body.version).toBe(2);
|
|
149
|
+
expect(response.body.shippingAddressIds).toHaveLength(1);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("removeShippingAddressId", async () => {
|
|
153
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
154
|
+
|
|
155
|
+
const addressId = businessUnit.addresses[0].id;
|
|
156
|
+
await supertest(ctMock.app)
|
|
157
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
158
|
+
.send({
|
|
159
|
+
version: 1,
|
|
160
|
+
actions: [
|
|
161
|
+
{
|
|
162
|
+
action: "addShippingAddressId",
|
|
163
|
+
addressId: addressId,
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const response = await supertest(ctMock.app)
|
|
169
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
170
|
+
.send({
|
|
171
|
+
version: 2,
|
|
172
|
+
actions: [
|
|
173
|
+
{
|
|
174
|
+
action: "removeShippingAddressId",
|
|
175
|
+
addressId: addressId,
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
});
|
|
179
|
+
expect(response.status).toBe(200);
|
|
180
|
+
const result = response.body as BusinessUnit;
|
|
181
|
+
expect(result.version).toBe(3);
|
|
182
|
+
expect(result.shippingAddressIds).toHaveLength(0);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("setDefaultShippingAddress by ID", async () => {
|
|
186
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
187
|
+
|
|
188
|
+
const addressId = businessUnit.addresses[0].id;
|
|
189
|
+
|
|
190
|
+
const response = await supertest(ctMock.app)
|
|
191
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
192
|
+
.send({
|
|
193
|
+
version: businessUnit.version,
|
|
194
|
+
actions: [
|
|
195
|
+
{
|
|
196
|
+
action: "setDefaultShippingAddress",
|
|
197
|
+
addressId: addressId,
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
});
|
|
201
|
+
expect(response.status, JSON.stringify(response.body)).toBe(200);
|
|
202
|
+
expect(response.body.version).toBe(2);
|
|
203
|
+
expect(response.body.defaultShippingAddressId).toBe(addressId);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("addBillingAddressId", async () => {
|
|
207
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
208
|
+
|
|
209
|
+
const response = await supertest(ctMock.app)
|
|
210
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
211
|
+
.send({
|
|
212
|
+
version: 1,
|
|
213
|
+
actions: [
|
|
214
|
+
{
|
|
215
|
+
action: "addBillingAddressId",
|
|
216
|
+
addressId: businessUnit.addresses[0].id,
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
expect(response.status).toBe(200);
|
|
222
|
+
expect(response.body.version).toBe(2);
|
|
223
|
+
expect(response.body.billingAddressIds).toHaveLength(1);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("removeBillingAddressId", async () => {
|
|
227
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
228
|
+
|
|
229
|
+
const addressId = businessUnit.addresses[0].id;
|
|
230
|
+
await supertest(ctMock.app)
|
|
231
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
232
|
+
.send({
|
|
233
|
+
version: 1,
|
|
234
|
+
actions: [
|
|
235
|
+
{
|
|
236
|
+
action: "addBillingAddressId",
|
|
237
|
+
addressId: addressId,
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
const response = await supertest(ctMock.app)
|
|
243
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
244
|
+
.send({
|
|
245
|
+
version: 2,
|
|
246
|
+
actions: [
|
|
247
|
+
{
|
|
248
|
+
action: "removeBillingAddressId",
|
|
249
|
+
addressId: addressId,
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
});
|
|
253
|
+
expect(response.status).toBe(200);
|
|
254
|
+
const result = response.body as BusinessUnit;
|
|
255
|
+
expect(result.version).toBe(3);
|
|
256
|
+
expect(result.billingAddressIds).toHaveLength(0);
|
|
257
|
+
});
|
|
39
258
|
|
|
40
|
-
|
|
259
|
+
test("setDefaultBillingAddress by ID", async () => {
|
|
260
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
261
|
+
const addressId = businessUnit.addresses[0].id;
|
|
262
|
+
|
|
263
|
+
const response = await supertest(ctMock.app)
|
|
264
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
265
|
+
.send({
|
|
266
|
+
version: businessUnit.version,
|
|
267
|
+
actions: [
|
|
268
|
+
{
|
|
269
|
+
action: "setDefaultBillingAddress",
|
|
270
|
+
addressId: addressId,
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
});
|
|
274
|
+
expect(response.status, JSON.stringify(response.body)).toBe(200);
|
|
275
|
+
expect(response.body.version).toBe(2);
|
|
276
|
+
expect(response.body.defaultBillingAddressId).toBe(addressId);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test("changeName", async () => {
|
|
280
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
281
|
+
|
|
282
|
+
const response = await supertest(ctMock.app)
|
|
283
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
284
|
+
.send({
|
|
285
|
+
version: 1,
|
|
286
|
+
actions: [{ action: "changeName", name: "Updated Business Unit Name" }],
|
|
287
|
+
});
|
|
288
|
+
expect(response.status).toBe(200);
|
|
289
|
+
expect(response.body.version).toBe(2);
|
|
290
|
+
expect(response.body.name).toBe("Updated Business Unit Name");
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test("setContactEmail", async () => {
|
|
294
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
295
|
+
|
|
296
|
+
const response = await supertest(ctMock.app)
|
|
297
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
298
|
+
.send({
|
|
299
|
+
version: 1,
|
|
300
|
+
actions: [
|
|
301
|
+
{ action: "setContactEmail", contactEmail: "newemail@business.com" },
|
|
302
|
+
],
|
|
303
|
+
});
|
|
304
|
+
expect(response.status).toBe(200);
|
|
305
|
+
expect(response.body.version).toBe(2);
|
|
306
|
+
expect(response.body.contactEmail).toBe("newemail@business.com");
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
test("changeStatus", async () => {
|
|
310
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
311
|
+
|
|
312
|
+
const response = await supertest(ctMock.app)
|
|
313
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
314
|
+
.send({
|
|
315
|
+
version: 1,
|
|
316
|
+
actions: [{ action: "changeStatus", status: "Inactive" }],
|
|
317
|
+
});
|
|
318
|
+
expect(response.status).toBe(200);
|
|
319
|
+
expect(response.body.version).toBe(2);
|
|
320
|
+
expect(response.body.status).toBe("Inactive");
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test("changeParentUnit", async () => {
|
|
324
|
+
const parentBusinessUnit = await businessUnitDraftFactory(ctMock).create({
|
|
325
|
+
key: "parent-company",
|
|
326
|
+
name: "Parent Company",
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
const divisionBusinessUnit = await businessUnitDraftFactory(ctMock).create({
|
|
330
|
+
key: "division-unit",
|
|
331
|
+
name: "Division Unit",
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const response = await supertest(ctMock.app)
|
|
335
|
+
.post(`/dummy/business-units/${divisionBusinessUnit.id}`)
|
|
336
|
+
.send({
|
|
337
|
+
version: 1,
|
|
338
|
+
actions: [
|
|
339
|
+
{
|
|
340
|
+
action: "changeParentUnit",
|
|
341
|
+
parentUnit: {
|
|
342
|
+
typeId: "business-unit",
|
|
343
|
+
key: parentBusinessUnit.key,
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
],
|
|
347
|
+
});
|
|
348
|
+
expect(response.status).toBe(200);
|
|
349
|
+
expect(response.body.version).toBe(2);
|
|
350
|
+
expect(response.body.parentUnit?.key).toBe(parentBusinessUnit.key);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test("addAssociate", async () => {
|
|
354
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
355
|
+
const customer = await customerDraftFactory(ctMock).create();
|
|
356
|
+
|
|
357
|
+
const response = await supertest(ctMock.app)
|
|
358
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
359
|
+
.send({
|
|
360
|
+
version: 1,
|
|
361
|
+
actions: [
|
|
362
|
+
{
|
|
363
|
+
action: "addAssociate",
|
|
364
|
+
associate: {
|
|
365
|
+
customer: {
|
|
366
|
+
typeId: "customer",
|
|
367
|
+
id: customer.id,
|
|
368
|
+
},
|
|
369
|
+
associateRoleAssignments: [],
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
],
|
|
373
|
+
});
|
|
374
|
+
expect(response.status).toBe(200);
|
|
375
|
+
expect(response.body.version).toBe(2);
|
|
376
|
+
expect(response.body.associates).toHaveLength(1);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
test("removeAssociate", async () => {
|
|
380
|
+
const customer = await customerDraftFactory(ctMock).create();
|
|
381
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create({
|
|
382
|
+
associates: [
|
|
383
|
+
{
|
|
384
|
+
customer: {
|
|
385
|
+
typeId: "customer",
|
|
386
|
+
id: customer.id,
|
|
387
|
+
},
|
|
388
|
+
associateRoleAssignments: [],
|
|
389
|
+
},
|
|
390
|
+
],
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
const response = await supertest(ctMock.app)
|
|
394
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
395
|
+
.send({
|
|
396
|
+
version: 1,
|
|
397
|
+
actions: [
|
|
398
|
+
{
|
|
399
|
+
action: "removeAssociate",
|
|
400
|
+
customer: {
|
|
401
|
+
typeId: "customer",
|
|
402
|
+
id: customer.id,
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
],
|
|
406
|
+
});
|
|
407
|
+
expect(response.status).toBe(200);
|
|
408
|
+
expect(response.body.version).toBe(2);
|
|
409
|
+
expect(response.body.associates).toHaveLength(0);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
test("changeAssociate", async () => {
|
|
413
|
+
const customer = await customerDraftFactory(ctMock).create();
|
|
414
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create({
|
|
415
|
+
associates: [
|
|
416
|
+
{
|
|
417
|
+
customer: {
|
|
418
|
+
typeId: "customer",
|
|
419
|
+
id: customer.id,
|
|
420
|
+
},
|
|
421
|
+
associateRoleAssignments: [],
|
|
422
|
+
},
|
|
423
|
+
],
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
const response = await supertest(ctMock.app)
|
|
427
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
428
|
+
.send({
|
|
429
|
+
version: 1,
|
|
430
|
+
actions: [
|
|
431
|
+
{
|
|
432
|
+
action: "changeAssociate",
|
|
433
|
+
customer: {
|
|
434
|
+
typeId: "customer",
|
|
435
|
+
id: customer.id,
|
|
436
|
+
},
|
|
437
|
+
associate: {
|
|
438
|
+
customer: {
|
|
439
|
+
typeId: "customer",
|
|
440
|
+
id: customer.id,
|
|
441
|
+
},
|
|
442
|
+
associateRoleAssignments: [
|
|
443
|
+
{
|
|
444
|
+
associateRole: {
|
|
445
|
+
typeId: "associate-role",
|
|
446
|
+
key: "admin",
|
|
447
|
+
},
|
|
448
|
+
inheritance: "Enabled",
|
|
449
|
+
},
|
|
450
|
+
],
|
|
451
|
+
},
|
|
452
|
+
},
|
|
453
|
+
],
|
|
454
|
+
});
|
|
455
|
+
expect(response.status).toBe(200);
|
|
456
|
+
expect(response.body.version).toBe(2);
|
|
457
|
+
expect(response.body.associates[0].associateRoleAssignments).toHaveLength(
|
|
458
|
+
1,
|
|
459
|
+
);
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
test("setCustomType", async () => {
|
|
463
|
+
const type = await typeDraftFactory(ctMock).create({
|
|
464
|
+
resourceTypeIds: ["business-unit"],
|
|
465
|
+
fieldDefinitions: [
|
|
466
|
+
{
|
|
467
|
+
type: { name: "String" },
|
|
468
|
+
name: "customField",
|
|
469
|
+
label: { en: "Custom Field" },
|
|
470
|
+
required: false,
|
|
471
|
+
},
|
|
472
|
+
],
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
476
|
+
|
|
477
|
+
const response = await supertest(ctMock.app)
|
|
478
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
479
|
+
.send({
|
|
480
|
+
version: 1,
|
|
481
|
+
actions: [
|
|
482
|
+
{
|
|
483
|
+
action: "setCustomType",
|
|
484
|
+
type: {
|
|
485
|
+
typeId: "type",
|
|
486
|
+
id: type.id,
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
],
|
|
490
|
+
});
|
|
491
|
+
expect(response.status).toBe(200);
|
|
492
|
+
expect(response.body.version).toBe(2);
|
|
493
|
+
expect(response.body.custom.type.id).toBe(type.id);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
test("setCustomField", async () => {
|
|
497
|
+
const type = await typeDraftFactory(ctMock).create({
|
|
498
|
+
resourceTypeIds: ["business-unit"],
|
|
499
|
+
fieldDefinitions: [
|
|
500
|
+
{
|
|
501
|
+
type: { name: "String" },
|
|
502
|
+
name: "customField",
|
|
503
|
+
label: { en: "Custom Field" },
|
|
504
|
+
required: false,
|
|
505
|
+
},
|
|
506
|
+
],
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create({
|
|
510
|
+
custom: {
|
|
511
|
+
type: {
|
|
512
|
+
typeId: "type",
|
|
513
|
+
id: type.id,
|
|
514
|
+
},
|
|
515
|
+
fields: {
|
|
516
|
+
customField: "foo",
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
const response = await supertest(ctMock.app)
|
|
522
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
523
|
+
.send({
|
|
524
|
+
version: 1,
|
|
525
|
+
actions: [
|
|
526
|
+
{
|
|
527
|
+
action: "setCustomField",
|
|
528
|
+
name: "customField",
|
|
529
|
+
value: "bar",
|
|
530
|
+
},
|
|
531
|
+
],
|
|
532
|
+
});
|
|
533
|
+
expect(response.status).toBe(200);
|
|
534
|
+
expect(response.body.version).toBe(2);
|
|
535
|
+
expect(response.body.custom.fields.customField).toBe("bar");
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
test("setAddressCustomType", async () => {
|
|
539
|
+
const type = await typeDraftFactory(ctMock).create({
|
|
540
|
+
resourceTypeIds: ["address"],
|
|
541
|
+
fieldDefinitions: [
|
|
542
|
+
{
|
|
543
|
+
type: { name: "String" },
|
|
544
|
+
name: "addressCustomField",
|
|
545
|
+
label: { en: "Address Custom Field" },
|
|
546
|
+
required: false,
|
|
547
|
+
},
|
|
548
|
+
],
|
|
549
|
+
});
|
|
550
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
551
|
+
|
|
552
|
+
const response = await supertest(ctMock.app)
|
|
553
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
554
|
+
.send({
|
|
555
|
+
version: 1,
|
|
556
|
+
actions: [
|
|
557
|
+
{
|
|
558
|
+
action: "setAddressCustomType",
|
|
559
|
+
addressId: businessUnit.addresses[0].id,
|
|
560
|
+
type: {
|
|
561
|
+
typeId: "type",
|
|
562
|
+
id: type.id,
|
|
563
|
+
},
|
|
564
|
+
},
|
|
565
|
+
],
|
|
566
|
+
});
|
|
567
|
+
expect(response.status).toBe(200);
|
|
568
|
+
expect(response.body.version).toBe(2);
|
|
569
|
+
expect(response.body.addresses[0].custom.type.id).toBe(type.id);
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
test("setAddressCustomField", async () => {
|
|
573
|
+
const type = await typeDraftFactory(ctMock).create({
|
|
574
|
+
resourceTypeIds: ["address"],
|
|
575
|
+
fieldDefinitions: [
|
|
576
|
+
{
|
|
577
|
+
type: { name: "String" },
|
|
578
|
+
name: "addressCustomField",
|
|
579
|
+
label: { en: "Address Custom Field" },
|
|
580
|
+
required: false,
|
|
581
|
+
},
|
|
582
|
+
],
|
|
583
|
+
});
|
|
584
|
+
const businessUnit = await businessUnitDraftFactory(ctMock).create();
|
|
585
|
+
|
|
586
|
+
const response = await supertest(ctMock.app)
|
|
587
|
+
.post(`/dummy/business-units/${businessUnit.id}`)
|
|
588
|
+
.send({
|
|
589
|
+
version: 1,
|
|
590
|
+
actions: [
|
|
591
|
+
{
|
|
592
|
+
action: "setAddressCustomType",
|
|
593
|
+
addressId: businessUnit.addresses[0].id,
|
|
594
|
+
type: {
|
|
595
|
+
typeId: "type",
|
|
596
|
+
id: type.id,
|
|
597
|
+
},
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
action: "setAddressCustomField",
|
|
601
|
+
addressId: businessUnit.addresses[0].id,
|
|
602
|
+
name: "addressCustomField",
|
|
603
|
+
value: "address custom value",
|
|
604
|
+
},
|
|
605
|
+
],
|
|
606
|
+
});
|
|
607
|
+
expect(response.status).toBe(200);
|
|
608
|
+
expect(response.body.version).toBe(3);
|
|
609
|
+
expect(response.body.addresses[0].custom.fields.addressCustomField).toBe(
|
|
610
|
+
"address custom value",
|
|
611
|
+
);
|
|
41
612
|
});
|
|
42
613
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BusinessUnit,
|
|
3
|
+
BusinessUnitDraft,
|
|
4
|
+
CompanyDraft,
|
|
5
|
+
} from "@commercetools/platform-sdk";
|
|
6
|
+
import { Factory } from "fishery";
|
|
7
|
+
import supertest from "supertest";
|
|
8
|
+
import type { CommercetoolsMock } from "~src/ctMock";
|
|
9
|
+
|
|
10
|
+
export const businessUnitDraftFactory = (m: CommercetoolsMock) =>
|
|
11
|
+
Factory.define<BusinessUnitDraft, BusinessUnitDraft, BusinessUnit>(
|
|
12
|
+
({ onCreate }) => {
|
|
13
|
+
onCreate(async (draft) => {
|
|
14
|
+
const response = await supertest(m.app)
|
|
15
|
+
.post("/dummy/business-units")
|
|
16
|
+
.send(draft);
|
|
17
|
+
|
|
18
|
+
return response.body;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
key: "test-business-unit",
|
|
23
|
+
unitType: "Company",
|
|
24
|
+
name: "Test Business Unit",
|
|
25
|
+
status: "Active",
|
|
26
|
+
contactEmail: "contact@businessunit.com",
|
|
27
|
+
storeMode: "Explicit",
|
|
28
|
+
associateMode: "Explicit",
|
|
29
|
+
approvalRuleMode: "Explicit",
|
|
30
|
+
addresses: [
|
|
31
|
+
{
|
|
32
|
+
firstName: "Business",
|
|
33
|
+
lastName: "Contact",
|
|
34
|
+
streetName: "Business Street",
|
|
35
|
+
streetNumber: "100",
|
|
36
|
+
postalCode: "1000 AA",
|
|
37
|
+
city: "Business City",
|
|
38
|
+
country: "NL",
|
|
39
|
+
company: "Test Business Unit",
|
|
40
|
+
phone: "+31612345678",
|
|
41
|
+
email: "contact@businessunit.com",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
stores: [],
|
|
45
|
+
associates: [],
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Type, TypeDraft } from "@commercetools/platform-sdk";
|
|
2
|
+
import { Factory } from "fishery";
|
|
3
|
+
import supertest from "supertest";
|
|
4
|
+
import type { CommercetoolsMock } from "~src/ctMock";
|
|
5
|
+
|
|
6
|
+
export const typeDraftFactory = (m: CommercetoolsMock) =>
|
|
7
|
+
Factory.define<TypeDraft, TypeDraft, Type>(({ onCreate }) => {
|
|
8
|
+
onCreate(async (draft) => {
|
|
9
|
+
const response = await supertest(m.app).post("/dummy/types").send(draft);
|
|
10
|
+
|
|
11
|
+
return response.body;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
key: "type",
|
|
16
|
+
name: { en: "Type Name" },
|
|
17
|
+
resourceTypeIds: ["product"],
|
|
18
|
+
description: { en: "Type description" },
|
|
19
|
+
};
|
|
20
|
+
});
|