@skriptfabrik/n8n-nodes-fulfillmenttools 0.1.2 → 0.1.3

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/CHANGELOG.md +14 -0
  2. package/package.json +5 -4
  3. package/src/credentials/FulfillmenttoolsApi.credentials.d.ts +13 -0
  4. package/src/credentials/FulfillmenttoolsApi.credentials.js +126 -0
  5. package/src/credentials/FulfillmenttoolsApi.credentials.js.map +1 -0
  6. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.d.ts +5 -0
  7. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.js +174 -0
  8. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.js.map +1 -0
  9. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.d.ts +12 -0
  10. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.js +330 -0
  11. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.js.map +1 -0
  12. package/src/nodes/Fulfillmenttools/GenericFunctions.d.ts +3 -0
  13. package/src/nodes/Fulfillmenttools/GenericFunctions.js +90 -0
  14. package/src/nodes/Fulfillmenttools/GenericFunctions.js.map +1 -0
  15. package/src/nodes/Fulfillmenttools/descriptions/FacilityCarrierDescription.d.ts +3 -0
  16. package/src/nodes/Fulfillmenttools/descriptions/FacilityCarrierDescription.js +322 -0
  17. package/src/nodes/Fulfillmenttools/descriptions/FacilityCarrierDescription.js.map +1 -0
  18. package/src/nodes/Fulfillmenttools/descriptions/FacilityDescription.d.ts +3 -0
  19. package/src/nodes/Fulfillmenttools/descriptions/FacilityDescription.js +610 -0
  20. package/src/nodes/Fulfillmenttools/descriptions/FacilityDescription.js.map +1 -0
  21. package/src/nodes/Fulfillmenttools/descriptions/OrderDescription.d.ts +3 -0
  22. package/src/nodes/Fulfillmenttools/descriptions/OrderDescription.js +328 -0
  23. package/src/nodes/Fulfillmenttools/descriptions/OrderDescription.js.map +1 -0
  24. package/.eslintignore +0 -1
  25. package/.eslintrc.json +0 -30
  26. package/jest.config.ts +0 -11
  27. package/project.json +0 -37
  28. package/src/api.d.ts +0 -37084
  29. package/src/credentials/FulfillmenttoolsApi.credentials.spec.ts +0 -101
  30. package/src/credentials/FulfillmenttoolsApi.credentials.ts +0 -166
  31. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.spec.ts +0 -1149
  32. package/src/nodes/Fulfillmenttools/Fulfillmenttools.node.ts +0 -390
  33. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.spec.ts +0 -386
  34. package/src/nodes/Fulfillmenttools/FulfillmenttoolsTrigger.node.ts +0 -396
  35. package/src/nodes/Fulfillmenttools/GenericFunctions.spec.ts +0 -279
  36. package/src/nodes/Fulfillmenttools/GenericFunctions.ts +0 -156
  37. package/src/nodes/Fulfillmenttools/descriptions/FacilityCarrierDescription.ts +0 -335
  38. package/src/nodes/Fulfillmenttools/descriptions/FacilityDescription.ts +0 -621
  39. package/src/nodes/Fulfillmenttools/descriptions/OrderDescription.ts +0 -338
  40. package/tsconfig.json +0 -22
  41. package/tsconfig.lib.json +0 -10
  42. package/tsconfig.spec.json +0 -13
