@labdigital/commercetools-mock 2.53.2 → 2.55.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.
Files changed (52) hide show
  1. package/dist/index.d.ts +107 -77
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +330 -7
  4. package/dist/index.js.map +1 -1
  5. package/package.json +4 -3
  6. package/src/lib/productSearchFilter.test.ts +1 -0
  7. package/src/lib/projectionSearchFilter.test.ts +1 -0
  8. package/src/priceSelector.test.ts +1 -0
  9. package/src/product-projection-search.ts +2 -0
  10. package/src/product-search.ts +1 -0
  11. package/src/repositories/business-unit.ts +157 -2
  12. package/src/repositories/cart/index.test.ts +2 -0
  13. package/src/repositories/cart/index.ts +1 -0
  14. package/src/repositories/cart-discount/index.ts +1 -1
  15. package/src/repositories/customer/index.ts +2 -0
  16. package/src/repositories/discount-group/actions.ts +50 -0
  17. package/src/repositories/discount-group/index.ts +29 -0
  18. package/src/repositories/index.ts +6 -0
  19. package/src/repositories/order/index.test.ts +126 -125
  20. package/src/repositories/payment/actions.ts +87 -0
  21. package/src/repositories/payment/index.ts +1 -1
  22. package/src/repositories/product/index.ts +1 -0
  23. package/src/repositories/product-type.ts +1 -0
  24. package/src/repositories/quote/index.ts +1 -0
  25. package/src/repositories/quote-request/index.test.ts +1 -0
  26. package/src/repositories/quote-request/index.ts +1 -0
  27. package/src/repositories/recurrence-policy/actions.ts +53 -0
  28. package/src/repositories/recurrence-policy/index.ts +36 -0
  29. package/src/repositories/recurring-order/actions.ts +157 -0
  30. package/src/repositories/recurring-order/index.ts +52 -0
  31. package/src/repositories/review.test.ts +2 -0
  32. package/src/repositories/shopping-list/actions.ts +1 -0
  33. package/src/repositories/shopping-list/index.ts +1 -0
  34. package/src/services/business-units.test.ts +586 -15
  35. package/src/services/discount-group.test.ts +270 -0
  36. package/src/services/discount-group.ts +16 -0
  37. package/src/services/index.ts +12 -0
  38. package/src/services/my-cart.test.ts +1 -0
  39. package/src/services/my-payment.test.ts +1 -0
  40. package/src/services/payment.test.ts +1 -0
  41. package/src/services/product-projection.test.ts +4 -0
  42. package/src/services/product-type.test.ts +1 -0
  43. package/src/services/product.test.ts +1 -0
  44. package/src/services/recurrence-policy.test.ts +316 -0
  45. package/src/services/recurrence-policy.ts +16 -0
  46. package/src/services/recurring-order.test.ts +424 -0
  47. package/src/services/recurring-order.ts +16 -0
  48. package/src/services/shopping-list.test.ts +3 -0
  49. package/src/storage/in-memory.ts +6 -0
  50. package/src/testing/business-unit.ts +48 -0
  51. package/src/testing/type.ts +20 -0
  52. package/src/types.ts +6 -0
@@ -0,0 +1,52 @@
1
+ import assert from "node:assert";
2
+ import type {
3
+ RecurringOrder,
4
+ RecurringOrderDraft,
5
+ } from "@commercetools/platform-sdk";
6
+ import type { Config } from "~src/config";
7
+ import { getBaseResourceProperties } from "~src/helpers";
8
+ import {
9
+ AbstractResourceRepository,
10
+ type RepositoryContext,
11
+ } from "../abstract";
12
+ import { OrderRepository } from "../order";
13
+ import { RecurringOrderUpdateHandler } from "./actions";
14
+
15
+ export class RecurringOrderRepository extends AbstractResourceRepository<"recurring-order"> {
16
+ constructor(config: Config) {
17
+ super("recurring-order", config);
18
+ this.actions = new RecurringOrderUpdateHandler(config.storage);
19
+ }
20
+
21
+ create(
22
+ context: RepositoryContext,
23
+ draft: RecurringOrderDraft,
24
+ ): RecurringOrder {
25
+ assert(draft.cart, "draft.cart is missing");
26
+
27
+ const orderRepo = new OrderRepository(this.config);
28
+
29
+ const initialOrder = orderRepo.createFromCart(context, {
30
+ id: draft.cart.id!,
31
+ typeId: "cart",
32
+ });
33
+
34
+ const resource: RecurringOrder = {
35
+ ...getBaseResourceProperties(),
36
+ key: draft.key,
37
+ cart: {
38
+ typeId: "cart",
39
+ id: draft.cart.id!,
40
+ },
41
+ originOrder: {
42
+ typeId: "order",
43
+ id: initialOrder.id,
44
+ },
45
+ startsAt: draft.startsAt,
46
+ expiresAt: draft.expiresAt,
47
+ recurringOrderState: "Active",
48
+ schedule: { type: "standard", intervalUnit: "month", value: 1 },
49
+ };
50
+ return this.saveNew(context, resource);
51
+ }
52
+ }
@@ -36,6 +36,7 @@ describe("Review Repository", () => {
36
36
  current: {
37
37
  name: { "en-US": "Test Product" },
38
38
  slug: { "en-US": "test-product" },
39
+ attributes: [],
39
40
  categories: [],
40
41
  masterVariant: {
41
42
  id: 1,
@@ -49,6 +50,7 @@ describe("Review Repository", () => {
49
50
  staged: {
50
51
  name: { "en-US": "Test Product" },
51
52
  slug: { "en-US": "test-product" },
53
+ attributes: [],
52
54
  categories: [],
53
55
  masterVariant: {
54
56
  id: 1,
@@ -103,6 +103,7 @@ export class ShoppingListUpdateHandler
103
103
  name: product.masterData.current.name,
104
104
  variantId: varId,
105
105
  quantity,
106
+ published: Boolean(product.masterData.current),
106
107
  });
107
108
  }
108
109
  }
@@ -75,6 +75,7 @@ export class ShoppingListRepository extends AbstractResourceRepository<"shopping
75
75
  productId: draftLineItem.productId ?? "",
76
76
  name: {},
77
77
  variantId,
78
+ published: true,
78
79
  quantity: draftLineItem.quantity ?? 1,
79
80
  productType: { typeId: "product-type", id: "" },
80
81
  custom: createCustomFields(
@@ -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
- expect(businessUnit.key).toBe("example-business-unit");
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
  });