|
1
|
import { medusaIntegrationTestRunner } from "@medusajs/test-utils" |
|
2
|
import { MedusaContainer } from "@medusajs/types" |
|
3
|
import { |
|
4
|
ClaimReason, |
|
5
|
ClaimType, |
|
6
|
ContainerRegistrationKeys, |
|
7
|
Modules, |
|
8
|
ProductStatus, |
|
9
|
RuleOperator, |
|
10
|
} from "@medusajs/utils" |
|
11
|
import { |
|
12
|
adminHeaders, |
|
13
|
createAdminUser, |
|
14
|
} from "../../../helpers/create-admin-user" |
|
15
|
import { setupTaxStructure } from "../../../modules/__tests__/fixtures" |
|
16
|
|
|
17
|
jest.setTimeout(60000) |
|
18
|
|
|
19
|
process.env.MEDUSA_FF_TRANSLATION = "true" |
|
20
|
|
|
21
|
medusaIntegrationTestRunner({ |
|
22
|
testSuite: ({ dbConnection, getContainer, api, dbUtils }) => { |
|
23
|
let appContainer: MedusaContainer |
|
24
|
let order |
|
25
|
let product |
|
26
|
let productExtra |
|
27
|
let shippingProfile |
|
28
|
let stockLocation |
|
29
|
let location |
|
30
|
let fulfillmentSet |
|
31
|
let inventoryItem |
|
32
|
let inventoryItemExtra |
|
33
|
let taxRate |
|
34
|
let salesChannel |
|
35
|
let region |
|
36
|
let customer |
|
37
|
let shippingOption |
|
38
|
let returnShippingOption |
|
39
|
let outboundShippingOption |
|
40
|
const shippingProviderId = "manual_test-provider" |
|
41
|
|
|
42
|
beforeAll(async () => { |
|
43
|
appContainer = getContainer() |
|
44
|
const translationModule = appContainer.resolve(Modules.TRANSLATION) |
|
45
|
await translationModule.__hooks?.onApplicationStart?.().catch(() => {}) |
|
46
|
await createAdminUser(dbConnection, adminHeaders, appContainer) |
|
47
|
|
|
48
|
const taxStructure = await setupTaxStructure( |
|
49
|
appContainer.resolve(Modules.TAX) |
|
50
|
) |
|
51
|
|
|
52
|
const storeModule = appContainer.resolve(Modules.STORE) |
|
53
|
const [defaultStore] = await storeModule.listStores( |
|
54
|
{}, |
|
55
|
{ select: ["id"], take: 1 } |
|
56
|
) |
|
57
|
await storeModule.updateStores(defaultStore.id, { |
|
58
|
supported_locales: [ |
|
59
|
{ locale_code: "en-US" }, |
|
60
|
{ locale_code: "fr-FR" }, |
|
61
|
{ locale_code: "de-DE" }, |
|
62
|
], |
|
63
|
}) |
|
64
|
|
|
65
|
region = ( |
|
66
|
await api.post( |
|
67
|
"/admin/regions", |
|
68
|
{ |
|
69
|
name: "test-region", |
|
70
|
currency_code: "usd", |
|
71
|
}, |
|
72
|
adminHeaders |
|
73
|
) |
|
74
|
).data.region |
|
75
|
|
|
76
|
customer = ( |
|
77
|
await api.post( |
|
78
|
"/admin/customers", |
|
79
|
{ |
|
80
|
first_name: "joe", |
|
81
|
email: "joe@admin.com", |
|
82
|
}, |
|
83
|
adminHeaders |
|
84
|
) |
|
85
|
).data.customer |
|
86
|
|
|
87
|
salesChannel = ( |
|
88
|
await api.post( |
|
89
|
"/admin/sales-channels", |
|
90
|
{ |
|
91
|
name: "Test channel", |
|
92
|
}, |
|
93
|
adminHeaders |
|
94
|
) |
|
95
|
).data.sales_channel |
|
96
|
|
|
97
|
shippingProfile = ( |
|
98
|
await api.post( |
|
99
|
`/admin/shipping-profiles`, |
|
100
|
{ |
|
101
|
name: "Test", |
|
102
|
type: "default", |
|
103
|
}, |
|
104
|
adminHeaders |
|
105
|
) |
|
106
|
).data.shipping_profile |
|
107
|
|
|
108
|
location = ( |
|
109
|
await api.post( |
|
110
|
`/admin/stock-locations`, |
|
111
|
{ name: "Test location" }, |
|
112
|
adminHeaders |
|
113
|
) |
|
114
|
).data.stock_location |
|
115
|
|
|
116
|
inventoryItem = ( |
|
117
|
await api.post( |
|
118
|
`/admin/inventory-items`, |
|
119
|
{ sku: "test-variant" }, |
|
120
|
adminHeaders |
|
121
|
) |
|
122
|
).data.inventory_item |
|
123
|
|
|
124
|
await api.post( |
|
125
|
`/admin/inventory-items/${inventoryItem.id}/location-levels`, |
|
126
|
{ location_id: location.id, stocked_quantity: 10 }, |
|
127
|
adminHeaders |
|
128
|
) |
|
129
|
|
|
130
|
await api.post( |
|
131
|
`/admin/stock-locations/${location.id}/sales-channels`, |
|
132
|
{ add: [salesChannel.id] }, |
|
133
|
adminHeaders |
|
134
|
) |
|
135
|
|
|
136
|
product = ( |
|
137
|
await api.post( |
|
138
|
"/admin/products", |
|
139
|
{ |
|
140
|
title: "Test product", |
|
141
|
status: ProductStatus.PUBLISHED, |
|
142
|
options: [{ title: "size", values: ["large", "small"] }], |
|
143
|
shipping_profile_id: shippingProfile.id, |
|
144
|
variants: [ |
|
145
|
{ |
|
146
|
title: "Test variant", |
|
147
|
sku: "test-variant", |
|
148
|
options: { size: "large" }, |
|
149
|
inventory_items: [ |
|
150
|
{ |
|
151
|
inventory_item_id: inventoryItem.id, |
|
152
|
required_quantity: 1, |
|
153
|
}, |
|
154
|
], |
|
155
|
prices: [{ currency_code: "usd", amount: 25 }], |
|
156
|
}, |
|
157
|
], |
|
158
|
}, |
|
159
|
adminHeaders |
|
160
|
) |
|
161
|
).data.product |
|
162
|
|
|
163
|
productExtra = ( |
|
164
|
await api.post( |
|
165
|
"/admin/products", |
|
166
|
{ |
|
167
|
title: "Extra product", |
|
168
|
status: ProductStatus.PUBLISHED, |
|
169
|
options: [{ title: "size", values: ["large", "small"] }], |
|
170
|
shipping_profile_id: shippingProfile.id, |
|
171
|
variants: [ |
|
172
|
{ |
|
173
|
title: "Extra variant", |
|
174
|
sku: "extra-variant", |
|
175
|
options: { size: "large" }, |
|
176
|
prices: [{ currency_code: "usd", amount: 50 }], |
|
177
|
}, |
|
178
|
], |
|
179
|
}, |
|
180
|
adminHeaders |
|
181
|
) |
|
182
|
).data.product |
|
183
|
|
|
184
|
stockLocation = ( |
|
185
|
await api.post( |
|
186
|
`/admin/stock-locations/${location.id}/fulfillment-sets?fields=*fulfillment_sets`, |
|
187
|
{ name: "Test", type: "test-type" }, |
|
188
|
adminHeaders |
|
189
|
) |
|
190
|
).data.stock_location |
|
191
|
|
|
192
|
fulfillmentSet = ( |
|
193
|
await api.post( |
|
194
|
`/admin/fulfillment-sets/${stockLocation.fulfillment_sets[0].id}/service-zones`, |
|
195
|
{ |
|
196
|
name: "Test", |
|
197
|
geo_zones: [{ type: "country", country_code: "us" }], |
|
198
|
}, |
|
199
|
adminHeaders |
|
200
|
) |
|
201
|
).data.fulfillment_set |
|
202
|
|
|
203
|
inventoryItemExtra = ( |
|
204
|
await api.get(`/admin/inventory-items?sku=extra-variant`, adminHeaders) |
|
205
|
).data.inventory_items[0] |
|
206
|
|
|
207
|
await api.post( |
|
208
|
`/admin/inventory-items/${inventoryItemExtra.id}/location-levels`, |
|
209
|
{ |
|
210
|
location_id: location.id, |
|
211
|
stocked_quantity: 10, |
|
212
|
}, |
|
213
|
adminHeaders |
|
214
|
) |
|
215
|
|
|
216
|
const remoteLink = appContainer.resolve( |
|
217
|
ContainerRegistrationKeys.REMOTE_LINK |
|
218
|
) |
|
219
|
|
|
220
|
await api.post( |
|
221
|
`/admin/stock-locations/${stockLocation.id}/fulfillment-providers`, |
|
222
|
{ add: [shippingProviderId] }, |
|
223
|
adminHeaders |
|
224
|
) |
|
225
|
|
|
226
|
shippingOption = ( |
|
227
|
await api.post( |
|
228
|
"/admin/shipping-options", |
|
229
|
{ |
|
230
|
name: "Test shipping option", |
|
231
|
service_zone_id: fulfillmentSet.service_zones[0].id, |
|
232
|
shipping_profile_id: shippingProfile.id, |
|
233
|
provider_id: shippingProviderId, |
|
234
|
price_type: "flat", |
|
235
|
type: { |
|
236
|
label: "Test type", |
|
237
|
description: "Test description", |
|
238
|
code: "test-code", |
|
239
|
}, |
|
240
|
prices: [ |
|
241
|
{ |
|
242
|
currency_code: "usd", |
|
243
|
amount: 10, |
|
244
|
}, |
|
245
|
], |
|
246
|
rules: [], |
|
247
|
}, |
|
248
|
adminHeaders |
|
249
|
) |
|
250
|
).data.shipping_option |
|
251
|
|
|
252
|
returnShippingOption = ( |
|
253
|
await api.post( |
|
254
|
"/admin/shipping-options", |
|
255
|
{ |
|
256
|
name: "Return shipping", |
|
257
|
service_zone_id: fulfillmentSet.service_zones[0].id, |
|
258
|
shipping_profile_id: shippingProfile.id, |
|
259
|
provider_id: "manual_test-provider", |
|
260
|
price_type: "flat", |
|
261
|
type: { |
|
262
|
label: "Test type", |
|
263
|
description: "Test description", |
|
264
|
code: "test-code", |
|
265
|
}, |
|
266
|
prices: [{ currency_code: "usd", amount: 1500 }], |
|
267
|
rules: [ |
|
268
|
{ |
|
269
|
operator: RuleOperator.EQ, |
|
270
|
attribute: "is_return", |
|
271
|
value: "true", |
|
272
|
}, |
|
273
|
], |
|
274
|
}, |
|
275
|
adminHeaders |
|
276
|
) |
|
277
|
).data.shipping_option |
|
278
|
|
|
279
|
outboundShippingOption = ( |
|
280
|
await api.post( |
|
281
|
"/admin/shipping-options", |
|
282
|
{ |
|
283
|
name: "Outbound shipping", |
|
284
|
service_zone_id: fulfillmentSet.service_zones[0].id, |
|
285
|
shipping_profile_id: shippingProfile.id, |
|
286
|
provider_id: shippingProviderId, |
|
287
|
price_type: "flat", |
|
288
|
type: { |
|
289
|
label: "Test type", |
|
290
|
description: "Test description", |
|
291
|
code: "test-code", |
|
292
|
}, |
|
293
|
prices: [{ currency_code: "usd", amount: 0 }], |
|
294
|
rules: [ |
|
295
|
{ |
|
296
|
operator: RuleOperator.EQ, |
|
297
|
attribute: "is_return", |
|
298
|
value: "false", |
|
299
|
}, |
|
300
|
], |
|
301
|
}, |
|
302
|
adminHeaders |
|
303
|
) |
|
304
|
).data.shipping_option |
|
305
|
|
|
306
|
await remoteLink.create([ |
|
307
|
{ |
|
308
|
[Modules.STOCK_LOCATION]: { |
|
309
|
stock_location_id: stockLocation.id, |
|
310
|
}, |
|
311
|
[Modules.FULFILLMENT]: { |
|
312
|
fulfillment_provider_id: shippingProviderId, |
|
313
|
}, |
|
314
|
}, |
|
315
|
{ |
|
316
|
[Modules.STOCK_LOCATION]: { |
|
317
|
stock_location_id: stockLocation.id, |
|
318
|
}, |
|
319
|
[Modules.FULFILLMENT]: { |
|
320
|
fulfillment_set_id: fulfillmentSet.id, |
|
321
|
}, |
|
322
|
}, |
|
323
|
{ |
|
324
|
[Modules.SALES_CHANNEL]: { |
|
325
|
sales_channel_id: salesChannel.id, |
|
326
|
}, |
|
327
|
[Modules.STOCK_LOCATION]: { |
|
328
|
stock_location_id: stockLocation.id, |
|
329
|
}, |
|
330
|
}, |
|
331
|
{ |
|
332
|
[Modules.PRODUCT]: { |
|
333
|
variant_id: product.variants[0].id, |
|
334
|
}, |
|
335
|
[Modules.INVENTORY]: { |
|
336
|
inventory_item_id: inventoryItem.id, |
|
337
|
}, |
|
338
|
}, |
|
339
|
{ |
|
340
|
[Modules.PRODUCT]: { |
|
341
|
variant_id: productExtra.variants[0].id, |
|
342
|
}, |
|
343
|
[Modules.INVENTORY]: { |
|
344
|
inventory_item_id: inventoryItemExtra.id, |
|
345
|
}, |
|
346
|
}, |
|
347
|
]) |
|
348
|
|
|
349
|
const taxRatesResponse = await api.get( |
|
350
|
`/admin/tax-rates?tax_region_id=${taxStructure.us.children.cal.province.id}`, |
|
351
|
adminHeaders |
|
352
|
) |
|
353
|
taxRate = taxRatesResponse.data.tax_rates.find( |
|
354
|
(rate: { code: string }) => rate.code === "CADEFAULT" |
|
355
|
) |
|
356
|
|
|
357
|
// Create translations for tax rates and shipping options |
|
358
|
await api.post( |
|
359
|
"/admin/translations/batch", |
|
360
|
{ |
|
361
|
create: [ |
|
362
|
{ |
|
363
|
reference_id: taxRate.id, |
|
364
|
reference: "tax_rate", |
|
365
|
locale_code: "fr-FR", |
|
366
|
translations: { |
|
367
|
name: "Taux par défaut CA", |
|
368
|
}, |
|
369
|
}, |
|
370
|
{ |
|
371
|
reference_id: taxRate.id, |
|
372
|
reference: "tax_rate", |
|
373
|
locale_code: "de-DE", |
|
374
|
translations: { |
|
375
|
name: "CA Standardsteuersatz", |
|
376
|
}, |
|
377
|
}, |
|
378
|
{ |
|
379
|
reference_id: returnShippingOption.id, |
|
380
|
reference: "shipping_option", |
|
381
|
locale_code: "fr-FR", |
|
382
|
translations: { name: "Expédition de retour" }, |
|
383
|
}, |
|
384
|
{ |
|
385
|
reference_id: returnShippingOption.id, |
|
386
|
reference: "shipping_option", |
|
387
|
locale_code: "de-DE", |
|
388
|
translations: { name: "Rückversand" }, |
|
389
|
}, |
|
390
|
{ |
|
391
|
reference_id: outboundShippingOption.id, |
|
392
|
reference: "shipping_option", |
|
393
|
locale_code: "fr-FR", |
|
394
|
translations: { name: "Expédition sortante" }, |
|
395
|
}, |
|
396
|
{ |
|
397
|
reference_id: outboundShippingOption.id, |
|
398
|
reference: "shipping_option", |
|
399
|
locale_code: "de-DE", |
|
400
|
translations: { name: "Ausgehende Versand" }, |
|
401
|
}, |
|
402
|
], |
|
403
|
}, |
|
404
|
adminHeaders |
|
405
|
) |
|
406
|
|
|
407
|
await dbUtils.snapshot() |
|
408
|
}) |
|
409
|
|
|
410
|
const createOrderWithLocale = async (locale?: string) => { |
|
411
|
const orderModule = appContainer.resolve(Modules.ORDER) |
|
412
|
const inventoryModule = appContainer.resolve(Modules.INVENTORY) |
|
413
|
|
|
414
|
const createdOrder = await orderModule.createOrders({ |
|
415
|
region_id: region.id, |
|
416
|
email: "foo@bar.com", |
|
417
|
locale, |
|
418
|
items: [ |
|
419
|
{ |
|
420
|
title: "Custom Item", |
|
421
|
variant_id: product.variants[0].id, |
|
422
|
quantity: 2, |
|
423
|
unit_price: 25, |
|
424
|
}, |
|
425
|
], |
|
426
|
sales_channel_id: salesChannel.id, |
|
427
|
shipping_address: { |
|
428
|
customer_id: customer.id, |
|
429
|
first_name: "Test", |
|
430
|
last_name: "Test", |
|
431
|
address_1: "Test", |
|
432
|
city: "Test", |
|
433
|
country_code: "US", |
|
434
|
province: "CA", |
|
435
|
postal_code: "12345", |
|
436
|
phone: "12345", |
|
437
|
}, |
|
438
|
billing_address: { |
|
439
|
customer_id: customer.id, |
|
440
|
first_name: "Test", |
|
441
|
last_name: "Test", |
|
442
|
address_1: "Test", |
|
443
|
city: "Test", |
|
444
|
country_code: "US", |
|
445
|
province: "CA", |
|
446
|
postal_code: "12345", |
|
447
|
}, |
|
448
|
shipping_methods: [ |
|
449
|
{ |
|
450
|
name: "Test shipping method", |
|
451
|
amount: 10, |
|
452
|
data: {}, |
|
453
|
shipping_option_id: shippingOption.id, |
|
454
|
}, |
|
455
|
], |
|
456
|
currency_code: "usd", |
|
457
|
customer_id: customer.id, |
|
458
|
transactions: [ |
|
459
|
{ |
|
460
|
amount: 60, |
|
461
|
currency_code: "usd", |
|
462
|
}, |
|
463
|
], |
|
464
|
}) |
|
465
|
|
|
466
|
await inventoryModule.createReservationItems([ |
|
467
|
{ |
|
468
|
inventory_item_id: inventoryItem.id, |
|
469
|
location_id: stockLocation.id, |
|
470
|
quantity: 2, |
|
471
|
line_item_id: createdOrder.items![0].id, |
|
472
|
}, |
|
473
|
]) |
|
474
|
|
|
475
|
// Fulfill the order |
|
476
|
await api.post( |
|
477
|
`/admin/orders/${createdOrder.id}/fulfillments`, |
|
478
|
{ |
|
479
|
items: [ |
|
480
|
{ |
|
481
|
id: createdOrder.items![0].id, |
|
482
|
quantity: 2, |
|
483
|
}, |
|
484
|
], |
|
485
|
}, |
|
486
|
adminHeaders |
|
487
|
) |
|
488
|
|
|
489
|
return createdOrder |
|
490
|
} |
|
491
|
|
|
492
|
describe("Claims tax line translations", () => { |
|
493
|
describe("when adding outbound items to a claim", () => { |
|
494
|
it("should translate tax lines based on order locale when adding new items", async () => { |
|
495
|
order = await createOrderWithLocale("fr-FR") |
|
496
|
|
|
497
|
const claim = ( |
|
498
|
await api.post( |
|
499
|
"/admin/claims", |
|
500
|
{ |
|
501
|
order_id: order.id, |
|
502
|
type: ClaimType.REPLACE, |
|
503
|
description: "Test claim", |
|
504
|
}, |
|
505
|
adminHeaders |
|
506
|
) |
|
507
|
).data.claim |
|
508
|
|
|
509
|
await api.post( |
|
510
|
`/admin/claims/${claim.id}/outbound/items`, |
|
511
|
{ |
|
512
|
items: [ |
|
513
|
{ |
|
514
|
variant_id: productExtra.variants[0].id, |
|
515
|
quantity: 1, |
|
516
|
}, |
|
517
|
], |
|
518
|
}, |
|
519
|
adminHeaders |
|
520
|
) |
|
521
|
|
|
522
|
await api.post(`/admin/claims/${claim.id}/request`, {}, adminHeaders) |
|
523
|
|
|
524
|
const updatedOrder = ( |
|
525
|
await api.get(`/admin/orders/${order.id}`, adminHeaders) |
|
526
|
).data.order |
|
527
|
|
|
528
|
const newItem = updatedOrder.items.find( |
|
529
|
(item) => item.title === "Extra product" |
|
530
|
) |
|
531
|
|
|
532
|
expect(newItem).toBeDefined() |
|
533
|
expect(newItem.tax_lines).toBeDefined() |
|
534
|
expect(newItem.tax_lines.length).toBeGreaterThan(0) |
|
535
|
|
|
536
|
const taxLine = newItem.tax_lines.find( |
|
537
|
(tl) => tl.code === "CADEFAULT" |
|
538
|
) |
|
539
|
expect(taxLine).toBeDefined() |
|
540
|
expect(taxLine.description).toEqual("Taux par défaut CA") |
|
541
|
}) |
|
542
|
|
|
543
|
it("should use original tax line description when order has no locale", async () => { |
|
544
|
order = await createOrderWithLocale() |
|
545
|
|
|
546
|
const claim = ( |
|
547
|
await api.post( |
|
548
|
"/admin/claims", |
|
549
|
{ |
|
550
|
order_id: order.id, |
|
551
|
type: ClaimType.REPLACE, |
|
552
|
description: "Test claim", |
|
553
|
}, |
|
554
|
adminHeaders |
|
555
|
) |
|
556
|
).data.claim |
|
557
|
|
|
558
|
await api.post( |
|
559
|
`/admin/claims/${claim.id}/outbound/items`, |
|
560
|
{ |
|
561
|
items: [ |
|
562
|
{ |
|
563
|
variant_id: productExtra.variants[0].id, |
|
564
|
quantity: 1, |
|
565
|
}, |
|
566
|
], |
|
567
|
}, |
|
568
|
adminHeaders |
|
569
|
) |
|
570
|
|
|
571
|
await api.post(`/admin/claims/${claim.id}/request`, {}, adminHeaders) |
|
572
|
|
|
573
|
const updatedOrder = ( |
|
574
|
await api.get(`/admin/orders/${order.id}`, adminHeaders) |
|
575
|
).data.order |
|
576
|
|
|
577
|
const newItem = updatedOrder.items.find( |
|
578
|
(item) => item.title === "Extra product" |
|
579
|
) |
|
580
|
|
|
581
|
expect(newItem).toBeDefined() |
|
582
|
expect(newItem.tax_lines).toBeDefined() |
|
583
|
expect(newItem.tax_lines.length).toBeGreaterThan(0) |
|
584
|
|
|
585
|
const taxLine = newItem.tax_lines.find( |
|
586
|
(tl) => tl.code === "CADEFAULT" |
|
587
|
) |
|
588
|
expect(taxLine).toBeDefined() |
|
589
|
expect(taxLine.description).toEqual("CA Default Rate") |
|
590
|
}) |
|
591
|
}) |
|
592
|
|
|
593
|
describe("when adding outbound shipping methods to a claim", () => { |
|
594
|
it("should translate shipping method tax lines based on order locale", async () => { |
|
595
|
order = await createOrderWithLocale("fr-FR") |
|
596
|
|
|
597
|
await api.post( |
|
598
|
`/admin/orders/${order.id}`, |
|
599
|
{ locale: "fr-FR" }, |
|
600
|
adminHeaders |
|
601
|
) |
|
602
|
|
|
603
|
const claim = ( |
|
604
|
await api.post( |
|
605
|
"/admin/claims", |
|
606
|
{ |
|
607
|
order_id: order.id, |
|
608
|
type: ClaimType.REPLACE, |
|
609
|
description: "Test claim", |
|
610
|
}, |
|
611
|
adminHeaders |
|
612
|
) |
|
613
|
).data.claim |
|
614
|
|
|
615
|
await api.post( |
|
616
|
`/admin/claims/${claim.id}/outbound/items`, |
|
617
|
{ |
|
618
|
items: [ |
|
619
|
{ |
|
620
|
variant_id: productExtra.variants[0].id, |
|
621
|
quantity: 1, |
|
622
|
}, |
|
623
|
], |
|
624
|
}, |
|
625
|
adminHeaders |
|
626
|
) |
|
627
|
|
|
628
|
await api.post( |
|
629
|
`/admin/claims/${claim.id}/outbound/shipping-method`, |
|
630
|
{ shipping_option_id: outboundShippingOption.id }, |
|
631
|
adminHeaders |
|
632
|
) |
|
633
|
|
|
634
|
await api.post(`/admin/claims/${claim.id}/request`, {}, adminHeaders) |
|
635
|
|
|
636
|
const updatedOrder = ( |
|
637
|
await api.get(`/admin/orders/${order.id}`, adminHeaders) |
|
638
|
).data.order |
|
639
|
|
|
640
|
const outboundShippingMethod = updatedOrder.shipping_methods.find( |
|
641
|
(sm) => sm.shipping_option_id === outboundShippingOption.id |
|
642
|
) |
|
643
|
|
|
644
|
expect(outboundShippingMethod.tax_lines.length).toBeGreaterThan(0) |
|
645
|
const taxLine = outboundShippingMethod.tax_lines.find( |
|
646
|
(tl) => tl.code === "CADEFAULT" |
|
647
|
) |
|
648
|
expect(taxLine.description).toEqual("Taux par défaut CA") |
|
649
|
}) |
|
650
|
|
|
651
|
it("should use original tax line description when order has no locale", async () => { |
|
652
|
order = await createOrderWithLocale() |
|
653
|
|
|
654
|
const claim = ( |
|
655
|
await api.post( |
|
656
|
"/admin/claims", |
|
657
|
{ |
|
658
|
order_id: order.id, |
|
659
|
type: ClaimType.REPLACE, |
|
660
|
description: "Test claim", |
|
661
|
}, |
|
662
|
adminHeaders |
|
663
|
) |
|
664
|
).data.claim |
|
665
|
|
|
666
|
await api.post( |
|
667
|
`/admin/claims/${claim.id}/outbound/items`, |
|
668
|
{ |
|
669
|
items: [ |
|
670
|
{ |
|
671
|
variant_id: productExtra.variants[0].id, |
|
672
|
quantity: 1, |
|
673
|
}, |
|
674
|
], |
|
675
|
}, |
|
676
|
adminHeaders |
|
677
|
) |
|
678
|
|
|
679
|
await api.post( |
|
680
|
`/admin/claims/${claim.id}/outbound/shipping-method`, |
|
681
|
{ shipping_option_id: outboundShippingOption.id }, |
|
682
|
adminHeaders |
|
683
|
) |
|
684
|
|
|
685
|
await api.post(`/admin/claims/${claim.id}/request`, {}, adminHeaders) |
|
686
|
|
|
687
|
const updatedOrder = ( |
|
688
|
await api.get(`/admin/orders/${order.id}`, adminHeaders) |
|
689
|
).data.order |
|
690
|
|
|
691
|
const outboundShippingMethod = updatedOrder.shipping_methods.find( |
|
692
|
(sm) => sm.shipping_option_id === outboundShippingOption.id |
|
693
|
) |
|
694
|
|
|
695
|
expect(outboundShippingMethod.tax_lines.length).toBeGreaterThan(0) |
|
696
|
const taxLine = outboundShippingMethod.tax_lines.find( |
|
697
|
(tl) => tl.code === "CADEFAULT" |
|
698
|
) |
|
699
|
expect(taxLine.description).toEqual("CA Default Rate") |
|
700
|
}) |
|
701
|
}) |
|
702
|
|
|
703
|
describe("when updating outbound items in a claim", () => { |
|
704
|
it("should preserve tax line translations when updating item quantity", async () => { |
|
705
|
order = await createOrderWithLocale("fr-FR") |
|
706
|
|
|
707
|
await api.post( |
|
708
|
`/admin/orders/${order.id}`, |
|
709
|
{ locale: "fr-FR" }, |
|
710
|
adminHeaders |
|
711
|
) |
|
712
|
|
|
713
|
const claim = ( |
|
714
|
await api.post( |
|
715
|
"/admin/claims", |
|
716
|
{ |
|
717
|
order_id: order.id, |
|
718
|
type: ClaimType.REPLACE, |
|
719
|
description: "Test claim", |
|
720
|
}, |
|
721
|
adminHeaders |
|
722
|
) |
|
723
|
).data.claim |
|
724
|
|
|
725
|
const addItemResponse = await api.post( |
|
726
|
`/admin/claims/${claim.id}/outbound/items`, |
|
727
|
{ |
|
728
|
items: [ |
|
729
|
{ |
|
730
|
variant_id: productExtra.variants[0].id, |
|
731
|
quantity: 1, |
|
732
|
}, |
|
733
|
], |
|
734
|
}, |
|
735
|
adminHeaders |
|
736
|
) |
|
737
|
|
|
738
|
const actionId = addItemResponse.data.order_preview.items.find( |
|
739
|
(item) => |
|
740
|
!!item.actions?.find((action) => action.action === "ITEM_ADD") |
|
741
|
).actions[0].id |
|
742
|
|
|
743
|
await api.post( |
|
744
|
`/admin/claims/${claim.id}/outbound/items/${actionId}`, |
|
745
|
{ |
|
746
|
quantity: 2, |
|
747
|
}, |
|
748
|
adminHeaders |
|
749
|
) |
|
750
|
|
|
751
|
await api.post(`/admin/claims/${claim.id}/request`, {}, adminHeaders) |
|
752
|
|
|
753
|
const updatedOrder = ( |
|
754
|
await api.get(`/admin/orders/${order.id}`, adminHeaders) |
|
755
|
).data.order |
|
756
|
|
|
757
|
const newItem = updatedOrder.items.find( |
|
758
|
(item) => item.title === "Extra product" |
|
759
|
) |
|
760
|
|
|
761
|
expect(newItem).toBeDefined() |
|
762
|
expect(newItem.tax_lines).toBeDefined() |
|
763
|
expect(newItem.tax_lines.length).toBeGreaterThan(0) |
|
764
|
|
|
765
|
const taxLine = newItem.tax_lines.find( |
|
766
|
(tl) => tl.code === "CADEFAULT" |
|
767
|
) |
|
768
|
expect(taxLine).toBeDefined() |
|
769
|
expect(taxLine.description).toEqual("Taux par défaut CA") |
|
770
|
}) |
|
771
|
}) |
|
772
|
}) |
|
773
|
|
|
774
|
describe("Claim shipping method translation", () => { |
|
775
|
describe("Inbound (return) shipping method", () => { |
|
776
|
it("should translate inbound shipping method name using French locale", async () => { |
|
777
|
order = await createOrderWithLocale("fr-FR") |
|
778
|
|
|
779
|
const claim = ( |
|
780
|
await api.post( |
|
781
|
"/admin/claims", |
|
782
|
{ |
|
783
|
order_id: order.id, |
|
784
|
type: ClaimType.REPLACE, |
|
785
|
description: "Test claim", |
|
786
|
}, |
|
787
|
adminHeaders |
|
788
|
) |
|
789
|
).data.claim |
|
790
|
|
|
791
|
await api.post( |
|
792
|
`/admin/claims/${claim.id}/inbound/items`, |
|
793
|
{ |
|
794
|
items: [ |
|
795
|
{ |
|
796
|
id: order.items![0].id, |
|
797
|
quantity: 1, |
|
798
|
reason: ClaimReason.PRODUCTION_FAILURE, |
|
799
|
}, |
|
800
|
], |
|
801
|
}, |
|
802
|
adminHeaders |
|
803
|
) |
|
804
|
|
|
805
|
const shippingMethodResult = await api.post( |
|
806
|
`/admin/claims/${claim.id}/inbound/shipping-method`, |
|
807
|
{ shipping_option_id: returnShippingOption.id }, |
|
808
|
adminHeaders |
|
809
|
) |
|
810
|
|
|
811
|
const inboundShippingMethod = |
|
812
|
shippingMethodResult.data.order_preview.shipping_methods.find( |
|
813
|
(sm: any) => sm.shipping_option_id === returnShippingOption.id |
|
814
|
) |
|
815
|
|
|
816
|
expect(inboundShippingMethod).toEqual( |
|
817
|
expect.objectContaining({ |
|
818
|
name: "Expédition de retour", |
|
819
|
shipping_option_id: returnShippingOption.id, |
|
820
|
}) |
|
821
|
) |
|
822
|
}) |
|
823
|
|
|
824
|
it("should use original inbound shipping method name when order has no locale", async () => { |
|
825
|
order = await createOrderWithLocale() |
|
826
|
|
|
827
|
const claim = ( |
|
828
|
await api.post( |
|
829
|
"/admin/claims", |
|
830
|
{ |
|
831
|
order_id: order.id, |
|
832
|
type: ClaimType.REPLACE, |
|
833
|
description: "Test claim", |
|
834
|
}, |
|
835
|
adminHeaders |
|
836
|
) |
|
837
|
).data.claim |
|
838
|
|
|
839
|
await api.post( |
|
840
|
`/admin/claims/${claim.id}/inbound/items`, |
|
841
|
{ |
|
842
|
items: [ |
|
843
|
{ |
|
844
|
id: order.items![0].id, |
|
845
|
quantity: 1, |
|
846
|
reason: ClaimReason.PRODUCTION_FAILURE, |
|
847
|
}, |
|
848
|
], |
|
849
|
}, |
|
850
|
adminHeaders |
|
851
|
) |
|
852
|
|
|
853
|
const shippingMethodResult = await api.post( |
|
854
|
`/admin/claims/${claim.id}/inbound/shipping-method`, |
|
855
|
{ shipping_option_id: returnShippingOption.id }, |
|
856
|
adminHeaders |
|
857
|
) |
|
858
|
|
|
859
|
const inboundShippingMethod = |
|
860
|
shippingMethodResult.data.order_preview.shipping_methods.find( |
|
861
|
(sm: any) => sm.shipping_option_id === returnShippingOption.id |
|
862
|
) |
|
863
|
|
|
864
|
expect(inboundShippingMethod).toEqual( |
|
865
|
expect.objectContaining({ |
|
866
|
name: "Return shipping", |
|
867
|
shipping_option_id: returnShippingOption.id, |
|
868
|
}) |
|
869
|
) |
|
870
|
}) |
|
871
|
}) |
|
872
|
|
|
873
|
describe("Outbound shipping method", () => { |
|
874
|
it("should translate outbound shipping method", async () => { |
|
875
|
order = await createOrderWithLocale("fr-FR") |
|
876
|
|
|
877
|
const claim = ( |
|
878
|
await api.post( |
|
879
|
"/admin/claims", |
|
880
|
{ |
|
881
|
order_id: order.id, |
|
882
|
type: ClaimType.REPLACE, |
|
883
|
description: "Test claim", |
|
884
|
}, |
|
885
|
adminHeaders |
|
886
|
) |
|
887
|
).data.claim |
|
888
|
|
|
889
|
await api.post( |
|
890
|
`/admin/claims/${claim.id}/inbound/items`, |
|
891
|
{ |
|
892
|
items: [ |
|
893
|
{ |
|
894
|
id: order.items![0].id, |
|
895
|
quantity: 1, |
|
896
|
reason: ClaimReason.PRODUCTION_FAILURE, |
|
897
|
}, |
|
898
|
], |
|
899
|
}, |
|
900
|
adminHeaders |
|
901
|
) |
|
902
|
|
|
903
|
await api.post( |
|
904
|
`/admin/claims/${claim.id}/outbound/items`, |
|
905
|
{ |
|
906
|
items: [ |
|
907
|
{ |
|
908
|
variant_id: productExtra.variants[0].id, |
|
909
|
quantity: 1, |
|
910
|
}, |
|
911
|
], |
|
912
|
}, |
|
913
|
adminHeaders |
|
914
|
) |
|
915
|
|
|
916
|
const shippingMethodResult = await api.post( |
|
917
|
`/admin/claims/${claim.id}/outbound/shipping-method`, |
|
918
|
{ shipping_option_id: outboundShippingOption.id }, |
|
919
|
adminHeaders |
|
920
|
) |
|
921
|
|
|
922
|
const outboundShippingMethod = |
|
923
|
shippingMethodResult.data.order_preview.shipping_methods.find( |
|
924
|
(sm: any) => sm.shipping_option_id === outboundShippingOption.id |
|
925
|
) |
|
926
|
|
|
927
|
expect(outboundShippingMethod).toEqual( |
|
928
|
expect.objectContaining({ |
|
929
|
name: "Expédition sortante", |
|
930
|
shipping_option_id: outboundShippingOption.id, |
|
931
|
}) |
|
932
|
) |
|
933
|
}) |
|
934
|
|
|
935
|
it("should use original outbound shipping method name when order has no locale", async () => { |
|
936
|
order = await createOrderWithLocale() |
|
937
|
|
|
938
|
const claim = ( |
|
939
|
await api.post( |
|
940
|
"/admin/claims", |
|
941
|
{ |
|
942
|
order_id: order.id, |
|
943
|
type: ClaimType.REPLACE, |
|
944
|
description: "Test claim", |
|
945
|
}, |
|
946
|
adminHeaders |
|
947
|
) |
|
948
|
).data.claim |
|
949
|
|
|
950
|
await api.post( |
|
951
|
`/admin/claims/${claim.id}/inbound/items`, |
|
952
|
{ |
|
953
|
items: [ |
|
954
|
{ |
|
955
|
id: order.items![0].id, |
|
956
|
quantity: 1, |
|
957
|
reason: ClaimReason.PRODUCTION_FAILURE, |
|
958
|
}, |
|
959
|
], |
|
960
|
}, |
|
961
|
adminHeaders |
|
962
|
) |
|
963
|
|
|
964
|
await api.post( |
|
965
|
`/admin/claims/${claim.id}/outbound/items`, |
|
966
|
{ |
|
967
|
items: [ |
|
968
|
{ |
|
969
|
variant_id: productExtra.variants[0].id, |
|
970
|
quantity: 1, |
|
971
|
}, |
|
972
|
], |
|
973
|
}, |
|
974
|
adminHeaders |
|
975
|
) |
|
976
|
|
|
977
|
const shippingMethodResult = await api.post( |
|
978
|
`/admin/claims/${claim.id}/outbound/shipping-method`, |
|
979
|
{ shipping_option_id: outboundShippingOption.id }, |
|
980
|
adminHeaders |
|
981
|
) |
|
982
|
|
|
983
|
const outboundShippingMethod = |
|
984
|
shippingMethodResult.data.order_preview.shipping_methods.find( |
|
985
|
(sm: any) => sm.shipping_option_id === outboundShippingOption.id |
|
986
|
) |
|
987
|
|
|
988
|
expect(outboundShippingMethod).toEqual( |
|
989
|
expect.objectContaining({ |
|
990
|
name: "Outbound shipping", |
|
991
|
shipping_option_id: outboundShippingOption.id, |
|
992
|
}) |
|
993
|
) |
|
994
|
}) |
|
995
|
}) |
|
996
|
|
|
997
|
describe("Both inbound and outbound shipping methods", () => { |
|
998
|
it("should translate both shipping methods", async () => { |
|
999
|
order = await createOrderWithLocale("fr-FR") |
|
1000
|
|
|
1001
|
const claim = ( |
|
1002
|
await api.post( |
|
1003
|
"/admin/claims", |
|
1004
|
{ |
|
1005
|
order_id: order.id, |
|
1006
|
type: ClaimType.REPLACE, |
|
1007
|
description: "Test claim", |
|
1008
|
}, |
|
1009
|
adminHeaders |
|
1010
|
) |
|
1011
|
).data.claim |
|
1012
|
|
|
1013
|
await api.post( |
|
1014
|
`/admin/claims/${claim.id}/inbound/items`, |
|
1015
|
{ |
|
1016
|
items: [ |
|
1017
|
{ |
|
1018
|
id: order.items![0].id, |
|
1019
|
quantity: 1, |
|
1020
|
reason: ClaimReason.PRODUCTION_FAILURE, |
|
1021
|
}, |
|
1022
|
], |
|
1023
|
}, |
|
1024
|
adminHeaders |
|
1025
|
) |
|
1026
|
|
|
1027
|
await api.post( |
|
1028
|
`/admin/claims/${claim.id}/inbound/shipping-method`, |
|
1029
|
{ shipping_option_id: returnShippingOption.id }, |
|
1030
|
adminHeaders |
|
1031
|
) |
|
1032
|
|
|
1033
|
await api.post( |
|
1034
|
`/admin/claims/${claim.id}/outbound/items`, |
|
1035
|
{ |
|
1036
|
items: [ |
|
1037
|
{ |
|
1038
|
variant_id: productExtra.variants[0].id, |
|
1039
|
quantity: 1, |
|
1040
|
}, |
|
1041
|
], |
|
1042
|
}, |
|
1043
|
adminHeaders |
|
1044
|
) |
|
1045
|
|
|
1046
|
const result = await api.post( |
|
1047
|
`/admin/claims/${claim.id}/outbound/shipping-method`, |
|
1048
|
{ shipping_option_id: outboundShippingOption.id }, |
|
1049
|
adminHeaders |
|
1050
|
) |
|
1051
|
|
|
1052
|
const shippingMethods = result.data.order_preview.shipping_methods |
|
1053
|
|
|
1054
|
const inboundShippingMethod = shippingMethods.find( |
|
1055
|
(sm: any) => sm.shipping_option_id === returnShippingOption.id |
|
1056
|
) |
|
1057
|
const outboundShippingMethod = shippingMethods.find( |
|
1058
|
(sm: any) => sm.shipping_option_id === outboundShippingOption.id |
|
1059
|
) |
|
1060
|
|
|
1061
|
expect(inboundShippingMethod).toEqual( |
|
1062
|
expect.objectContaining({ |
|
1063
|
name: "Expédition de retour", |
|
1064
|
shipping_option_id: returnShippingOption.id, |
|
1065
|
}) |
|
1066
|
) |
|
1067
|
|
|
1068
|
expect(outboundShippingMethod).toEqual( |
|
1069
|
expect.objectContaining({ |
|
1070
|
name: "Expédition sortante", |
|
1071
|
shipping_option_id: outboundShippingOption.id, |
|
1072
|
}) |
|
1073
|
) |
|
1074
|
}) |
|
1075
|
|
|
1076
|
it("should keep translations after confirming claim request", async () => { |
|
1077
|
order = await createOrderWithLocale("fr-FR") |
|
1078
|
|
|
1079
|
const claim = ( |
|
1080
|
await api.post( |
|
1081
|
"/admin/claims", |
|
1082
|
{ |
|
1083
|
order_id: order.id, |
|
1084
|
type: ClaimType.REPLACE, |
|
1085
|
description: "Test claim", |
|
1086
|
}, |
|
1087
|
adminHeaders |
|
1088
|
) |
|
1089
|
).data.claim |
|
1090
|
|
|
1091
|
await api.post( |
|
1092
|
`/admin/claims/${claim.id}/inbound/items`, |
|
1093
|
{ |
|
1094
|
items: [ |
|
1095
|
{ |
|
1096
|
id: order.items![0].id, |
|
1097
|
quantity: 1, |
|
1098
|
reason: ClaimReason.PRODUCTION_FAILURE, |
|
1099
|
}, |
|
1100
|
], |
|
1101
|
}, |
|
1102
|
adminHeaders |
|
1103
|
) |
|
1104
|
|
|
1105
|
await api.post( |
|
1106
|
`/admin/claims/${claim.id}/inbound/shipping-method`, |
|
1107
|
{ shipping_option_id: returnShippingOption.id }, |
|
1108
|
adminHeaders |
|
1109
|
) |
|
1110
|
|
|
1111
|
await api.post( |
|
1112
|
`/admin/claims/${claim.id}/outbound/items`, |
|
1113
|
{ |
|
1114
|
items: [ |
|
1115
|
{ |
|
1116
|
variant_id: productExtra.variants[0].id, |
|
1117
|
quantity: 1, |
|
1118
|
}, |
|
1119
|
], |
|
1120
|
}, |
|
1121
|
adminHeaders |
|
1122
|
) |
|
1123
|
|
|
1124
|
await api.post( |
|
1125
|
`/admin/claims/${claim.id}/outbound/shipping-method`, |
|
1126
|
{ shipping_option_id: outboundShippingOption.id }, |
|
1127
|
adminHeaders |
|
1128
|
) |
|
1129
|
|
|
1130
|
await api.post(`/admin/claims/${claim.id}/request`, {}, adminHeaders) |
|
1131
|
|
|
1132
|
const orderResult = await api.get( |
|
1133
|
`/admin/orders/${order.id}`, |
|
1134
|
adminHeaders |
|
1135
|
) |
|
1136
|
|
|
1137
|
const shippingMethods = orderResult.data.order.shipping_methods |
|
1138
|
|
|
1139
|
const outboundShippingMethod = shippingMethods.find( |
|
1140
|
(sm: any) => sm.shipping_option_id === outboundShippingOption.id |
|
1141
|
) |
|
1142
|
|
|
1143
|
expect(outboundShippingMethod).toEqual( |
|
1144
|
expect.objectContaining({ |
|
1145
|
name: "Expédition sortante", |
|
1146
|
shipping_option_id: outboundShippingOption.id, |
|
1147
|
}) |
|
1148
|
) |
|
1149
|
}) |
|
1150
|
}) |
|
1151
|
}) |
|
1152
|
}, |
|
1153
|
}) |