@@ -1,396 +0,0 @@
1
- import type {
2
- IDataObject,
3
- IHookFunctions,
4
- INodeType,
5
- INodeTypeDescription,
6
- IWebhookFunctions,
7
- IWebhookResponseData,
8
- } from 'n8n-workflow';
9
- import type { components } from '../../api';
10
- import { fulfillmenttoolsApiRequest } from './GenericFunctions';
11
-
12
- type Subscription = components['schemas']['Subscription'];
13
- type Subscriptions = components['schemas']['Subscriptions'];
14
-
15
- type Credentials = {
16
- username: string;
17
- password: string;
18
- apiKey: string;
19
- subDomain: string;
20
- webhookToken: string;
21
- idToken?: string;
22
- refreshToken?: string;
23
- };
24
-
25
- type HeaderData = {
26
- 'x-fulfillmenttools-event'?: string;
27
- 'x-fulfillmenttools-token'?: string;
28
- };
29
-
30
- type StaticData = {
31
- subscriptionId?: string;
32
- };
33
-
34
- enum FulfillmenttoolsEvents {
35
- ORDER_CREATED = 'ORDER_CREATED',
36
- ORDER_CANCELED = 'ORDER_CANCELED',
37
- ORDER_UNLOCKED = 'ORDER_UNLOCKED',
38
- INVENTORY_FACILITY_STOCK_CHANGED = 'INVENTORY_FACILITY_STOCK_CHANGED',
39
- INBOUND_DELIVERY_RECEIVED = 'INBOUND_DELIVERY_RECEIVED',
40
- INBOUND_DELIVERY_FINISHED = 'INBOUND_DELIVERY_FINISHED',
41
- INBOUND_DELIVERY_ON_HOLD = 'INBOUND_DELIVERY_ON_HOLD',
42
- ROUTING_PLAN_SPLITTED = 'ROUTING_PLAN_SPLITTED',
43
- ROUTING_PLAN_WAITING = 'ROUTING_PLAN_WAITING',
44
- ROUTING_PLAN_FALLBACK = 'ROUTING_PLAN_FALLBACK',
45
- ROUTING_PLAN_ROUTED = 'ROUTING_PLAN_ROUTED',
46
- ROUTING_PLAN_REROUTEPLAN_CREATED = 'ROUTING_PLAN_REROUTEPLAN_CREATED',
47
- ROUTING_PLAN_NOT_ROUTABLE = 'ROUTING_PLAN_NOT_ROUTABLE',
48
- FACILITY_CREATED = 'FACILITY_CREATED',
49
- FACILITY_UPDATED = 'FACILITY_UPDATED',
50
- FACILITY_DELETED = 'FACILITY_DELETED',
51
- PICK_JOB_CREATED = 'PICK_JOB_CREATED',
52
- PICK_JOB_PICKING_COMMENCED = 'PICK_JOB_PICKING_COMMENCED',
53
- PICK_JOB_PICKING_PAUSED = 'PICK_JOB_PICKING_PAUSED',
54
- PICK_JOB_PICKING_FINISHED = 'PICK_JOB_PICKING_FINISHED',
55
- PICK_JOB_PICK_LINE_PICKED = 'PICK_JOB_PICK_LINE_PICKED',
56
- PICK_JOB_REROUTED = 'PICK_JOB_REROUTED',
57
- PICK_JOB_RESET = 'PICK_JOB_RESET',
58
- PICK_JOB_ABORTED = 'PICK_JOB_ABORTED',
59
- PACK_JOB_CREATED = 'PACK_JOB_CREATED',
60
- PACK_JOB_UPDATED = 'PACK_JOB_UPDATED',
61
- HANDOVERJOB_CREATED = 'HANDOVERJOB_CREATED',
62
- HANDOVERJOB_HANDED_OVER = 'HANDOVERJOB_HANDED_OVER',
63
- HANDOVERJOB_REVERTED = 'HANDOVERJOB_REVERTED',
64
- HANDOVERJOB_CANCELED = 'HANDOVERJOB_CANCELED',
65
- PARCEL_CARRIER_REQUESTED = 'PARCEL_CARRIER_REQUESTED',
66
- PARCEL_CARRIER_FAILED = 'PARCEL_CARRIER_FAILED',
67
- PARCEL_CARRIER_ACKNOWLEDGED = 'PARCEL_CARRIER_ACKNOWLEDGED',
68
- RETURN_CREATED = 'RETURN_CREATED',
69
- RETURN_CLAIMED = 'RETURN_CLAIMED',
70
- RETURN_CLOSED = 'RETURN_CLOSED',
71
- RETURN_CANCELED = 'RETURN_CANCELED',
72
- RETURN_UPDATED = 'RETURN_UPDATED',
73
- }
74
-
75
- export class FulfillmenttoolsTrigger implements INodeType {
76
- description: INodeTypeDescription = {
77
- name: 'fulfillmenttoolsTrigger',
78
-
79
- displayName: 'fulfillmenttools Trigger',
80
-
81
- icon: 'file:icons/fulfillmenttools.svg',
82
-
83
- group: ['trigger'],
84
-
85
- version: 1,
86
-
87
- subtitle: '={{$parameter["event"].toLowerCase().split("_").join(" ")}}',
88
-
89
- description: 'Listen to fulfillmenttools events',
90
-
91
- defaults: {
92
- name: 'fulfillmenttools Trigger',
93
- },
94
-
95
- inputs: [],
96
-
97
- outputs: ['main'],
98
-
99
- credentials: [
100
- {
101
- name: 'fulfillmenttoolsApi',
102
- required: true,
103
- },
104
- ],
105
-
106
- webhooks: [
107
- {
108
- name: 'default',
109
- httpMethod: 'POST',
110
- responseMode: 'onReceived',
111
- path: 'webhook',
112
- },
113
- ],
114
-
115
- properties: [
116
- {
117
- displayName: 'Event',
118
- name: 'event',
119
- type: 'options',
120
- noDataExpression: true,
121
- options: [
122
- {
123
- name: 'Order Created',
124
- value: FulfillmenttoolsEvents.ORDER_CREATED,
125
- },
126
- {
127
- name: 'Order Canceled',
128
- value: FulfillmenttoolsEvents.ORDER_CANCELED,
129
- },
130
- {
131
- name: 'Order Unlocked',
132
- value: FulfillmenttoolsEvents.ORDER_UNLOCKED,
133
- },
134
- {
135
- name: 'Inventory Facility Stock Changed',
136
- value: FulfillmenttoolsEvents.INVENTORY_FACILITY_STOCK_CHANGED,
137
- },
138
- {
139
- name: 'Inbound Delivery Received',
140
- value: FulfillmenttoolsEvents.INBOUND_DELIVERY_RECEIVED,
141
- },
142
- {
143
- name: 'Inbound Delivery Finished',
144
- value: FulfillmenttoolsEvents.INBOUND_DELIVERY_FINISHED,
145
- },
146
- {
147
- name: 'Inbound Delivery On Hold',
148
- value: FulfillmenttoolsEvents.INBOUND_DELIVERY_ON_HOLD,
149
- },
150
- {
151
- name: 'Routing Plan Splitted',
152
- value: FulfillmenttoolsEvents.ROUTING_PLAN_SPLITTED,
153
- },
154
- {
155
- name: 'Routing Plan Waiting',
156
- value: FulfillmenttoolsEvents.ROUTING_PLAN_WAITING,
157
- },
158
- {
159
- name: 'Routing Plan Fallback',
160
- value: FulfillmenttoolsEvents.ROUTING_PLAN_FALLBACK,
161
- },
162
- {
163
- name: 'Routing Plan Routed',
164
- value: FulfillmenttoolsEvents.ROUTING_PLAN_ROUTED,
165
- },
166
- {
167
- name: 'Routing Plan Rerouteplan Created',
168
- value: FulfillmenttoolsEvents.ROUTING_PLAN_REROUTEPLAN_CREATED,
169
- },
170
- {
171
- name: 'Routing Plan Not Routable',
172
- value: FulfillmenttoolsEvents.ROUTING_PLAN_NOT_ROUTABLE,
173
- },
174
- {
175
- name: 'Facility Created',
176
- value: FulfillmenttoolsEvents.FACILITY_CREATED,
177
- },
178
- {
179
- name: 'Facility Updated',
180
- value: FulfillmenttoolsEvents.FACILITY_UPDATED,
181
- },
182
- {
183
- name: 'Facility Deleted',
184
- value: FulfillmenttoolsEvents.FACILITY_DELETED,
185
- },
186
- {
187
- name: 'Pick Job Created',
188
- value: FulfillmenttoolsEvents.PICK_JOB_CREATED,
189
- },
190
- {
191
- name: 'Pick Job Picking Commenced',
192
- value: FulfillmenttoolsEvents.PICK_JOB_PICKING_COMMENCED,
193
- },
194
- {
195
- name: 'Pick Job Picking Paused',
196
- value: FulfillmenttoolsEvents.PICK_JOB_PICKING_PAUSED,
197
- },
198
- {
199
- name: 'Pick Job Picking Finished',
200
- value: FulfillmenttoolsEvents.PICK_JOB_PICKING_FINISHED,
201
- },
202
- {
203
- name: 'Pick Job Pick Line Picked',
204
- value: FulfillmenttoolsEvents.PICK_JOB_PICK_LINE_PICKED,
205
- },
206
- {
207
- name: 'Pick Job Rerouted',
208
- value: FulfillmenttoolsEvents.PICK_JOB_REROUTED,
209
- },
210
- {
211
- name: 'Pick Job Reset',
212
- value: FulfillmenttoolsEvents.PICK_JOB_RESET,
213
- },
214
- {
215
- name: 'Pick Job Aborted',
216
- value: FulfillmenttoolsEvents.PICK_JOB_ABORTED,
217
- },
218
- {
219
- name: 'Pack Job Created',
220
- value: FulfillmenttoolsEvents.PACK_JOB_CREATED,
221
- },
222
- {
223
- name: 'Pack Job Updated',
224
- value: FulfillmenttoolsEvents.PACK_JOB_UPDATED,
225
- },
226
- {
227
- name: 'Handoverjob Created',
228
- value: FulfillmenttoolsEvents.HANDOVERJOB_CREATED,
229
- },
230
- {
231
- name: 'Handoverjob Handed Over',
232
- value: FulfillmenttoolsEvents.HANDOVERJOB_HANDED_OVER,
233
- },
234
- {
235
- name: 'Handoverjob Reverted',
236
- value: FulfillmenttoolsEvents.HANDOVERJOB_REVERTED,
237
- },
238
- {
239
- name: 'Handoverjob Canceled',
240
- value: FulfillmenttoolsEvents.HANDOVERJOB_CANCELED,
241
- },
242
- {
243
- name: 'Parcel Carrier Requested',
244
- value: FulfillmenttoolsEvents.PARCEL_CARRIER_REQUESTED,
245
- },
246
- {
247
- name: 'Parcel Carrier Failed',
248
- value: FulfillmenttoolsEvents.PARCEL_CARRIER_FAILED,
249
- },
250
- {
251
- name: 'Parcel Carrier Acknowledged',
252
- value: FulfillmenttoolsEvents.PARCEL_CARRIER_ACKNOWLEDGED,
253
- },
254
- {
255
- name: 'Return Created',
256
- value: FulfillmenttoolsEvents.RETURN_CREATED,
257
- },
258
- {
259
- name: 'Return Claimed',
260
- value: FulfillmenttoolsEvents.RETURN_CLAIMED,
261
- },
262
- {
263
- name: 'Return Closed',
264
- value: FulfillmenttoolsEvents.RETURN_CLOSED,
265
- },
266
- {
267
- name: 'Return Canceled',
268
- value: FulfillmenttoolsEvents.RETURN_CANCELED,
269
- },
270
- {
271
- name: 'Return Updated',
272
- value: FulfillmenttoolsEvents.RETURN_UPDATED,
273
- },
274
- ],
275
- default: FulfillmenttoolsEvents.ORDER_CREATED.toString(),
276
- },
277
- ],
278
- };
279
-
280
- webhookMethods = {
281
- default: {
282
- async checkExists(this: IHookFunctions): Promise<boolean> {
283
- const callbackUrl = this.getNodeWebhookUrl('default') as string;
284
- const staticData = this.getWorkflowStaticData('node') as StaticData;
285
-
286
- const responseData = (await fulfillmenttoolsApiRequest.call(
287
- this,
288
- 'GET',
289
- '/subscriptions',
290
- )) as Subscriptions;
291
-
292
- for (const subscription of responseData.subscriptions as Subscription[]) {
293
- if (subscription.callbackUrl === callbackUrl) {
294
- staticData.subscriptionId = subscription.id;
295
- return true;
296
- }
297
- }
298
-
299
- return false;
300
- },
301
- async create(this: IHookFunctions): Promise<boolean> {
302
- const callbackUrl = this.getNodeWebhookUrl('default') as string;
303
- const event = this.getNodeParameter('event') as string;
304
- const credentials = (await this.getCredentials(
305
- 'fulfillmenttoolsApi',
306
- )) as Credentials;
307
- const staticData = this.getWorkflowStaticData('node') as StaticData;
308
-
309
- const responseData = (await fulfillmenttoolsApiRequest.call(
310
- this,
311
- 'POST',
312
- '/subscriptions',
313
- {
314
- callbackUrl,
315
- event,
316
- name: `${event}`.split('_').join(' ').toLowerCase(),
317
- headers: [
318
- {
319
- key: 'user-agent',
320
- value: `${credentials.subDomain}/1.0`,
321
- },
322
- {
323
- key: 'x-fulfillmenttools-event',
324
- value: event,
325
- },
326
- {
327
- key: 'x-fulfillmenttools-token',
328
- value: credentials.webhookToken,
329
- },
330
- ],
331
- },
332
- )) as Subscription;
333
-
334
- if (responseData.id === undefined) {
335
- return false;
336
- }
337
-
338
- staticData.subscriptionId = responseData.id;
339
-
340
- return true;
341
- },
342
- async delete(this: IHookFunctions): Promise<boolean> {
343
- const staticData = this.getWorkflowStaticData('node') as StaticData;
344
-
345
- if (staticData.subscriptionId === undefined) {
346
- return true;
347
- }
348
-
349
- try {
350
- await fulfillmenttoolsApiRequest.call(
351
- this,
352
- 'DELETE',
353
- `/subscriptions/${staticData.subscriptionId}`,
354
- );
355
- } catch (error) {
356
- return false;
357
- }
358
-
359
- delete staticData.subscriptionId;
360
-
361
- return true;
362
- },
363
- },
364
- };
365
-
366
- async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
367
- const headerData = this.getHeaderData() as HeaderData;
368
-
369
- if (
370
- headerData['x-fulfillmenttools-event'] === undefined ||
371
- headerData['x-fulfillmenttools-token'] === undefined
372
- ) {
373
- return {};
374
- }
375
-
376
- const event = this.getNodeParameter('event') as string;
377
-
378
- if (headerData['x-fulfillmenttools-event'] !== event) {
379
- return {};
380
- }
381
-
382
- const credentials = (await this.getCredentials(
383
- 'fulfillmenttoolsApi',
384
- )) as Credentials;
385
-
386
- if (headerData['x-fulfillmenttools-token'] !== credentials.webhookToken) {
387
- return {};
388
- }
389
-
390
- const req = this.getRequestObject();
391
-
392
- return {
393
- workflowData: [this.helpers.returnJsonArray(req.body as IDataObject)],
394
- };
395
- }
396
- }
@@ -1,279 +0,0 @@
1
- import { mockClear, mockDeep } from 'jest-mock-extended';
2
- import type { IExecuteFunctions } from 'n8n-workflow';
3
- import { NodeApiError, sleep } from 'n8n-workflow';
4
- import {
5
- fulfillmenttoolsApiRequest,
6
- fulfillmenttoolsApiRequestAllItems,
7
- } from './GenericFunctions';
8
-
9
- jest.mock('n8n-workflow');
10
-
11
- describe('GenericFunctions', () => {
12
- const executeFunctions = mockDeep<IExecuteFunctions>();
13
- const mockedSleep = jest.mocked(sleep);
14
-
15
- afterEach(() => {
16
- mockClear(executeFunctions);
17
- mockClear(mockedSleep);
18
- });
19
-
20
- it('should make a simple API request', () => {
21
- const body = {
22
- status: 'UP',
23
- dependencies: [
24
- {
25
- name: 'database',
26
- status: 'UP',
27
- },
28
- ],
29
- };
30
-
31
- const responses = [{ body, statusCode: 200 }];
32
-
33
- executeFunctions.getCredentials
34
- .calledWith('fulfillmenttoolsApi')
35
- .mockResolvedValue({ subDomain: '_example_' });
36
- executeFunctions.helpers.httpRequestWithAuthentication
37
- .calledWith('fulfillmenttoolsApi', expect.any(Object))
38
- .mockImplementation(() => Promise.resolve(responses.shift()));
39
-
40
- expect(
41
- fulfillmenttoolsApiRequest.call(executeFunctions, 'GET', '/health'),
42
- ).resolves.toEqual(body);
43
- });
44
-
45
- it('should make a second API request because of version missmatch', () => {
46
- const body = {
47
- version: 3,
48
- };
49
-
50
- const responses = [
51
- { body: [{ version: 2 }], statusCode: 409 },
52
- { body, statusCode: 200 },
53
- ];
54
-
55
- executeFunctions.getCredentials
56
- .calledWith('fulfillmenttoolsApi')
57
- .mockResolvedValue({ subDomain: '_example_' });
58
- executeFunctions.helpers.httpRequestWithAuthentication
59
- .calledWith('fulfillmenttoolsApi', expect.any(Object))
60
- .mockImplementation(() => Promise.resolve(responses.shift()));
61
-
62
- expect(
63
- fulfillmenttoolsApiRequest.call(executeFunctions, 'POST', '/example', {
64
- version: 1,
65
- }),
66
- ).resolves.toEqual(body);
67
- });
68
-
69
- it('should make a second API request because of too many requests', () => {
70
- const body = {
71
- version: 3,
72
- };
73
-
74
- const responses = [
75
- { body: [], statusCode: 429 },
76
- { body, statusCode: 200 },
77
- ];
78
-
79
- executeFunctions.getCredentials
80
- .calledWith('fulfillmenttoolsApi')
81
- .mockResolvedValue({ subDomain: '_example_' });
82
- executeFunctions.helpers.httpRequestWithAuthentication
83
- .calledWith('fulfillmenttoolsApi', expect.any(Object))
84
- .mockImplementation(() => Promise.resolve(responses.shift()));
85
-
86
- expect(
87
- fulfillmenttoolsApiRequest.call(executeFunctions, 'POST', '/example', {
88
- version: 1,
89
- }),
90
- ).resolves.toEqual(body);
91
- });
92
-
93
- it('should throw immediatly because of invalid input', () => {
94
- const responses = [
95
- { body: [{ summary: 'Invalid input' }], statusCode: 400 },
96
- ];
97
-
98
- executeFunctions.getCredentials
99
- .calledWith('fulfillmenttoolsApi')
100
- .mockResolvedValue({ subDomain: '_example_' });
101
- executeFunctions.helpers.httpRequestWithAuthentication
102
- .calledWith('fulfillmenttoolsApi', expect.any(Object))
103
- .mockImplementation(() => Promise.resolve(responses.shift()));
104
-
105
- expect(
106
- fulfillmenttoolsApiRequest.call(executeFunctions, 'POST', '/example', {
107
- version: 1,
108
- }),
109
- ).rejects.toBeInstanceOf(NodeApiError);
110
- });
111
-
112
- it('should throw immediatly because of version missmatch without version in response', () => {
113
- const responses = [
114
- {
115
- body: [{ summary: 'Conflict while processing something' }],
116
- statusCode: 409,
117
- },
118
- ];
119
-
120
- executeFunctions.getCredentials
121
- .calledWith('fulfillmenttoolsApi')
122
- .mockResolvedValue({ subDomain: '_example_' });
123
- executeFunctions.helpers.httpRequestWithAuthentication
124
- .calledWith('fulfillmenttoolsApi', expect.any(Object))
125
- .mockImplementation(() => Promise.resolve(responses.shift()));
126
-
127
- expect(
128
- fulfillmenttoolsApiRequest.call(executeFunctions, 'POST', '/example', {
129
- version: 1,
130
- }),
131
- ).rejects.toBeInstanceOf(NodeApiError);
132
- });
133
-
134
- it('should throw after 2 retries because of version missmatch', () => {
135
- const responses = [
136
- { body: [{ version: 2 }], statusCode: 409 },
137
- { body: [{ version: 2 }], statusCode: 409 },
138
- ];
139
-
140
- executeFunctions.getCredentials
141
- .calledWith('fulfillmenttoolsApi')
142
- .mockResolvedValue({ subDomain: '_example_' });
143
- executeFunctions.helpers.httpRequestWithAuthentication
144
- .calledWith('fulfillmenttoolsApi', expect.any(Object))
145
- .mockImplementation(() => Promise.resolve(responses.shift()));
146
-
147
- expect(
148
- fulfillmenttoolsApiRequest.call(executeFunctions, 'POST', '/example', {
149
- version: 1,
150
- }),
151
- ).rejects.toBeInstanceOf(NodeApiError);
152
- });
153
-
154
- it('should throw after 9 retries because of too many requests', () => {
155
- const responses = [
156
- { body: [], statusCode: 429 },
157
- { body: [], statusCode: 429 },
158
- { body: [], statusCode: 429 },
159
- { body: [], statusCode: 429 },
160
- { body: [], statusCode: 429 },
161
- { body: [], statusCode: 429 },
162
- { body: [], statusCode: 429 },
163
- { body: [], statusCode: 429 },
164
- { body: [], statusCode: 429 },
165
- ];
166
-
167
- executeFunctions.getCredentials
168
- .calledWith('fulfillmenttoolsApi')
169
- .mockResolvedValue({ subDomain: '_example_' });
170
- executeFunctions.helpers.httpRequestWithAuthentication
171
- .calledWith('fulfillmenttoolsApi', expect.any(Object))
172
- .mockImplementation(() => Promise.resolve(responses.shift()));
173
-
174
- expect(
175
- fulfillmenttoolsApiRequest.call(executeFunctions, 'POST', '/example', {
176
- version: 1,
177
- }),
178
- ).rejects.toBeInstanceOf(NodeApiError);
179
- });
180
-
181
- it('should make an API request to get all items', () => {
182
- const body = [
183
- {
184
- id: '005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
185
- created: '2023-11-02T13:14:22.443Z',
186
- lastModified: '2023-11-02T13:14:22.443Z',
187
- orderDate: '2023-11-02T13:14:20.631Z',
188
- version: 1,
189
- status: 'OPEN',
190
- orderLineItems: [
191
- {
192
- quantity: 1,
193
- title: 'Longsleeve in mehrfarbigem Streifendesign',
194
- },
195
- ],
196
- },
197
- ];
198
-
199
- const responses = [
200
- { body, statusCode: 200 },
201
- { body: [], statusCode: 200 },
202
- ];
203
-
204
- executeFunctions.getCredentials
205
- .calledWith('fulfillmenttoolsApi')
206
- .mockResolvedValue({ subDomain: '_example_' });
207
- executeFunctions.helpers.httpRequestWithAuthentication
208
- .calledWith('fulfillmenttoolsApi', expect.any(Object))
209
- .mockImplementation(() => Promise.resolve(responses.shift()));
210
-
211
- expect(
212
- fulfillmenttoolsApiRequestAllItems.call(
213
- executeFunctions,
214
- undefined,
215
- 'GET',
216
- '/orders',
217
- ),
218
- ).resolves.toEqual(body);
219
- });
220
-
221
- it('should make an API request to get some items', () => {
222
- const body = {
223
- orders: [
224
- {
225
- id: '005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
226
- created: '2023-11-02T13:14:22.443Z',
227
- lastModified: '2023-11-02T13:14:22.443Z',
228
- orderDate: '2023-11-02T13:14:20.631Z',
229
- version: 1,
230
- status: 'OPEN',
231
- orderLineItems: [
232
- {
233
- quantity: 1,
234
- title: 'Longsleeve in mehrfarbigem Streifendesign',
235
- },
236
- ],
237
- },
238
- {
239
- id: '005319a3-29d0-4de0-ab4a-e7c1f0dc8877',
240
- created: '2023-11-02T13:14:22.443Z',
241
- lastModified: '2023-11-02T13:14:22.443Z',
242
- orderDate: '2023-11-02T13:14:20.631Z',
243
- version: 1,
244
- status: 'OPEN',
245
- orderLineItems: [
246
- {
247
- quantity: 1,
248
- title: 'Longsleeve in mehrfarbigem Streifendesign',
249
- },
250
- ],
251
- },
252
- ],
253
- total: 2,
254
- };
255
-
256
- const responses = [
257
- { body, statusCode: 200 },
258
- { body: { orders: [], total: 0 }, statusCode: 200 },
259
- ];
260
-
261
- executeFunctions.getCredentials
262
- .calledWith('fulfillmenttoolsApi')
263
- .mockResolvedValue({ subDomain: '_example_' });
264
- executeFunctions.helpers.httpRequestWithAuthentication
265
- .calledWith('fulfillmenttoolsApi', expect.any(Object))
266
- .mockImplementation(() => Promise.resolve(responses.shift()));
267
-
268
- expect(
269
- fulfillmenttoolsApiRequestAllItems.call(
270
- executeFunctions,
271
- 'orders',
272
- 'GET',
273
- '/orders',
274
- undefined,
275
- { limit: 1 },
276
- ),
277
- ).resolves.toEqual([body.orders[0]]);
278
- });
279
- });