|
1
|
import { |
|
2
|
IFulfillmentModuleService, |
|
3
|
UpdateFulfillmentDTO, |
|
4
|
} from "@medusajs/framework/types" |
|
5
|
import { FulfillmentEvents, Modules } from "@medusajs/framework/utils" |
|
6
|
import { |
|
7
|
MockEventBusService, |
|
8
|
moduleIntegrationTestRunner, |
|
9
|
} from "@medusajs/test-utils" |
|
10
|
import { resolve } from "path" |
|
11
|
import { |
|
12
|
buildExpectedEventMessageShape, |
|
13
|
generateCreateFulfillmentData, |
|
14
|
generateCreateShippingOptionsData, |
|
15
|
} from "../../__fixtures__" |
|
16
|
import { FulfillmentProviderServiceFixtures } from "../../__fixtures__/providers/default-provider" |
|
17
|
|
|
18
|
jest.setTimeout(100000) |
|
19
|
|
|
20
|
const moduleOptions = { |
|
21
|
providers: [ |
|
22
|
{ |
|
23
|
resolve: resolve( |
|
24
|
process.cwd() + |
|
25
|
"/integration-tests/__fixtures__/providers/default-provider" |
|
26
|
), |
|
27
|
id: "test-provider", |
|
28
|
}, |
|
29
|
], |
|
30
|
} |
|
31
|
|
|
32
|
const providerId = "fixtures-fulfillment-provider_test-provider" |
|
33
|
|
|
34
|
moduleIntegrationTestRunner<IFulfillmentModuleService>({ |
|
35
|
moduleName: Modules.FULFILLMENT, |
|
36
|
moduleOptions: moduleOptions, |
|
37
|
testSuite: ({ service }) => { |
|
38
|
let eventBusEmitSpy |
|
39
|
|
|
40
|
beforeEach(() => { |
|
41
|
eventBusEmitSpy = jest.spyOn(MockEventBusService.prototype, "emit") |
|
42
|
}) |
|
43
|
|
|
44
|
afterEach(() => { |
|
45
|
jest.clearAllMocks() |
|
46
|
}) |
|
47
|
|
|
48
|
describe("Fulfillment Module Service", () => { |
|
49
|
describe("read", () => { |
|
50
|
it("should list fulfillment", async () => { |
|
51
|
const shippingProfile = await service.createShippingProfiles({ |
|
52
|
name: "test", |
|
53
|
type: "default", |
|
54
|
}) |
|
55
|
const fulfillmentSet = await service.createFulfillmentSets({ |
|
56
|
name: "test", |
|
57
|
type: "test-type", |
|
58
|
}) |
|
59
|
const serviceZone = await service.createServiceZones({ |
|
60
|
name: "test", |
|
61
|
fulfillment_set_id: fulfillmentSet.id, |
|
62
|
}) |
|
63
|
|
|
64
|
const shippingOption = await service.createShippingOptions( |
|
65
|
generateCreateShippingOptionsData({ |
|
66
|
provider_id: providerId, |
|
67
|
service_zone_id: serviceZone.id, |
|
68
|
shipping_profile_id: shippingProfile.id, |
|
69
|
}) |
|
70
|
) |
|
71
|
|
|
72
|
const fulfillment = await service.createFulfillment( |
|
73
|
generateCreateFulfillmentData({ |
|
74
|
provider_id: providerId, |
|
75
|
shipping_option_id: shippingOption.id, |
|
76
|
}) |
|
77
|
) |
|
78
|
|
|
79
|
const result = await service.listFulfillments({ |
|
80
|
shipping_option_id: shippingOption.id, |
|
81
|
}) |
|
82
|
|
|
83
|
expect(result.length).toEqual(1) |
|
84
|
expect(result[0].id).toEqual(fulfillment.id) |
|
85
|
}) |
|
86
|
|
|
87
|
it("should retrieve the fulfillment options", async () => { |
|
88
|
const fulfillmentOptions = await service.retrieveFulfillmentOptions( |
|
89
|
providerId |
|
90
|
) |
|
91
|
|
|
92
|
expect(fulfillmentOptions).toEqual({}) |
|
93
|
}) |
|
94
|
}) |
|
95
|
|
|
96
|
describe("mutations", () => { |
|
97
|
describe("on create", () => { |
|
98
|
it("should create a fulfillment", async () => { |
|
99
|
const shippingProfile = await service.createShippingProfiles({ |
|
100
|
name: "test", |
|
101
|
type: "default", |
|
102
|
}) |
|
103
|
const fulfillmentSet = await service.createFulfillmentSets({ |
|
104
|
name: "test", |
|
105
|
type: "test-type", |
|
106
|
}) |
|
107
|
const serviceZone = await service.createServiceZones({ |
|
108
|
name: "test", |
|
109
|
fulfillment_set_id: fulfillmentSet.id, |
|
110
|
}) |
|
111
|
|
|
112
|
const shippingOption = await service.createShippingOptions( |
|
113
|
generateCreateShippingOptionsData({ |
|
114
|
provider_id: providerId, |
|
115
|
service_zone_id: serviceZone.id, |
|
116
|
shipping_profile_id: shippingProfile.id, |
|
117
|
}) |
|
118
|
) |
|
119
|
|
|
120
|
jest.clearAllMocks() |
|
121
|
|
|
122
|
const fulfillment = await service.createFulfillment( |
|
123
|
generateCreateFulfillmentData({ |
|
124
|
provider_id: providerId, |
|
125
|
shipping_option_id: shippingOption.id, |
|
126
|
}) |
|
127
|
) |
|
128
|
|
|
129
|
expect(fulfillment).toEqual( |
|
130
|
expect.objectContaining({ |
|
131
|
id: expect.any(String), |
|
132
|
packed_at: null, |
|
133
|
shipped_at: null, |
|
134
|
delivered_at: null, |
|
135
|
canceled_at: null, |
|
136
|
data: null, |
|
137
|
provider_id: providerId, |
|
138
|
shipping_option_id: shippingOption.id, |
|
139
|
metadata: null, |
|
140
|
delivery_address: expect.objectContaining({ |
|
141
|
id: expect.any(String), |
|
142
|
}), |
|
143
|
items: [ |
|
144
|
expect.objectContaining({ |
|
145
|
id: expect.any(String), |
|
146
|
}), |
|
147
|
], |
|
148
|
labels: [ |
|
149
|
expect.objectContaining({ |
|
150
|
id: expect.any(String), |
|
151
|
}), |
|
152
|
], |
|
153
|
}) |
|
154
|
) |
|
155
|
|
|
156
|
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(5) |
|
157
|
expect(eventBusEmitSpy).toHaveBeenCalledWith( |
|
158
|
expect.arrayContaining([ |
|
159
|
buildExpectedEventMessageShape({ |
|
160
|
eventName: FulfillmentEvents.FULFILLMENT_CREATED, |
|
161
|
action: "created", |
|
162
|
object: "fulfillment", |
|
163
|
data: { id: fulfillment.id }, |
|
164
|
}), |
|
165
|
buildExpectedEventMessageShape({ |
|
166
|
eventName: FulfillmentEvents.FULFILLMENT_UPDATED, |
|
167
|
action: "updated", |
|
168
|
object: "fulfillment", |
|
169
|
data: { id: fulfillment.id }, |
|
170
|
}), |
|
171
|
buildExpectedEventMessageShape({ |
|
172
|
eventName: FulfillmentEvents.FULFILLMENT_ADDRESS_CREATED, |
|
173
|
action: "created", |
|
174
|
object: "fulfillment_address", |
|
175
|
data: { id: fulfillment.delivery_address.id }, |
|
176
|
}), |
|
177
|
buildExpectedEventMessageShape({ |
|
178
|
eventName: FulfillmentEvents.FULFILLMENT_ITEM_CREATED, |
|
179
|
action: "created", |
|
180
|
object: "fulfillment_item", |
|
181
|
data: { id: fulfillment.items[0].id }, |
|
182
|
}), |
|
183
|
buildExpectedEventMessageShape({ |
|
184
|
eventName: FulfillmentEvents.FULFILLMENT_LABEL_CREATED, |
|
185
|
action: "created", |
|
186
|
object: "fulfillment_label", |
|
187
|
data: { id: fulfillment.labels[0].id }, |
|
188
|
}), |
|
189
|
]), |
|
190
|
{ |
|
191
|
internal: true, |
|
192
|
} |
|
193
|
) |
|
194
|
}) |
|
195
|
|
|
196
|
it("should forward additional_data to the provider without persisting it", async () => { |
|
197
|
const shippingProfile = await service.createShippingProfiles({ |
|
198
|
name: "test", |
|
199
|
type: "default", |
|
200
|
}) |
|
201
|
const fulfillmentSet = await service.createFulfillmentSets({ |
|
202
|
name: "test", |
|
203
|
type: "test-type", |
|
204
|
}) |
|
205
|
const serviceZone = await service.createServiceZones({ |
|
206
|
name: "test", |
|
207
|
fulfillment_set_id: fulfillmentSet.id, |
|
208
|
}) |
|
209
|
|
|
210
|
const shippingOption = await service.createShippingOptions( |
|
211
|
generateCreateShippingOptionsData({ |
|
212
|
provider_id: providerId, |
|
213
|
service_zone_id: serviceZone.id, |
|
214
|
shipping_profile_id: shippingProfile.id, |
|
215
|
}) |
|
216
|
) |
|
217
|
|
|
218
|
const createFulfillmentProviderSpy = jest.spyOn( |
|
219
|
FulfillmentProviderServiceFixtures.prototype, |
|
220
|
"createFulfillment" |
|
221
|
) |
|
222
|
|
|
223
|
jest.clearAllMocks() |
|
224
|
|
|
225
|
const additionalData = { |
|
226
|
recipient_first_name: "John", |
|
227
|
recipient_last_name: "Doe", |
|
228
|
} |
|
229
|
|
|
230
|
const fulfillment = await service.createFulfillment( |
|
231
|
generateCreateFulfillmentData({ |
|
232
|
provider_id: providerId, |
|
233
|
shipping_option_id: shippingOption.id, |
|
234
|
additional_data: additionalData, |
|
235
|
}) |
|
236
|
) |
|
237
|
|
|
238
|
// the provider receives additional_data as its last argument |
|
239
|
expect(createFulfillmentProviderSpy).toHaveBeenCalledTimes(1) |
|
240
|
expect(createFulfillmentProviderSpy.mock.calls[0][4]).toEqual( |
|
241
|
additionalData |
|
242
|
) |
|
243
|
|
|
244
|
// additional_data is not persisted on the fulfillment |
|
245
|
expect(fulfillment).not.toHaveProperty("additional_data") |
|
246
|
}) |
|
247
|
|
|
248
|
it("should create a return fulfillment", async () => { |
|
249
|
const shippingProfile = await service.createShippingProfiles({ |
|
250
|
name: "test", |
|
251
|
type: "default", |
|
252
|
}) |
|
253
|
const fulfillmentSet = await service.createFulfillmentSets({ |
|
254
|
name: "test", |
|
255
|
type: "test-type", |
|
256
|
}) |
|
257
|
const serviceZone = await service.createServiceZones({ |
|
258
|
name: "test", |
|
259
|
fulfillment_set_id: fulfillmentSet.id, |
|
260
|
}) |
|
261
|
|
|
262
|
const shippingOption = await service.createShippingOptions( |
|
263
|
generateCreateShippingOptionsData({ |
|
264
|
provider_id: providerId, |
|
265
|
service_zone_id: serviceZone.id, |
|
266
|
shipping_profile_id: shippingProfile.id, |
|
267
|
}) |
|
268
|
) |
|
269
|
|
|
270
|
jest.clearAllMocks() |
|
271
|
|
|
272
|
const fulfillment = await service.createReturnFulfillment( |
|
273
|
generateCreateFulfillmentData({ |
|
274
|
provider_id: providerId, |
|
275
|
shipping_option_id: shippingOption.id, |
|
276
|
}) |
|
277
|
) |
|
278
|
|
|
279
|
expect(fulfillment).toEqual( |
|
280
|
expect.objectContaining({ |
|
281
|
id: expect.any(String), |
|
282
|
packed_at: null, |
|
283
|
shipped_at: null, |
|
284
|
delivered_at: null, |
|
285
|
canceled_at: null, |
|
286
|
data: null, |
|
287
|
provider_id: providerId, |
|
288
|
shipping_option_id: shippingOption.id, |
|
289
|
metadata: null, |
|
290
|
delivery_address: expect.objectContaining({ |
|
291
|
id: expect.any(String), |
|
292
|
}), |
|
293
|
items: [ |
|
294
|
expect.objectContaining({ |
|
295
|
id: expect.any(String), |
|
296
|
}), |
|
297
|
], |
|
298
|
labels: [ |
|
299
|
expect.objectContaining({ |
|
300
|
id: expect.any(String), |
|
301
|
}), |
|
302
|
], |
|
303
|
}) |
|
304
|
) |
|
305
|
|
|
306
|
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(5) |
|
307
|
expect(eventBusEmitSpy).toHaveBeenCalledWith( |
|
308
|
expect.arrayContaining([ |
|
309
|
buildExpectedEventMessageShape({ |
|
310
|
eventName: FulfillmentEvents.FULFILLMENT_CREATED, |
|
311
|
action: "created", |
|
312
|
object: "fulfillment", |
|
313
|
data: { id: fulfillment.id }, |
|
314
|
}), |
|
315
|
buildExpectedEventMessageShape({ |
|
316
|
eventName: FulfillmentEvents.FULFILLMENT_UPDATED, |
|
317
|
action: "updated", |
|
318
|
object: "fulfillment", |
|
319
|
data: { id: fulfillment.id }, |
|
320
|
}), |
|
321
|
buildExpectedEventMessageShape({ |
|
322
|
eventName: FulfillmentEvents.FULFILLMENT_ADDRESS_CREATED, |
|
323
|
action: "created", |
|
324
|
object: "fulfillment_address", |
|
325
|
data: { id: fulfillment.delivery_address.id }, |
|
326
|
}), |
|
327
|
buildExpectedEventMessageShape({ |
|
328
|
eventName: FulfillmentEvents.FULFILLMENT_ITEM_CREATED, |
|
329
|
action: "created", |
|
330
|
object: "fulfillment_item", |
|
331
|
data: { id: fulfillment.items[0].id }, |
|
332
|
}), |
|
333
|
buildExpectedEventMessageShape({ |
|
334
|
eventName: FulfillmentEvents.FULFILLMENT_LABEL_CREATED, |
|
335
|
action: "created", |
|
336
|
object: "fulfillment_label", |
|
337
|
data: { id: fulfillment.labels[0].id }, |
|
338
|
}), |
|
339
|
]), |
|
340
|
{ |
|
341
|
internal: true, |
|
342
|
} |
|
343
|
) |
|
344
|
}) |
|
345
|
}) |
|
346
|
|
|
347
|
describe("on update", () => { |
|
348
|
it("should update a fulfillment", async () => { |
|
349
|
const shippingProfile = await service.createShippingProfiles({ |
|
350
|
name: "test", |
|
351
|
type: "default", |
|
352
|
}) |
|
353
|
const fulfillmentSet = await service.createFulfillmentSets({ |
|
354
|
name: "test", |
|
355
|
type: "test-type", |
|
356
|
}) |
|
357
|
const serviceZone = await service.createServiceZones({ |
|
358
|
name: "test", |
|
359
|
fulfillment_set_id: fulfillmentSet.id, |
|
360
|
}) |
|
361
|
|
|
362
|
const shippingOption = await service.createShippingOptions( |
|
363
|
generateCreateShippingOptionsData({ |
|
364
|
provider_id: providerId, |
|
365
|
service_zone_id: serviceZone.id, |
|
366
|
shipping_profile_id: shippingProfile.id, |
|
367
|
}) |
|
368
|
) |
|
369
|
|
|
370
|
const fulfillment = await service.createFulfillment( |
|
371
|
generateCreateFulfillmentData({ |
|
372
|
provider_id: providerId, |
|
373
|
shipping_option_id: shippingOption.id, |
|
374
|
labels: [ |
|
375
|
{ |
|
376
|
tracking_number: "test-tracking-number-1", |
|
377
|
tracking_url: "test-tracking-url-1", |
|
378
|
label_url: "test-label-url-1", |
|
379
|
}, |
|
380
|
{ |
|
381
|
tracking_number: "test-tracking-number-2", |
|
382
|
tracking_url: "test-tracking-url-2", |
|
383
|
label_url: "test-label-url-2", |
|
384
|
}, |
|
385
|
{ |
|
386
|
tracking_number: "test-tracking-number-3", |
|
387
|
tracking_url: "test-tracking-url-3", |
|
388
|
label_url: "test-label-url-3", |
|
389
|
}, |
|
390
|
], |
|
391
|
}) |
|
392
|
) |
|
393
|
|
|
394
|
const label1 = fulfillment.labels.find( |
|
395
|
(l) => l.tracking_number === "test-tracking-number-1" |
|
396
|
)! |
|
397
|
const label2 = fulfillment.labels.find( |
|
398
|
(l) => l.tracking_number === "test-tracking-number-2" |
|
399
|
)! |
|
400
|
const label3 = fulfillment.labels.find( |
|
401
|
(l) => l.tracking_number === "test-tracking-number-3" |
|
402
|
)! |
|
403
|
|
|
404
|
const updateData: UpdateFulfillmentDTO = { |
|
405
|
labels: [ |
|
406
|
{ id: label1.id }, |
|
407
|
{ ...label2, label_url: "updated-test-label-url-2" }, |
|
408
|
{ |
|
409
|
tracking_number: "test-tracking-number-4", |
|
410
|
tracking_url: "test-tracking-url-4", |
|
411
|
label_url: "test-label-url-4", |
|
412
|
}, |
|
413
|
], |
|
414
|
} |
|
415
|
|
|
416
|
jest.clearAllMocks() |
|
417
|
|
|
418
|
const updatedFulfillment = await service.updateFulfillment( |
|
419
|
fulfillment.id, |
|
420
|
updateData |
|
421
|
) |
|
422
|
|
|
423
|
const label4 = updatedFulfillment.labels.find( |
|
424
|
(l) => l.tracking_number === "test-tracking-number-4" |
|
425
|
)! |
|
426
|
|
|
427
|
expect(updatedFulfillment.labels).toHaveLength(3) |
|
428
|
expect(updatedFulfillment).toEqual( |
|
429
|
expect.objectContaining({ |
|
430
|
id: expect.any(String), |
|
431
|
labels: expect.arrayContaining([ |
|
432
|
expect.objectContaining({ |
|
433
|
tracking_number: "test-tracking-number-1", |
|
434
|
tracking_url: "test-tracking-url-1", |
|
435
|
label_url: "test-label-url-1", |
|
436
|
}), |
|
437
|
expect.objectContaining({ |
|
438
|
tracking_number: "test-tracking-number-2", |
|
439
|
tracking_url: "test-tracking-url-2", |
|
440
|
label_url: "updated-test-label-url-2", |
|
441
|
}), |
|
442
|
expect.objectContaining({ |
|
443
|
tracking_number: "test-tracking-number-4", |
|
444
|
tracking_url: "test-tracking-url-4", |
|
445
|
label_url: "test-label-url-4", |
|
446
|
}), |
|
447
|
]), |
|
448
|
}) |
|
449
|
) |
|
450
|
|
|
451
|
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(3) |
|
452
|
expect(eventBusEmitSpy).toHaveBeenCalledWith( |
|
453
|
expect.arrayContaining([ |
|
454
|
buildExpectedEventMessageShape({ |
|
455
|
eventName: FulfillmentEvents.FULFILLMENT_LABEL_DELETED, |
|
456
|
action: "deleted", |
|
457
|
object: "fulfillment_label", |
|
458
|
data: { id: label3.id }, |
|
459
|
}), |
|
460
|
buildExpectedEventMessageShape({ |
|
461
|
eventName: FulfillmentEvents.FULFILLMENT_LABEL_UPDATED, |
|
462
|
action: "updated", |
|
463
|
object: "fulfillment_label", |
|
464
|
data: { id: label2.id }, |
|
465
|
}), |
|
466
|
buildExpectedEventMessageShape({ |
|
467
|
eventName: FulfillmentEvents.FULFILLMENT_LABEL_CREATED, |
|
468
|
action: "created", |
|
469
|
object: "fulfillment_label", |
|
470
|
data: { id: label4.id }, |
|
471
|
}), |
|
472
|
]), |
|
473
|
{ |
|
474
|
internal: true, |
|
475
|
} |
|
476
|
) |
|
477
|
}) |
|
478
|
}) |
|
479
|
|
|
480
|
describe("on cancel", () => { |
|
481
|
let fulfillment |
|
482
|
|
|
483
|
beforeEach(async () => { |
|
484
|
const shippingProfile = await service.createShippingProfiles({ |
|
485
|
name: "test", |
|
486
|
type: "default", |
|
487
|
}) |
|
488
|
const fulfillmentSet = await service.createFulfillmentSets({ |
|
489
|
name: "test", |
|
490
|
type: "test-type", |
|
491
|
}) |
|
492
|
const serviceZone = await service.createServiceZones({ |
|
493
|
name: "test", |
|
494
|
fulfillment_set_id: fulfillmentSet.id, |
|
495
|
}) |
|
496
|
|
|
497
|
const shippingOption = await service.createShippingOptions( |
|
498
|
generateCreateShippingOptionsData({ |
|
499
|
provider_id: providerId, |
|
500
|
service_zone_id: serviceZone.id, |
|
501
|
shipping_profile_id: shippingProfile.id, |
|
502
|
}) |
|
503
|
) |
|
504
|
|
|
505
|
fulfillment = await service.createFulfillment( |
|
506
|
generateCreateFulfillmentData({ |
|
507
|
provider_id: providerId, |
|
508
|
shipping_option_id: shippingOption.id, |
|
509
|
}) |
|
510
|
) |
|
511
|
|
|
512
|
jest.clearAllMocks() |
|
513
|
}) |
|
514
|
|
|
515
|
it("should cancel a fulfillment successfully", async () => { |
|
516
|
const result = await service.cancelFulfillment(fulfillment.id) |
|
517
|
// should be idempotent |
|
518
|
const idempotentResult = await service.cancelFulfillment( |
|
519
|
fulfillment.id |
|
520
|
) |
|
521
|
|
|
522
|
expect(result.canceled_at).not.toBeNull() |
|
523
|
expect(idempotentResult.canceled_at).not.toBeNull() |
|
524
|
expect(idempotentResult.canceled_at).toEqual(result.canceled_at) |
|
525
|
|
|
526
|
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1) |
|
527
|
expect(eventBusEmitSpy).toHaveBeenNthCalledWith( |
|
528
|
1, |
|
529
|
[ |
|
530
|
buildExpectedEventMessageShape({ |
|
531
|
eventName: FulfillmentEvents.FULFILLMENT_UPDATED, |
|
532
|
action: "updated", |
|
533
|
object: "fulfillment", |
|
534
|
data: { id: fulfillment.id }, |
|
535
|
}), |
|
536
|
], |
|
537
|
{ |
|
538
|
internal: true, |
|
539
|
} |
|
540
|
) |
|
541
|
}) |
|
542
|
|
|
543
|
it("should fail to cancel a fulfillment that is already shipped", async () => { |
|
544
|
await service.updateFulfillment(fulfillment.id, { |
|
545
|
shipped_at: new Date(), |
|
546
|
}) |
|
547
|
|
|
548
|
const err = await service |
|
549
|
.cancelFulfillment(fulfillment.id) |
|
550
|
.catch((e) => e) |
|
551
|
|
|
552
|
expect(err.message).toEqual( |
|
553
|
`Fulfillment with id ${fulfillment.id} already shipped` |
|
554
|
) |
|
555
|
}) |
|
556
|
|
|
557
|
it("should fail to cancel a fulfillment that is already delivered", async () => { |
|
558
|
await service.updateFulfillment(fulfillment.id, { |
|
559
|
delivered_at: new Date(), |
|
560
|
}) |
|
561
|
|
|
562
|
const err = await service |
|
563
|
.cancelFulfillment(fulfillment.id) |
|
564
|
.catch((e) => e) |
|
565
|
|
|
566
|
expect(err.message).toEqual( |
|
567
|
`Fulfillment with id ${fulfillment.id} already delivered` |
|
568
|
) |
|
569
|
}) |
|
570
|
}) |
|
571
|
|
|
572
|
describe("on delete", () => { |
|
573
|
let fulfillment |
|
574
|
|
|
575
|
beforeEach(async () => { |
|
576
|
const shippingProfile = await service.createShippingProfiles({ |
|
577
|
name: "test", |
|
578
|
type: "default", |
|
579
|
}) |
|
580
|
|
|
581
|
const fulfillmentSet = await service.createFulfillmentSets({ |
|
582
|
name: "test", |
|
583
|
type: "test-type", |
|
584
|
}) |
|
585
|
|
|
586
|
const serviceZone = await service.createServiceZones({ |
|
587
|
name: "test", |
|
588
|
fulfillment_set_id: fulfillmentSet.id, |
|
589
|
}) |
|
590
|
|
|
591
|
const shippingOption = await service.createShippingOptions( |
|
592
|
generateCreateShippingOptionsData({ |
|
593
|
provider_id: providerId, |
|
594
|
service_zone_id: serviceZone.id, |
|
595
|
shipping_profile_id: shippingProfile.id, |
|
596
|
}) |
|
597
|
) |
|
598
|
|
|
599
|
fulfillment = await service.createFulfillment( |
|
600
|
generateCreateFulfillmentData({ |
|
601
|
provider_id: providerId, |
|
602
|
shipping_option_id: shippingOption.id, |
|
603
|
}) |
|
604
|
) |
|
605
|
|
|
606
|
jest.clearAllMocks() |
|
607
|
}) |
|
608
|
|
|
609
|
it("should delete a canceled fulfillment successfully", async () => { |
|
610
|
await service.cancelFulfillment(fulfillment.id) |
|
611
|
await service.deleteFulfillment(fulfillment.id) |
|
612
|
|
|
613
|
const retrieveError = await service |
|
614
|
.retrieveFulfillment(fulfillment.id) |
|
615
|
.catch((e) => e) |
|
616
|
|
|
617
|
expect(retrieveError.message).toEqual( |
|
618
|
`Fulfillment with id: ${fulfillment.id} was not found` |
|
619
|
) |
|
620
|
}) |
|
621
|
|
|
622
|
it("should fail to delete an uncanceled fulfillment", async () => { |
|
623
|
const deleteError = await service |
|
624
|
.deleteFulfillment(fulfillment.id) |
|
625
|
.catch((e) => e) |
|
626
|
|
|
627
|
expect(deleteError.message).toEqual( |
|
628
|
`Fulfillment with id ${fulfillment.id} needs to be canceled first before deleting` |
|
629
|
) |
|
630
|
}) |
|
631
|
}) |
|
632
|
}) |
|
633
|
}) |
|
634
|
}, |
|
635
|
}) |