@skriptfabrik/n8n-nodes-fulfillmenttools 0.1.0 → 0.1.2

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 (42) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.json +30 -0
  3. package/CHANGELOG.md +25 -0
  4. package/jest.config.ts +11 -0
  5. package/package.json +3 -3
  6. package/project.json +37 -0
  7. package/src/api.d.ts +37084 -0
  8. package/src/credentials/FulfillmenttoolsApi.credentials.spec.ts +101 -0
  9. package/src/credentials/FulfillmenttoolsApi.credentials.ts +166 -0
  10. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.spec.ts +1149 -0
  11. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.ts +390 -0
  12. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.spec.ts +386 -0
  13. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.ts +396 -0
  14. package/src/nodes/Fulfillmenttools/GenericFunctions.spec.ts +279 -0
  15. package/src/nodes/Fulfillmenttools/GenericFunctions.ts +156 -0
  16. package/src/nodes/Fulfillmenttools/descriptions/FacilityCarrierDescription.ts +335 -0
  17. package/src/nodes/Fulfillmenttools/descriptions/FacilityDescription.ts +621 -0
  18. package/src/nodes/Fulfillmenttools/descriptions/OrderDescription.ts +338 -0
  19. package/tsconfig.json +22 -0
  20. package/tsconfig.lib.json +10 -0
  21. package/tsconfig.spec.json +13 -0
  22. package/src/credentials/FulfillmenttoolsApi.credentials.d.ts +0 -13
  23. package/src/credentials/FulfillmenttoolsApi.credentials.js +0 -126
  24. package/src/credentials/FulfillmenttoolsApi.credentials.js.map +0 -1
  25. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.d.ts +0 -5
  26. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.js +0 -174
  27. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.js.map +0 -1
  28. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.d.ts +0 -12
  29. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.js +0 -330
  30. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.js.map +0 -1
  31. package/src/nodes/Fulfillmenttools/GenericFunctions.d.ts +0 -3
  32. package/src/nodes/Fulfillmenttools/GenericFunctions.js +0 -91
  33. package/src/nodes/Fulfillmenttools/GenericFunctions.js.map +0 -1
  34. package/src/nodes/Fulfillmenttools/descriptions/FacilityCarrierDescription.d.ts +0 -3
  35. package/src/nodes/Fulfillmenttools/descriptions/FacilityCarrierDescription.js +0 -322
  36. package/src/nodes/Fulfillmenttools/descriptions/FacilityCarrierDescription.js.map +0 -1
  37. package/src/nodes/Fulfillmenttools/descriptions/FacilityDescription.d.ts +0 -3
  38. package/src/nodes/Fulfillmenttools/descriptions/FacilityDescription.js +0 -610
  39. package/src/nodes/Fulfillmenttools/descriptions/FacilityDescription.js.map +0 -1
  40. package/src/nodes/Fulfillmenttools/descriptions/OrderDescription.d.ts +0 -3
  41. package/src/nodes/Fulfillmenttools/descriptions/OrderDescription.js +0 -328
  42. package/src/nodes/Fulfillmenttools/descriptions/OrderDescription.js.map +0 -1
@@ -0,0 +1,1149 @@
1
+ import { mockClear, mockDeep } from 'jest-mock-extended';
2
+ import { type IExecuteFunctions } from 'n8n-workflow';
3
+ import { Fulfillmenttools } from './Fulfillmenttools.node';
4
+ import {
5
+ fulfillmenttoolsApiRequest,
6
+ fulfillmenttoolsApiRequestAllItems,
7
+ } from './GenericFunctions';
8
+
9
+ jest.mock('./GenericFunctions');
10
+
11
+ describe('Fulfillmenttools', () => {
12
+ const executeFunctions = mockDeep<IExecuteFunctions>();
13
+
14
+ let fulfillmenttools: Fulfillmenttools;
15
+
16
+ beforeEach(() => {
17
+ fulfillmenttools = new Fulfillmenttools();
18
+ });
19
+
20
+ afterEach(() => {
21
+ mockClear(executeFunctions);
22
+ });
23
+
24
+ it('should be defined', () => {
25
+ expect(fulfillmenttools).toBeDefined();
26
+ });
27
+
28
+ it('should create facility', () => {
29
+ const facility = {
30
+ address: {
31
+ city: 'Langenfeld',
32
+ country: 'DE',
33
+ houseNumber: '42a',
34
+ postalCode: '40764',
35
+ street: 'Hauptstr.',
36
+ companyName: 'Speedy Boxales Ltd.',
37
+ },
38
+ name: 'Hamburg NW2',
39
+ };
40
+ const jsonArray = [{ json: facility }];
41
+ const executionData = jsonArray.map(({ json }) => ({
42
+ json,
43
+ pairedItem: { item: 0 },
44
+ }));
45
+
46
+ executeFunctions.getInputData.mockReturnValue([
47
+ {
48
+ json: {},
49
+ },
50
+ ]);
51
+
52
+ executeFunctions.getNodeParameter
53
+ .calledWith('resource', 0)
54
+ .mockReturnValue('facility');
55
+ executeFunctions.getNodeParameter
56
+ .calledWith('operation', 0)
57
+ .mockReturnValue('create');
58
+ executeFunctions.getNodeParameter
59
+ .calledWith('facility', 0)
60
+ .mockReturnValue(facility);
61
+
62
+ jest.mocked(fulfillmenttoolsApiRequest).mockResolvedValue(facility);
63
+
64
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
65
+
66
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
67
+ executionData,
68
+ );
69
+
70
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
71
+ executionData,
72
+ ]);
73
+
74
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
75
+ 'POST',
76
+ '/facilities',
77
+ facility,
78
+ );
79
+ });
80
+
81
+ it('should get a single facility', async () => {
82
+ const facility = {
83
+ name: 'Store',
84
+ locationType: 'EXTERNAL',
85
+ address: {
86
+ city: 'Langenfeld',
87
+ country: 'DE',
88
+ province: 'NRW',
89
+ houseNumber: '42a',
90
+ postalCode: '40764',
91
+ street: 'Hauptstr.',
92
+ companyName: 'Speedy Boxales Ltd.',
93
+ },
94
+ status: 'ONLINE',
95
+ services: [
96
+ {
97
+ type: 'SHIP_FROM_STORE',
98
+ },
99
+ ],
100
+ closingDays: null,
101
+ pickingTimes: null,
102
+ pickingMethods: null,
103
+ scanningRule: null,
104
+ capacityEnabled: false,
105
+ capacityPlanningTimeframe: null,
106
+ tags: null,
107
+ created: '2023-11-17T13:09:09.651Z',
108
+ lastModified: '2023-11-17T13:09:22.714Z',
109
+ version: 3,
110
+ id: '005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
111
+ };
112
+ const jsonArray = [{ json: facility }];
113
+ const executionData = jsonArray.map(({ json }) => ({
114
+ json,
115
+ pairedItem: { item: 0 },
116
+ }));
117
+
118
+ executeFunctions.getInputData.mockReturnValue([
119
+ {
120
+ json: {},
121
+ },
122
+ ]);
123
+
124
+ executeFunctions.getNodeParameter
125
+ .calledWith('resource', 0)
126
+ .mockReturnValue('facility');
127
+ executeFunctions.getNodeParameter
128
+ .calledWith('operation', 0)
129
+ .mockReturnValue('get');
130
+ executeFunctions.getNodeParameter
131
+ .calledWith('facilityId', 0)
132
+ .mockReturnValue('005319a3-29d0-4de0-ab4a-e7c1f0dc8877');
133
+
134
+ jest.mocked(fulfillmenttoolsApiRequest).mockResolvedValue(facility);
135
+
136
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
137
+
138
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
139
+ executionData,
140
+ );
141
+
142
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
143
+ executionData,
144
+ ]);
145
+
146
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
147
+ 'GET',
148
+ '/facilities/005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
149
+ );
150
+ });
151
+
152
+ it('should delete a single facility', async () => {
153
+ const facility = {
154
+ name: 'Store',
155
+ locationType: 'EXTERNAL',
156
+ address: {
157
+ city: 'Langenfeld',
158
+ country: 'DE',
159
+ province: 'NRW',
160
+ houseNumber: '42a',
161
+ postalCode: '40764',
162
+ street: 'Hauptstr.',
163
+ companyName: 'Speedy Boxales Ltd.',
164
+ },
165
+ status: 'ONLINE',
166
+ services: [
167
+ {
168
+ type: 'SHIP_FROM_STORE',
169
+ },
170
+ ],
171
+ closingDays: null,
172
+ pickingTimes: null,
173
+ pickingMethods: null,
174
+ scanningRule: null,
175
+ capacityEnabled: false,
176
+ capacityPlanningTimeframe: null,
177
+ tags: null,
178
+ created: '2023-11-17T13:09:09.651Z',
179
+ lastModified: '2023-11-17T13:09:22.714Z',
180
+ version: 3,
181
+ id: '005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
182
+ };
183
+ const jsonArray = [{ json: facility }];
184
+ const executionData = jsonArray.map(({ json }) => ({
185
+ json,
186
+ pairedItem: { item: 0 },
187
+ }));
188
+
189
+ executeFunctions.getInputData.mockReturnValue([
190
+ {
191
+ json: {},
192
+ },
193
+ ]);
194
+
195
+ executeFunctions.getNodeParameter
196
+ .calledWith('resource', 0)
197
+ .mockReturnValue('facility');
198
+ executeFunctions.getNodeParameter
199
+ .calledWith('operation', 0)
200
+ .mockReturnValue('delete');
201
+ executeFunctions.getNodeParameter
202
+ .calledWith('facilityId', 0)
203
+ .mockReturnValue('005319a3-29d0-4de0-ab4a-e7c1f0dc8877');
204
+
205
+ jest.mocked(fulfillmenttoolsApiRequest).mockResolvedValue(facility);
206
+
207
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
208
+
209
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
210
+ executionData,
211
+ );
212
+
213
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
214
+ executionData,
215
+ ]);
216
+
217
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
218
+ 'DELETE',
219
+ '/facilities/005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
220
+ );
221
+ });
222
+
223
+ it('should list all facilities', async () => {
224
+ const facilities = [
225
+ {
226
+ id: '005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
227
+ name: 'Store Magdeburg',
228
+ version: 18,
229
+ tenantFacilityId: '8',
230
+ status: 'ONLINE',
231
+ created: '2023-11-07T09:53:15.531Z',
232
+ lastModified: '2023-11-08T23:00:03.916Z',
233
+ city: 'Magdeburg',
234
+ country: 'DE',
235
+ houseNumber: '10',
236
+ street: 'Hauptsraße',
237
+ postalCode: '39104',
238
+ },
239
+ ];
240
+ const jsonArray = facilities.map((json) => ({ json }));
241
+ const executionData = jsonArray.map(({ json }) => ({
242
+ json,
243
+ pairedItem: { item: 0 },
244
+ }));
245
+
246
+ executeFunctions.getInputData.mockReturnValue([
247
+ {
248
+ json: {},
249
+ },
250
+ ]);
251
+
252
+ executeFunctions.getNodeParameter
253
+ .calledWith('resource', 0)
254
+ .mockReturnValue('facility');
255
+ executeFunctions.getNodeParameter
256
+ .calledWith('operation', 0)
257
+ .mockReturnValue('list');
258
+ executeFunctions.getNodeParameter
259
+ .calledWith('returnAll', 0)
260
+ .mockReturnValue(true);
261
+ executeFunctions.getNodeParameter.calledWith('size', 0).mockReturnValue(25);
262
+ executeFunctions.getNodeParameter
263
+ .calledWith('status', 0)
264
+ .mockReturnValue('');
265
+ executeFunctions.getNodeParameter
266
+ .calledWith('tenantFacilityId', 0)
267
+ .mockReturnValue('');
268
+ executeFunctions.getNodeParameter
269
+ .calledWith('orderBy', 0)
270
+ .mockReturnValue('');
271
+
272
+ jest
273
+ .mocked(fulfillmenttoolsApiRequestAllItems)
274
+ .mockResolvedValue(facilities);
275
+
276
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
277
+
278
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
279
+ executionData,
280
+ );
281
+
282
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
283
+ executionData,
284
+ ]);
285
+
286
+ expect(fulfillmenttoolsApiRequestAllItems).toHaveBeenCalledWith(
287
+ 'facilities',
288
+ 'GET',
289
+ '/facilities',
290
+ undefined,
291
+ {
292
+ size: 25,
293
+ status: undefined,
294
+ tenantFacilityId: undefined,
295
+ orderBy: undefined,
296
+ },
297
+ );
298
+ });
299
+
300
+ it('should list some facilities with provided tenant facility ID', async () => {
301
+ const facilities = [
302
+ {
303
+ id: '005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
304
+ name: 'Store Magdeburg',
305
+ version: 18,
306
+ tenantFacilityId: '8',
307
+ status: 'ONLINE',
308
+ created: '2023-11-07T09:53:15.531Z',
309
+ lastModified: '2023-11-08T23:00:03.916Z',
310
+ city: 'Magdeburg',
311
+ country: 'DE',
312
+ houseNumber: '10',
313
+ street: 'Hauptsraße',
314
+ postalCode: '39104',
315
+ },
316
+ ];
317
+ const jsonArray = facilities.map((json) => ({ json }));
318
+ const executionData = jsonArray.map(({ json }) => ({
319
+ json,
320
+ pairedItem: { item: 0 },
321
+ }));
322
+
323
+ executeFunctions.getInputData.mockReturnValue([
324
+ {
325
+ json: {},
326
+ },
327
+ ]);
328
+
329
+ executeFunctions.getNodeParameter
330
+ .calledWith('resource', 0)
331
+ .mockReturnValue('facility');
332
+ executeFunctions.getNodeParameter
333
+ .calledWith('operation', 0)
334
+ .mockReturnValue('list');
335
+ executeFunctions.getNodeParameter
336
+ .calledWith('returnAll', 0)
337
+ .mockReturnValue(false);
338
+ executeFunctions.getNodeParameter
339
+ .calledWith('limit', 0)
340
+ .mockReturnValue(50);
341
+ executeFunctions.getNodeParameter
342
+ .calledWith('startAfterId', 0)
343
+ .mockReturnValue(undefined);
344
+ executeFunctions.getNodeParameter.calledWith('size', 0).mockReturnValue(25);
345
+ executeFunctions.getNodeParameter
346
+ .calledWith('status', 0)
347
+ .mockReturnValue('ONLINE');
348
+ executeFunctions.getNodeParameter
349
+ .calledWith('tenantFacilityId', 0)
350
+ .mockReturnValue('1234');
351
+ executeFunctions.getNodeParameter
352
+ .calledWith('orderBy', 0)
353
+ .mockReturnValue('NAME');
354
+
355
+ jest
356
+ .mocked(fulfillmenttoolsApiRequestAllItems)
357
+ .mockResolvedValue(facilities);
358
+
359
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
360
+
361
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
362
+ executionData,
363
+ );
364
+
365
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
366
+ executionData,
367
+ ]);
368
+
369
+ expect(fulfillmenttoolsApiRequestAllItems).toHaveBeenCalledWith(
370
+ 'facilities',
371
+ 'GET',
372
+ '/facilities',
373
+ undefined,
374
+ {
375
+ limit: 50,
376
+ startAfterId: undefined,
377
+ size: 25,
378
+ status: 'ONLINE',
379
+ tenantFacilityId: '1234',
380
+ orderBy: 'NAME',
381
+ },
382
+ );
383
+ });
384
+
385
+ it('should patch facility', () => {
386
+ const facility = {
387
+ actions: [
388
+ {
389
+ action: 'ModifyFacility',
390
+ closingDays: [
391
+ {
392
+ date: '2020-02-03T09:45:51.525Z',
393
+ reason: 'string',
394
+ recurrence: 'YEARLY',
395
+ },
396
+ ],
397
+ },
398
+ ],
399
+ version: 2,
400
+ };
401
+ const jsonArray = [{ json: facility }];
402
+ const executionData = jsonArray.map(({ json }) => ({
403
+ json,
404
+ pairedItem: { item: 0 },
405
+ }));
406
+
407
+ executeFunctions.getInputData.mockReturnValue([
408
+ {
409
+ json: {},
410
+ },
411
+ ]);
412
+
413
+ executeFunctions.getNodeParameter
414
+ .calledWith('resource', 0)
415
+ .mockReturnValue('facility');
416
+ executeFunctions.getNodeParameter
417
+ .calledWith('operation', 0)
418
+ .mockReturnValue('patch');
419
+ executeFunctions.getNodeParameter
420
+ .calledWith('facilityId', 0)
421
+ .mockReturnValue('005319a3-29d0-4de0-ab4a-e7c1f0dc8877');
422
+ executeFunctions.getNodeParameter
423
+ .calledWith('facility', 0)
424
+ .mockReturnValue(facility);
425
+
426
+ jest.mocked(fulfillmenttoolsApiRequest).mockResolvedValue(facility);
427
+
428
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
429
+
430
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
431
+ executionData,
432
+ );
433
+
434
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
435
+ executionData,
436
+ ]);
437
+
438
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
439
+ 'PATCH',
440
+ '/facilities/005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
441
+ facility,
442
+ );
443
+ });
444
+
445
+ it('should create facility carrier connection without locale', () => {
446
+ const facilityCarrier = {
447
+ name: 'DHL Köln',
448
+ status: 'ACTIVE',
449
+ };
450
+ const jsonArray = [{ json: facilityCarrier }];
451
+ const executionData = jsonArray.map(({ json }) => ({
452
+ json,
453
+ pairedItem: { item: 0 },
454
+ }));
455
+
456
+ executeFunctions.getInputData.mockReturnValue([
457
+ {
458
+ json: {},
459
+ },
460
+ ]);
461
+
462
+ executeFunctions.getNodeParameter
463
+ .calledWith('resource', 0)
464
+ .mockReturnValue('facilityCarrier');
465
+ executeFunctions.getNodeParameter
466
+ .calledWith('operation', 0)
467
+ .mockReturnValue('create');
468
+ executeFunctions.getNodeParameter
469
+ .calledWith('facilityId', 0)
470
+ .mockReturnValue('005319a3-29d0-4de0-ab4a-e7c1f0dc8877');
471
+ executeFunctions.getNodeParameter
472
+ .calledWith('carrierRef', 0)
473
+ .mockReturnValue('DHL');
474
+ executeFunctions.getNodeParameter
475
+ .calledWith('facilityCarrier', 0)
476
+ .mockReturnValue(facilityCarrier);
477
+ executeFunctions.getNodeParameter
478
+ .calledWith('locale', 0)
479
+ .mockReturnValue('');
480
+
481
+ jest.mocked(fulfillmenttoolsApiRequest).mockResolvedValue(facilityCarrier);
482
+
483
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
484
+
485
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
486
+ executionData,
487
+ );
488
+
489
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
490
+ executionData,
491
+ ]);
492
+
493
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
494
+ 'POST',
495
+ '/facilities/005319a3-29d0-4de0-ab4a-e7c1f0dc8877/carriers/DHL',
496
+ facilityCarrier,
497
+ { locale: undefined },
498
+ );
499
+ });
500
+
501
+ it('should create facility carrier connection with locale', () => {
502
+ const facilityCarrier = {
503
+ name: 'DHL Köln',
504
+ status: 'ACTIVE',
505
+ };
506
+ const jsonArray = [{ json: facilityCarrier }];
507
+ const executionData = jsonArray.map(({ json }) => ({
508
+ json,
509
+ pairedItem: { item: 0 },
510
+ }));
511
+
512
+ executeFunctions.getInputData.mockReturnValue([
513
+ {
514
+ json: {},
515
+ },
516
+ ]);
517
+
518
+ executeFunctions.getNodeParameter
519
+ .calledWith('resource', 0)
520
+ .mockReturnValue('facilityCarrier');
521
+ executeFunctions.getNodeParameter
522
+ .calledWith('operation', 0)
523
+ .mockReturnValue('create');
524
+ executeFunctions.getNodeParameter
525
+ .calledWith('facilityId', 0)
526
+ .mockReturnValue('005319a3-29d0-4de0-ab4a-e7c1f0dc8877');
527
+ executeFunctions.getNodeParameter
528
+ .calledWith('carrierRef', 0)
529
+ .mockReturnValue('DHL');
530
+ executeFunctions.getNodeParameter
531
+ .calledWith('facilityCarrier', 0)
532
+ .mockReturnValue(facilityCarrier);
533
+ executeFunctions.getNodeParameter
534
+ .calledWith('locale', 0)
535
+ .mockReturnValue('de_DE');
536
+
537
+ jest.mocked(fulfillmenttoolsApiRequest).mockResolvedValue(facilityCarrier);
538
+
539
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
540
+
541
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
542
+ executionData,
543
+ );
544
+
545
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
546
+ executionData,
547
+ ]);
548
+
549
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
550
+ 'POST',
551
+ '/facilities/005319a3-29d0-4de0-ab4a-e7c1f0dc8877/carriers/DHL',
552
+ facilityCarrier,
553
+ { locale: 'de_DE' },
554
+ );
555
+ });
556
+
557
+ it('should get facility carrier connection with locale', () => {
558
+ const facilityCarrier = {
559
+ name: 'DHL Köln',
560
+ status: 'ACTIVE',
561
+ };
562
+ const jsonArray = [{ json: facilityCarrier }];
563
+ const executionData = jsonArray.map(({ json }) => ({
564
+ json,
565
+ pairedItem: { item: 0 },
566
+ }));
567
+
568
+ executeFunctions.getInputData.mockReturnValue([
569
+ {
570
+ json: {},
571
+ },
572
+ ]);
573
+
574
+ executeFunctions.getNodeParameter
575
+ .calledWith('resource', 0)
576
+ .mockReturnValue('facilityCarrier');
577
+ executeFunctions.getNodeParameter
578
+ .calledWith('operation', 0)
579
+ .mockReturnValue('get');
580
+ executeFunctions.getNodeParameter
581
+ .calledWith('facilityId', 0)
582
+ .mockReturnValue('005319a3-29d0-4de0-ab4a-e7c1f0dc8877');
583
+ executeFunctions.getNodeParameter
584
+ .calledWith('carrierRef', 0)
585
+ .mockReturnValue('DHL');
586
+ executeFunctions.getNodeParameter
587
+ .calledWith('locale', 0)
588
+ .mockReturnValue('de_DE');
589
+
590
+ jest.mocked(fulfillmenttoolsApiRequest).mockResolvedValue(facilityCarrier);
591
+
592
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
593
+
594
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
595
+ executionData,
596
+ );
597
+
598
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
599
+ executionData,
600
+ ]);
601
+
602
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
603
+ 'GET',
604
+ '/facilities/005319a3-29d0-4de0-ab4a-e7c1f0dc8877/carriers/DHL',
605
+ undefined,
606
+ { locale: 'de_DE' },
607
+ );
608
+ });
609
+
610
+ it('should get facility carrier connection without locale', () => {
611
+ const facilityCarrier = {
612
+ name: 'DHL Köln',
613
+ status: 'ACTIVE',
614
+ };
615
+ const jsonArray = [{ json: facilityCarrier }];
616
+ const executionData = jsonArray.map(({ json }) => ({
617
+ json,
618
+ pairedItem: { item: 0 },
619
+ }));
620
+
621
+ executeFunctions.getInputData.mockReturnValue([
622
+ {
623
+ json: {},
624
+ },
625
+ ]);
626
+
627
+ executeFunctions.getNodeParameter
628
+ .calledWith('resource', 0)
629
+ .mockReturnValue('facilityCarrier');
630
+ executeFunctions.getNodeParameter
631
+ .calledWith('operation', 0)
632
+ .mockReturnValue('get');
633
+ executeFunctions.getNodeParameter
634
+ .calledWith('facilityId', 0)
635
+ .mockReturnValue('005319a3-29d0-4de0-ab4a-e7c1f0dc8877');
636
+ executeFunctions.getNodeParameter
637
+ .calledWith('carrierRef', 0)
638
+ .mockReturnValue('DHL');
639
+ executeFunctions.getNodeParameter
640
+ .calledWith('locale', 0)
641
+ .mockReturnValue('');
642
+
643
+ jest.mocked(fulfillmenttoolsApiRequest).mockResolvedValue(facilityCarrier);
644
+
645
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
646
+
647
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
648
+ executionData,
649
+ );
650
+
651
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
652
+ executionData,
653
+ ]);
654
+
655
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
656
+ 'GET',
657
+ '/facilities/005319a3-29d0-4de0-ab4a-e7c1f0dc8877/carriers/DHL',
658
+ undefined,
659
+ { locale: undefined },
660
+ );
661
+ });
662
+
663
+ it('should list all facility carrier connections', () => {
664
+ const facilityCarriers = [
665
+ {
666
+ name: 'DHL Köln',
667
+ status: 'ACTIVE',
668
+ },
669
+ ];
670
+ const jsonArray = facilityCarriers.map((json) => ({ json }));
671
+ const executionData = jsonArray.map(({ json }) => ({
672
+ json,
673
+ pairedItem: { item: 0 },
674
+ }));
675
+
676
+ executeFunctions.getInputData.mockReturnValue([
677
+ {
678
+ json: {},
679
+ },
680
+ ]);
681
+
682
+ executeFunctions.getNodeParameter
683
+ .calledWith('resource', 0)
684
+ .mockReturnValue('facilityCarrier');
685
+ executeFunctions.getNodeParameter
686
+ .calledWith('operation', 0)
687
+ .mockReturnValue('list');
688
+ executeFunctions.getNodeParameter
689
+ .calledWith('facilityId', 0)
690
+ .mockReturnValue('005319a3-29d0-4de0-ab4a-e7c1f0dc8877');
691
+
692
+ jest
693
+ .mocked(fulfillmenttoolsApiRequestAllItems)
694
+ .mockResolvedValue(facilityCarriers);
695
+
696
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
697
+
698
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
699
+ executionData,
700
+ );
701
+
702
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
703
+ executionData,
704
+ ]);
705
+
706
+ expect(fulfillmenttoolsApiRequestAllItems).toHaveBeenCalledWith(
707
+ 'carriers',
708
+ 'GET',
709
+ '/facilities/005319a3-29d0-4de0-ab4a-e7c1f0dc8877/carriers',
710
+ );
711
+ });
712
+
713
+ it('should connect facility carrier connection with locale', () => {
714
+ const facilityCarrier = {
715
+ name: 'DHL Köln',
716
+ status: 'ACTIVE',
717
+ };
718
+ const jsonArray = [{ json: facilityCarrier }];
719
+ const executionData = jsonArray.map(({ json }) => ({
720
+ json,
721
+ pairedItem: { item: 0 },
722
+ }));
723
+
724
+ executeFunctions.getInputData.mockReturnValue([
725
+ {
726
+ json: {},
727
+ },
728
+ ]);
729
+
730
+ executeFunctions.getNodeParameter
731
+ .calledWith('resource', 0)
732
+ .mockReturnValue('facilityCarrier');
733
+ executeFunctions.getNodeParameter
734
+ .calledWith('operation', 0)
735
+ .mockReturnValue('connect');
736
+ executeFunctions.getNodeParameter
737
+ .calledWith('facilityId', 0)
738
+ .mockReturnValue('005319a3-29d0-4de0-ab4a-e7c1f0dc8877');
739
+ executeFunctions.getNodeParameter
740
+ .calledWith('carrierRef', 0)
741
+ .mockReturnValue('DHL');
742
+ executeFunctions.getNodeParameter
743
+ .calledWith('facilityCarrier', 0)
744
+ .mockReturnValue(facilityCarrier);
745
+ executeFunctions.getNodeParameter
746
+ .calledWith('locale', 0)
747
+ .mockReturnValue('de_DE');
748
+
749
+ jest.mocked(fulfillmenttoolsApiRequest).mockResolvedValue(facilityCarrier);
750
+
751
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
752
+
753
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
754
+ executionData,
755
+ );
756
+
757
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
758
+ executionData,
759
+ ]);
760
+
761
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
762
+ 'PUT',
763
+ '/facilities/005319a3-29d0-4de0-ab4a-e7c1f0dc8877/carriers/DHL',
764
+ facilityCarrier,
765
+ { locale: 'de_DE' },
766
+ );
767
+ });
768
+
769
+ it('should connect facility carrier connection without locale', () => {
770
+ const facilityCarrier = {
771
+ name: 'DHL Köln',
772
+ status: 'ACTIVE',
773
+ };
774
+ const jsonArray = [{ json: facilityCarrier }];
775
+ const executionData = jsonArray.map(({ json }) => ({
776
+ json,
777
+ pairedItem: { item: 0 },
778
+ }));
779
+
780
+ executeFunctions.getInputData.mockReturnValue([
781
+ {
782
+ json: {},
783
+ },
784
+ ]);
785
+
786
+ executeFunctions.getNodeParameter
787
+ .calledWith('resource', 0)
788
+ .mockReturnValue('facilityCarrier');
789
+ executeFunctions.getNodeParameter
790
+ .calledWith('operation', 0)
791
+ .mockReturnValue('connect');
792
+ executeFunctions.getNodeParameter
793
+ .calledWith('facilityId', 0)
794
+ .mockReturnValue('005319a3-29d0-4de0-ab4a-e7c1f0dc8877');
795
+ executeFunctions.getNodeParameter
796
+ .calledWith('carrierRef', 0)
797
+ .mockReturnValue('DHL');
798
+ executeFunctions.getNodeParameter
799
+ .calledWith('facilityCarrier', 0)
800
+ .mockReturnValue(facilityCarrier);
801
+ executeFunctions.getNodeParameter
802
+ .calledWith('locale', 0)
803
+ .mockReturnValue('');
804
+
805
+ jest.mocked(fulfillmenttoolsApiRequest).mockResolvedValue(facilityCarrier);
806
+
807
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
808
+
809
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
810
+ executionData,
811
+ );
812
+
813
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
814
+ executionData,
815
+ ]);
816
+
817
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
818
+ 'PUT',
819
+ '/facilities/005319a3-29d0-4de0-ab4a-e7c1f0dc8877/carriers/DHL',
820
+ facilityCarrier,
821
+ { locale: undefined },
822
+ );
823
+ });
824
+
825
+ it('should create order', () => {
826
+ const order = {
827
+ consumer: {
828
+ addresses: [
829
+ {
830
+ city: 'Langenfeld',
831
+ country: 'DE',
832
+ houseNumber: '42a',
833
+ postalCode: '40764',
834
+ street: 'Hauptstr.',
835
+ },
836
+ ],
837
+ },
838
+ orderDate: '2020-02-03T08:45:50.525Z',
839
+ orderLineItems: [
840
+ {
841
+ article: {
842
+ tenantArticleId: '4711',
843
+ title: 'Cologne Water',
844
+ },
845
+ quantity: 21,
846
+ },
847
+ ],
848
+ };
849
+ const jsonArray = [{ json: order }];
850
+ const executionData = jsonArray.map(({ json }) => ({
851
+ json,
852
+ pairedItem: { item: 0 },
853
+ }));
854
+
855
+ executeFunctions.getInputData.mockReturnValue([
856
+ {
857
+ json: {},
858
+ },
859
+ ]);
860
+
861
+ executeFunctions.getNodeParameter
862
+ .calledWith('resource', 0)
863
+ .mockReturnValue('order');
864
+ executeFunctions.getNodeParameter
865
+ .calledWith('operation', 0)
866
+ .mockReturnValue('create');
867
+ executeFunctions.getNodeParameter
868
+ .calledWith('order', 0)
869
+ .mockReturnValue(order);
870
+
871
+ jest.mocked(fulfillmenttoolsApiRequest).mockResolvedValue(order);
872
+
873
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
874
+
875
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
876
+ executionData,
877
+ );
878
+
879
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
880
+ executionData,
881
+ ]);
882
+
883
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
884
+ 'POST',
885
+ '/orders',
886
+ order,
887
+ );
888
+ });
889
+
890
+ it('should get a single order', async () => {
891
+ const order = {
892
+ id: '005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
893
+ created: '2023-11-02T13:14:22.443Z',
894
+ lastModified: '2023-11-02T13:14:22.443Z',
895
+ orderDate: '2023-11-02T13:14:20.631Z',
896
+ version: 1,
897
+ status: 'OPEN',
898
+ orderLineItems: [
899
+ {
900
+ quantity: 1,
901
+ title: 'Longsleeve in mehrfarbigem Streifendesign',
902
+ },
903
+ ],
904
+ };
905
+ const jsonArray = [{ json: order }];
906
+ const executionData = jsonArray.map(({ json }) => ({
907
+ json,
908
+ pairedItem: { item: 0 },
909
+ }));
910
+
911
+ executeFunctions.getInputData.mockReturnValue([
912
+ {
913
+ json: {},
914
+ },
915
+ ]);
916
+
917
+ executeFunctions.getNodeParameter
918
+ .calledWith('resource', 0)
919
+ .mockReturnValue('order');
920
+ executeFunctions.getNodeParameter
921
+ .calledWith('operation', 0)
922
+ .mockReturnValue('get');
923
+ executeFunctions.getNodeParameter
924
+ .calledWith('orderId', 0)
925
+ .mockReturnValue('005319a3-29d0-4de0-ab4a-e7c1f0dc8877');
926
+
927
+ jest.mocked(fulfillmenttoolsApiRequest).mockResolvedValue(order);
928
+
929
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
930
+
931
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
932
+ executionData,
933
+ );
934
+
935
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
936
+ executionData,
937
+ ]);
938
+
939
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
940
+ 'GET',
941
+ '/orders/005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
942
+ );
943
+ });
944
+
945
+ it('should list all orders', async () => {
946
+ const orders = [
947
+ {
948
+ id: '005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
949
+ created: '2023-11-02T13:14:22.443Z',
950
+ lastModified: '2023-11-02T13:14:22.443Z',
951
+ orderDate: '2023-11-02T13:14:20.631Z',
952
+ version: 1,
953
+ status: 'OPEN',
954
+ orderLineItems: [
955
+ {
956
+ quantity: 1,
957
+ title: 'Longsleeve in mehrfarbigem Streifendesign',
958
+ },
959
+ ],
960
+ },
961
+ ];
962
+ const jsonArray = orders.map((json) => ({ json }));
963
+ const executionData = jsonArray.map(({ json }) => ({
964
+ json,
965
+ pairedItem: { item: 0 },
966
+ }));
967
+
968
+ executeFunctions.getInputData.mockReturnValue([
969
+ {
970
+ json: {},
971
+ },
972
+ ]);
973
+
974
+ executeFunctions.getNodeParameter
975
+ .calledWith('resource', 0)
976
+ .mockReturnValue('order');
977
+ executeFunctions.getNodeParameter
978
+ .calledWith('operation', 0)
979
+ .mockReturnValue('list');
980
+ executeFunctions.getNodeParameter
981
+ .calledWith('returnAll', 0)
982
+ .mockReturnValue(true);
983
+ executeFunctions.getNodeParameter.calledWith('size', 0).mockReturnValue(25);
984
+ executeFunctions.getNodeParameter
985
+ .calledWith('tenantOrderId', 0)
986
+ .mockReturnValue('');
987
+
988
+ jest.mocked(fulfillmenttoolsApiRequestAllItems).mockResolvedValue(orders);
989
+
990
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
991
+
992
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
993
+ executionData,
994
+ );
995
+
996
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
997
+ executionData,
998
+ ]);
999
+
1000
+ expect(fulfillmenttoolsApiRequestAllItems).toHaveBeenCalledWith(
1001
+ 'orders',
1002
+ 'GET',
1003
+ '/orders',
1004
+ undefined,
1005
+ { size: 25, tenantOrderId: undefined },
1006
+ );
1007
+ });
1008
+
1009
+ it('should list some orders with provided tenant order ID', async () => {
1010
+ const orders = [
1011
+ {
1012
+ id: '005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
1013
+ created: '2023-11-02T13:14:22.443Z',
1014
+ lastModified: '2023-11-02T13:14:22.443Z',
1015
+ orderDate: '2023-11-02T13:14:20.631Z',
1016
+ version: 1,
1017
+ status: 'OPEN',
1018
+ orderLineItems: [
1019
+ {
1020
+ quantity: 1,
1021
+ title: 'Longsleeve in mehrfarbigem Streifendesign',
1022
+ },
1023
+ ],
1024
+ },
1025
+ ];
1026
+ const jsonArray = orders.map((json) => ({ json }));
1027
+ const executionData = jsonArray.map(({ json }) => ({
1028
+ json,
1029
+ pairedItem: { item: 0 },
1030
+ }));
1031
+
1032
+ executeFunctions.getInputData.mockReturnValue([
1033
+ {
1034
+ json: {},
1035
+ },
1036
+ ]);
1037
+
1038
+ executeFunctions.getNodeParameter
1039
+ .calledWith('resource', 0)
1040
+ .mockReturnValue('order');
1041
+ executeFunctions.getNodeParameter
1042
+ .calledWith('operation', 0)
1043
+ .mockReturnValue('list');
1044
+ executeFunctions.getNodeParameter
1045
+ .calledWith('returnAll', 0)
1046
+ .mockReturnValue(false);
1047
+ executeFunctions.getNodeParameter
1048
+ .calledWith('limit', 0)
1049
+ .mockReturnValue(50);
1050
+ executeFunctions.getNodeParameter
1051
+ .calledWith('startAfterId', 0)
1052
+ .mockReturnValue(undefined);
1053
+ executeFunctions.getNodeParameter.calledWith('size', 0).mockReturnValue(25);
1054
+ executeFunctions.getNodeParameter
1055
+ .calledWith('tenantOrderId', 0)
1056
+ .mockReturnValue('1234');
1057
+
1058
+ jest.mocked(fulfillmenttoolsApiRequestAllItems).mockResolvedValue(orders);
1059
+
1060
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
1061
+
1062
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
1063
+ executionData,
1064
+ );
1065
+
1066
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
1067
+ executionData,
1068
+ ]);
1069
+
1070
+ expect(fulfillmenttoolsApiRequestAllItems).toHaveBeenCalledWith(
1071
+ 'orders',
1072
+ 'GET',
1073
+ '/orders',
1074
+ undefined,
1075
+ {
1076
+ limit: 50,
1077
+ startAfterId: undefined,
1078
+ size: 25,
1079
+ tenantOrderId: '1234',
1080
+ },
1081
+ );
1082
+ });
1083
+
1084
+ it('should return an error', async () => {
1085
+ executeFunctions.getInputData.mockReturnValue([
1086
+ {
1087
+ json: {},
1088
+ },
1089
+ ]);
1090
+
1091
+ executeFunctions.getNodeParameter
1092
+ .calledWith('resource', 0)
1093
+ .mockReturnValue('order');
1094
+ executeFunctions.getNodeParameter
1095
+ .calledWith('operation', 0)
1096
+ .mockReturnValue('get');
1097
+ executeFunctions.getNodeParameter
1098
+ .calledWith('orderId', 0)
1099
+ .mockReturnValue('005319a3-29d0-4de0-ab4a-e7c1f0dc8877');
1100
+
1101
+ jest
1102
+ .mocked(fulfillmenttoolsApiRequest)
1103
+ .mockRejectedValue(new Error('__error_message__'));
1104
+
1105
+ executeFunctions.continueOnFail.mockReturnValue(true);
1106
+
1107
+ expect(fulfillmenttools.execute.call(executeFunctions)).resolves.toEqual([
1108
+ [{ json: { error: '__error_message__' }, pairedItem: { item: 0 } }],
1109
+ ]);
1110
+
1111
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
1112
+ 'GET',
1113
+ '/orders/005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
1114
+ );
1115
+ });
1116
+
1117
+ it('should throw an error', async () => {
1118
+ executeFunctions.getInputData.mockReturnValue([
1119
+ {
1120
+ json: {},
1121
+ },
1122
+ ]);
1123
+
1124
+ executeFunctions.getNodeParameter
1125
+ .calledWith('resource', 0)
1126
+ .mockReturnValue('order');
1127
+ executeFunctions.getNodeParameter
1128
+ .calledWith('operation', 0)
1129
+ .mockReturnValue('get');
1130
+ executeFunctions.getNodeParameter
1131
+ .calledWith('orderId', 0)
1132
+ .mockReturnValue('005319a3-29d0-4de0-ab4a-e7c1f0dc8877');
1133
+
1134
+ const error = new Error('__error_message__');
1135
+
1136
+ jest.mocked(fulfillmenttoolsApiRequest).mockRejectedValue(error);
1137
+
1138
+ executeFunctions.continueOnFail.mockReturnValue(false);
1139
+
1140
+ expect(fulfillmenttools.execute.call(executeFunctions)).rejects.toEqual(
1141
+ error,
1142
+ );
1143
+
1144
+ expect(fulfillmenttoolsApiRequest).toHaveBeenCalledWith(
1145
+ 'GET',
1146
+ '/orders/005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
1147
+ );
1148
+ });
1149
+ });