1 import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
2 import { MedusaContainer } from "@medusajs/types"
3 import { Modules, ProductStatus } from "@medusajs/utils"
4 import {
5 adminHeaders,
6 createAdminUser,
7 } from "../../../../helpers/create-admin-user"
8 import { setupTaxStructure } from "../../../../modules/__tests__/fixtures"
9
10 jest.setTimeout(300000)
11
12 process.env.MEDUSA_FF_TRANSLATION = "true"
13
14 medusaIntegrationTestRunner({
15 testSuite: ({ dbConnection, getContainer, api, dbUtils }) => {
16 describe("Admin Draft Order Translation API", () => {
17 let appContainer: MedusaContainer
18 let region: { id: string }
19 let product: { id: string; variants: { id: string; title: string }[] }
20 let salesChannel: { id: string }
21 let shippingProfile: { id: string }
22 let stockLocation: { id: string }
23 let shippingOption: { id: string }
24 let taxRate: { id: string }
25
26 beforeAll(async () => {
27 appContainer = getContainer()
28 })
29
30 beforeAll(async () => {
31 const taxStructure = await setupTaxStructure(
32 appContainer.resolve(Modules.TAX)
33 )
34 await createAdminUser(dbConnection, adminHeaders, appContainer)
35
36 const translationModule = appContainer.resolve(Modules.TRANSLATION)
37 await translationModule.__hooks?.onApplicationStart?.().catch(() => {})
38
39 salesChannel = (
40 await api.post(
41 "/admin/sales-channels",
42 { name: "Webshop", description: "channel" },
43 adminHeaders
44 )
45 ).data.sales_channel
46
47 const storeModule = appContainer.resolve(Modules.STORE)
48 const [defaultStore] = await storeModule.listStores(
49 {},
50 { select: ["id"], take: 1 }
51 )
52 await storeModule.updateStores(defaultStore.id, {
53 supported_locales: [
54 { locale_code: "en-US" },
55 { locale_code: "fr-FR" },
56 { locale_code: "de-DE" },
57 ],
58 })
59
60 region = (
61 await api.post(
62 "/admin/regions",
63 { name: "US", currency_code: "usd", countries: ["us"] },
64 adminHeaders
65 )
66 ).data.region
67
68 shippingProfile = (
69 await api.post(
70 `/admin/shipping-profiles`,
71 { name: "default", type: "default" },
72 adminHeaders
73 )
74 ).data.shipping_profile
75
76 stockLocation = (
77 await api.post(
78 `/admin/stock-locations`,
79 { name: "test location" },
80 adminHeaders
81 )
82 ).data.stock_location
83
84 await api.post(
85 `/admin/stock-locations/${stockLocation.id}/sales-channels`,
86 { add: [salesChannel.id] },
87 adminHeaders
88 )
89
90 product = (
91 await api.post(
92 "/admin/products",
93 {
94 title: "Medusa T-Shirt",
95 description: "A comfortable cotton t-shirt",
96 handle: "t-shirt",
97 status: ProductStatus.PUBLISHED,
98 shipping_profile_id: shippingProfile.id,
99 options: [{ title: "Size", values: ["S", "M"] }],
100 variants: [
101 {
102 title: "Small",
103 sku: "SHIRT-S",
104 options: { Size: "S" },
105 manage_inventory: false,
106 prices: [{ amount: 1500, currency_code: "usd" }],
107 },
108 {
109 title: "Medium",
110 sku: "SHIRT-M",
111 options: { Size: "M" },
112 manage_inventory: false,
113 prices: [{ amount: 1500, currency_code: "usd" }],
114 },
115 ],
116 },
117 adminHeaders
118 )
119 ).data.product
120
121 const variantSmall = product.variants.find((v) => v.title === "Small")
122 const variantMedium = product.variants.find((v) => v.title === "Medium")
123 product.variants = [variantSmall!, variantMedium!]
124
125 const fulfillmentSets = (
126 await api.post(
127 `/admin/stock-locations/${stockLocation.id}/fulfillment-sets?fields=*fulfillment_sets`,
128 { name: "Test", type: "test-type" },
129 adminHeaders
130 )
131 ).data.stock_location.fulfillment_sets
132
133 const fulfillmentSet = (
134 await api.post(
135 `/admin/fulfillment-sets/${fulfillmentSets[0].id}/service-zones`,
136 {
137 name: "Test",
138 geo_zones: [{ type: "country", country_code: "us" }],
139 },
140 adminHeaders
141 )
142 ).data.fulfillment_set
143
144 await api.post(
145 `/admin/stock-locations/${stockLocation.id}/fulfillment-providers`,
146 { add: ["manual_test-provider"] },
147 adminHeaders
148 )
149
150 shippingOption = (
151 await api.post(
152 `/admin/shipping-options`,
153 {
154 name: "Test shipping option",
155 service_zone_id: fulfillmentSet.service_zones[0].id,
156 shipping_profile_id: shippingProfile.id,
157 provider_id: "manual_test-provider",
158 price_type: "flat",
159 type: {
160 label: "Test type",
161 description: "Test description",
162 code: "test-code",
163 },
164 prices: [{ currency_code: "usd", amount: 1000 }],
165 rules: [],
166 },
167 adminHeaders
168 )
169 ).data.shipping_option
170
171 const taxRatesResponse = await api.get(
172 `/admin/tax-rates?tax_region_id=${taxStructure.us.children.cal.province.id}`,
173 adminHeaders
174 )
175 taxRate = taxRatesResponse.data.tax_rates.find(
176 (rate: { code: string }) => rate.code === "CADEFAULT"
177 )
178
179 await api.post(
180 "/admin/translations/batch",
181 {
182 create: [
183 {
184 reference_id: product.id,
185 reference: "product",
186 locale_code: "fr-FR",
187 translations: {
188 title: "T-Shirt Medusa",
189 description: "Un t-shirt en coton confortable",
190 },
191 },
192 {
193 reference_id: product.id,
194 reference: "product",
195 locale_code: "de-DE",
196 translations: {
197 title: "Medusa T-Shirt DE",
198 description: "Ein bequemes Baumwoll-T-Shirt",
199 },
200 },
201 {
202 reference_id: product.variants[0].id,
203 reference: "product_variant",
204 locale_code: "fr-FR",
205 translations: { title: "Petit" },
206 },
207 {
208 reference_id: product.variants[0].id,
209 reference: "product_variant",
210 locale_code: "de-DE",
211 translations: { title: "Klein" },
212 },
213 {
214 reference_id: product.variants[1].id,
215 reference: "product_variant",
216 locale_code: "fr-FR",
217 translations: { title: "Moyen" },
218 },
219 {
220 reference_id: product.variants[1].id,
221 reference: "product_variant",
222 locale_code: "de-DE",
223 translations: { title: "Mittel" },
224 },
225 {
226 reference_id: shippingOption.id,
227 reference: "shipping_option",
228 locale_code: "fr-FR",
229 translations: {
230 name: "Option d'expédition de test",
231 },
232 },
233 {
234 reference_id: shippingOption.id,
235 reference: "shipping_option",
236 locale_code: "de-DE",
237 translations: {
238 name: "Test-Versandoption",
239 },
240 },
241 {
242 reference_id: taxRate.id,
243 reference: "tax_rate",
244 locale_code: "fr-FR",
245 translations: {
246 name: "Taux par défaut CA",
247 },
248 },
249 {
250 reference_id: taxRate.id,
251 reference: "tax_rate",
252 locale_code: "de-DE",
253 translations: {
254 name: "CA Standardsteuersatz",
255 },
256 },
257 ],
258 },
259 adminHeaders
260 )
261
262 await dbUtils.snapshot()
263 })
264
265 describe("POST /admin/draft-orders (create draft order with items)", () => {
266 it("should translate items when creating a draft order with items and locale", async () => {
267 const created = (
268 await api.post(
269 "/admin/draft-orders",
270 {
271 email: "test@test.com",
272 region_id: region.id,
273 sales_channel_id: salesChannel.id,
274 locale: "fr-FR",
275 items: [{ variant_id: product.variants[0].id, quantity: 1 }],
276 shipping_address: {
277 address_1: "123 Main St",
278 city: "Anytown",
279 country_code: "us",
280 province: "ca",
281 postal_code: "12345",
282 first_name: "John",
283 },
284 },
285 adminHeaders
286 )
287 ).data.draft_order
288
289 const draftOrder = (
290 await api.get(`/admin/draft-orders/${created.id}`, adminHeaders)
291 ).data.draft_order
292
293 expect(draftOrder.items[0]).toEqual(
294 expect.objectContaining({
295 product_title: "T-Shirt Medusa",
296 product_description: "Un t-shirt en coton confortable",
297 variant_title: "Petit",
298 })
299 )
300 })
301 })
302
303 describe("POST /admin/draft-orders/:id/edit/items (add items to draft order)", () => {
304 it("should translate items when adding to draft order with locale", async () => {
305 const draftOrder = (
306 await api.post(
307 "/admin/draft-orders",
308 {
309 email: "test@test.com",
310 region_id: region.id,
311 sales_channel_id: salesChannel.id,
312 locale: "fr-FR",
313 shipping_address: {
314 address_1: "123 Main St",
315 city: "Anytown",
316 country_code: "us",
317 province: "ca",
318 postal_code: "12345",
319 first_name: "John",
320 },
321 },
322 adminHeaders
323 )
324 ).data.draft_order
325
326 await api.post(
327 `/admin/draft-orders/${draftOrder.id}/edit`,
328 {},
329 adminHeaders
330 )
331
332 await api.post(
333 `/admin/draft-orders/${draftOrder.id}/edit/items`,
334 {
335 items: [{ variant_id: product.variants[0].id, quantity: 1 }],
336 },
337 adminHeaders
338 )
339
340 await api.post(
341 `/admin/draft-orders/${draftOrder.id}/edit/confirm`,
342 {},
343 adminHeaders
344 )
345
346 const updatedDraftOrder = (
347 await api.get(`/admin/draft-orders/${draftOrder.id}`, adminHeaders)
348 ).data.draft_order
349
350 expect(updatedDraftOrder.items[0]).toEqual(
351 expect.objectContaining({
352 product_title: "T-Shirt Medusa",
353 product_description: "Un t-shirt en coton confortable",
354 variant_title: "Petit",
355 })
356 )
357
358 expect(updatedDraftOrder.items[0].tax_lines.length).toBeGreaterThan(0)
359 const taxLine = updatedDraftOrder.items[0].tax_lines.find(
360 (tl) => tl.code === "CADEFAULT"
361 )
362 expect(taxLine.description).toEqual("Taux par défaut CA")
363 })
364
365 it("should have original values when draft order has no locale", async () => {
366 const draftOrder = (
367 await api.post(
368 "/admin/draft-orders",
369 {
370 email: "test@test.com",
371 region_id: region.id,
372 sales_channel_id: salesChannel.id,
373 shipping_address: {
374 address_1: "123 Main St",
375 city: "Anytown",
376 country_code: "us",
377 province: "ca",
378 postal_code: "12345",
379 first_name: "John",
380 },
381 },
382 adminHeaders
383 )
384 ).data.draft_order
385
386 await api.post(
387 `/admin/draft-orders/${draftOrder.id}/edit`,
388 {},
389 adminHeaders
390 )
391
392 await api.post(
393 `/admin/draft-orders/${draftOrder.id}/edit/items`,
394 {
395 items: [{ variant_id: product.variants[0].id, quantity: 1 }],
396 },
397 adminHeaders
398 )
399
400 await api.post(
401 `/admin/draft-orders/${draftOrder.id}/edit/confirm`,
402 {},
403 adminHeaders
404 )
405
406 const updatedDraftOrder = (
407 await api.get(`/admin/draft-orders/${draftOrder.id}`, adminHeaders)
408 ).data.draft_order
409
410 expect(updatedDraftOrder.items[0]).toEqual(
411 expect.objectContaining({
412 product_title: "Medusa T-Shirt",
413 product_description: "A comfortable cotton t-shirt",
414 variant_title: "Small",
415 })
416 )
417
418 expect(updatedDraftOrder.items[0].tax_lines.length).toBeGreaterThan(0)
419 const taxLine = updatedDraftOrder.items[0].tax_lines.find(
420 (tl) => tl.code === "CADEFAULT"
421 )
422 expect(taxLine.description).toEqual("CA Default Rate")
423 })
424
425 it("should translate multiple items added to draft order", async () => {
426 const draftOrder = (
427 await api.post(
428 "/admin/draft-orders",
429 {
430 email: "test@test.com",
431 region_id: region.id,
432 sales_channel_id: salesChannel.id,
433 locale: "de-DE",
434 shipping_address: {
435 address_1: "123 Main St",
436 city: "Anytown",
437 country_code: "us",
438 province: "ca",
439 postal_code: "12345",
440 first_name: "John",
441 },
442 },
443 adminHeaders
444 )
445 ).data.draft_order
446
447 await api.post(
448 `/admin/draft-orders/${draftOrder.id}/edit`,
449 {},
450 adminHeaders
451 )
452
453 await api.post(
454 `/admin/draft-orders/${draftOrder.id}/edit/items`,
455 {
456 items: [
457 { variant_id: product.variants[0].id, quantity: 1 },
458 { variant_id: product.variants[1].id, quantity: 2 },
459 ],
460 },
461 adminHeaders
462 )
463
464 await api.post(
465 `/admin/draft-orders/${draftOrder.id}/edit/confirm`,
466 {},
467 adminHeaders
468 )
469
470 const updatedDraftOrder = (
471 await api.get(`/admin/draft-orders/${draftOrder.id}`, adminHeaders)
472 ).data.draft_order
473
474 expect(updatedDraftOrder.items).toHaveLength(2)
475
476 const smallItem = updatedDraftOrder.items.find(
477 (item) => item.variant_id === product.variants[0].id
478 )
479 const mediumItem = updatedDraftOrder.items.find(
480 (item) => item.variant_id === product.variants[1].id
481 )
482
483 expect(smallItem).toEqual(
484 expect.objectContaining({
485 product_title: "Medusa T-Shirt DE",
486 variant_title: "Klein",
487 })
488 )
489 expect(mediumItem).toEqual(
490 expect.objectContaining({
491 product_title: "Medusa T-Shirt DE",
492 variant_title: "Mittel",
493 })
494 )
495
496 expect(smallItem.tax_lines.length).toBeGreaterThan(0)
497 const smallTaxLine = smallItem.tax_lines.find(
498 (tl) => tl.code === "CADEFAULT"
499 )
500 expect(smallTaxLine.description).toEqual("CA Standardsteuersatz")
501
502 expect(mediumItem.tax_lines.length).toBeGreaterThan(0)
503 const mediumTaxLine = mediumItem.tax_lines.find(
504 (tl) => tl.code === "CADEFAULT"
505 )
506 expect(mediumTaxLine.description).toEqual("CA Standardsteuersatz")
507 })
508 })
509
510 describe("POST /admin/draft-orders/:id/edit/shipping-methods (add shipping method to draft order)", () => {
511 it("should translate shipping method tax lines when adding to draft order with locale", async () => {
512 const draftOrder = (
513 await api.post(
514 "/admin/draft-orders",
515 {
516 email: "test@test.com",
517 region_id: region.id,
518 sales_channel_id: salesChannel.id,
519 locale: "fr-FR",
520 shipping_address: {
521 address_1: "123 Main St",
522 city: "Anytown",
523 country_code: "us",
524 province: "ca",
525 postal_code: "12345",
526 first_name: "John",
527 },
528 },
529 adminHeaders
530 )
531 ).data.draft_order
532
533 await api.post(
534 `/admin/draft-orders/${draftOrder.id}/edit`,
535 {},
536 adminHeaders
537 )
538
539 await api.post(
540 `/admin/draft-orders/${draftOrder.id}/edit/items`,
541 {
542 items: [{ variant_id: product.variants[0].id, quantity: 1 }],
543 },
544 adminHeaders
545 )
546
547 await api.post(
548 `/admin/draft-orders/${draftOrder.id}/edit/shipping-methods`,
549 {
550 shipping_option_id: shippingOption.id,
551 },
552 adminHeaders
553 )
554
555 await api.post(
556 `/admin/draft-orders/${draftOrder.id}/edit/confirm`,
557 {},
558 adminHeaders
559 )
560
561 const updatedDraftOrder = (
562 await api.get(`/admin/draft-orders/${draftOrder.id}`, adminHeaders)
563 ).data.draft_order
564
565 expect(updatedDraftOrder.shipping_methods.length).toBeGreaterThan(0)
566
567 const shippingMethod = updatedDraftOrder.shipping_methods[0]
568 const taxLine = shippingMethod.tax_lines.find(
569 (tl) => tl.code === "CADEFAULT"
570 )
571 expect(taxLine.description).toEqual("Taux par défaut CA")
572 })
573
574 it("should use original tax line description when draft order has no locale", async () => {
575 const draftOrder = (
576 await api.post(
577 "/admin/draft-orders",
578 {
579 email: "test@test.com",
580 region_id: region.id,
581 sales_channel_id: salesChannel.id,
582 shipping_address: {
583 address_1: "123 Main St",
584 city: "Anytown",
585 country_code: "us",
586 province: "ca",
587 postal_code: "12345",
588 first_name: "John",
589 },
590 },
591 adminHeaders
592 )
593 ).data.draft_order
594
595 await api.post(
596 `/admin/draft-orders/${draftOrder.id}/edit`,
597 {},
598 adminHeaders
599 )
600
601 await api.post(
602 `/admin/draft-orders/${draftOrder.id}/edit/items`,
603 {
604 items: [{ variant_id: product.variants[0].id, quantity: 1 }],
605 },
606 adminHeaders
607 )
608
609 await api.post(
610 `/admin/draft-orders/${draftOrder.id}/edit/shipping-methods`,
611 {
612 shipping_option_id: shippingOption.id,
613 },
614 adminHeaders
615 )
616
617 await api.post(
618 `/admin/draft-orders/${draftOrder.id}/edit/confirm`,
619 {},
620 adminHeaders
621 )
622
623 const updatedDraftOrder = (
624 await api.get(`/admin/draft-orders/${draftOrder.id}`, adminHeaders)
625 ).data.draft_order
626
627 expect(updatedDraftOrder.shipping_methods.length).toBeGreaterThan(0)
628
629 const shippingMethod = updatedDraftOrder.shipping_methods[0]
630 const taxLine = shippingMethod.tax_lines.find(
631 (tl) => tl.code === "CADEFAULT"
632 )
633 expect(taxLine).toBeDefined()
634 expect(taxLine.description).toEqual("CA Default Rate")
635 })
636 })
637
638 describe("POST /admin/draft-orders/:id (update draft order locale)", () => {
639 it("should re-translate all items when locale is updated", async () => {
640 const draftOrder = (
641 await api.post(
642 "/admin/draft-orders",
643 {
644 email: "test@test.com",
645 region_id: region.id,
646 sales_channel_id: salesChannel.id,
647 locale: "fr-FR",
648 shipping_address: {
649 address_1: "123 Main St",
650 city: "Anytown",
651 country_code: "us",
652 province: "ca",
653 postal_code: "12345",
654 first_name: "John",
655 },
656 },
657 adminHeaders
658 )
659 ).data.draft_order
660
661 await api.post(
662 `/admin/draft-orders/${draftOrder.id}/edit`,
663 {},
664 adminHeaders
665 )
666
667 await api.post(
668 `/admin/draft-orders/${draftOrder.id}/edit/items`,
669 {
670 items: [
671 { variant_id: product.variants[0].id, quantity: 1 },
672 { variant_id: product.variants[1].id, quantity: 1 },
673 ],
674 },
675 adminHeaders
676 )
677
678 await api.post(
679 `/admin/draft-orders/${draftOrder.id}/edit/shipping-methods`,
680 {
681 shipping_option_id: shippingOption.id,
682 },
683 adminHeaders
684 )
685
686 await api.post(
687 `/admin/draft-orders/${draftOrder.id}/edit/confirm`,
688 {},
689 adminHeaders
690 )
691
692 let updatedDraftOrder = (
693 await api.get(`/admin/draft-orders/${draftOrder.id}`, adminHeaders)
694 ).data.draft_order
695
696 const frenchSmallItem = updatedDraftOrder.items.find(
697 (item) => item.variant_id === product.variants[0].id
698 )
699 expect(frenchSmallItem.variant_title).toEqual("Petit")
700
701 expect(frenchSmallItem.tax_lines.length).toBeGreaterThan(0)
702 const frenchTaxLine = frenchSmallItem.tax_lines.find(
703 (tl) => tl.code === "CADEFAULT"
704 )
705 expect(frenchTaxLine.description).toEqual("Taux par défaut CA")
706
707 await api.post(
708 `/admin/draft-orders/${draftOrder.id}`,
709 { locale: "de-DE" },
710 adminHeaders
711 )
712
713 updatedDraftOrder = (
714 await api.get(`/admin/draft-orders/${draftOrder.id}`, adminHeaders)
715 ).data.draft_order
716
717 const germanSmallItem = updatedDraftOrder.items.find(
718 (item) => item.variant_id === product.variants[0].id
719 )
720 const germanMediumItem = updatedDraftOrder.items.find(
721 (item) => item.variant_id === product.variants[1].id
722 )
723
724 expect(germanSmallItem).toEqual(
725 expect.objectContaining({
726 product_title: "Medusa T-Shirt DE",
727 product_description: "Ein bequemes Baumwoll-T-Shirt",
728 variant_title: "Klein",
729 })
730 )
731 expect(germanMediumItem).toEqual(
732 expect.objectContaining({
733 product_title: "Medusa T-Shirt DE",
734 variant_title: "Mittel",
735 })
736 )
737
738 expect(germanSmallItem.tax_lines.length).toBeGreaterThan(0)
739 const germanSmallTaxLine = germanSmallItem.tax_lines.find(
740 (tl) => tl.code === "CADEFAULT"
741 )
742 expect(germanSmallTaxLine.description).toEqual(
743 "CA Standardsteuersatz"
744 )
745
746 expect(germanMediumItem.tax_lines.length).toBeGreaterThan(0)
747 const germanMediumTaxLine = germanMediumItem.tax_lines.find(
748 (tl) => tl.code === "CADEFAULT"
749 )
750 expect(germanMediumTaxLine.description).toEqual(
751 "CA Standardsteuersatz"
752 )
753
754 expect(updatedDraftOrder.shipping_methods.length).toBeGreaterThan(0)
755
756 const shippingMethod = updatedDraftOrder.shipping_methods[0]
757 const shippingTaxLine = shippingMethod.tax_lines.find(
758 (tl) => tl.code === "CADEFAULT"
759 )
760 expect(shippingTaxLine).toBeDefined()
761 expect(shippingTaxLine.description).toEqual("CA Standardsteuersatz")
762 })
763 })
764
765 describe("POST /admin/draft-orders/:id/edit/shipping-methods (add shipping method to draft order)", () => {
766 it("should translate shipping method added to draft order using draft order locale", async () => {
767 const draftOrder = (
768 await api.post(
769 "/admin/draft-orders",
770 {
771 email: "test@test.com",
772 region_id: region.id,
773 sales_channel_id: salesChannel.id,
774 locale: "fr-FR",
775 shipping_address: {
776 address_1: "123 Main St",
777 city: "Anytown",
778 country_code: "us",
779 postal_code: "12345",
780 first_name: "John",
781 },
782 },
783 adminHeaders
784 )
785 ).data.draft_order
786
787 await api.post(
788 `/admin/draft-orders/${draftOrder.id}/edit`,
789 {},
790 adminHeaders
791 )
792
793 const previewResponse = await api.post(
794 `/admin/draft-orders/${draftOrder.id}/edit/shipping-methods`,
795 { shipping_option_id: shippingOption.id },
796 adminHeaders
797 )
798
799 expect(
800 previewResponse.data.draft_order_preview.shipping_methods
801 ).toEqual(
802 expect.arrayContaining([
803 expect.objectContaining({
804 shipping_option_id: shippingOption.id,
805 name: "Option d'expédition de test",
806 }),
807 ])
808 )
809
810 await api.post(
811 `/admin/draft-orders/${draftOrder.id}/edit/confirm`,
812 {},
813 adminHeaders
814 )
815
816 const updatedDraftOrder = (
817 await api.get(`/admin/draft-orders/${draftOrder.id}`, adminHeaders)
818 ).data.draft_order
819
820 expect(updatedDraftOrder.shipping_methods).toEqual(
821 expect.arrayContaining([
822 expect.objectContaining({
823 shipping_option_id: shippingOption.id,
824 name: "Option d'expédition de test",
825 }),
826 ])
827 )
828 })
829
830 it("should have original shipping method name when draft order has no locale", async () => {
831 const draftOrder = (
832 await api.post(
833 "/admin/draft-orders",
834 {
835 email: "test@test.com",
836 region_id: region.id,
837 sales_channel_id: salesChannel.id,
838 shipping_address: {
839 address_1: "123 Main St",
840 city: "Anytown",
841 country_code: "us",
842 postal_code: "12345",
843 first_name: "John",
844 },
845 },
846 adminHeaders
847 )
848 ).data.draft_order
849
850 await api.post(
851 `/admin/draft-orders/${draftOrder.id}/edit`,
852 {},
853 adminHeaders
854 )
855
856 const previewResponse = await api.post(
857 `/admin/draft-orders/${draftOrder.id}/edit/shipping-methods`,
858 { shipping_option_id: shippingOption.id },
859 adminHeaders
860 )
861
862 expect(
863 previewResponse.data.draft_order_preview.shipping_methods
864 ).toEqual(
865 expect.arrayContaining([
866 expect.objectContaining({
867 shipping_option_id: shippingOption.id,
868 name: "Test shipping option",
869 }),
870 ])
871 )
872
873 await api.post(
874 `/admin/draft-orders/${draftOrder.id}/edit/confirm`,
875 {},
876 adminHeaders
877 )
878
879 const updatedDraftOrder = (
880 await api.get(`/admin/draft-orders/${draftOrder.id}`, adminHeaders)
881 ).data.draft_order
882
883 expect(updatedDraftOrder.shipping_methods).toEqual(
884 expect.arrayContaining([
885 expect.objectContaining({
886 shipping_option_id: shippingOption.id,
887 name: "Test shipping option",
888 }),
889 ])
890 )
891 })
892 })
893
894 describe("POST /admin/draft-orders/:id (update draft order locale)", () => {
895 it("should re-translate shipping methods when locale is updated", async () => {
896 const draftOrder = (
897 await api.post(
898 "/admin/draft-orders",
899 {
900 email: "test@test.com",
901 region_id: region.id,
902 sales_channel_id: salesChannel.id,
903 locale: "fr-FR",
904 shipping_address: {
905 address_1: "123 Main St",
906 city: "Anytown",
907 country_code: "us",
908 postal_code: "12345",
909 first_name: "John",
910 },
911 },
912 adminHeaders
913 )
914 ).data.draft_order
915
916 await api.post(
917 `/admin/draft-orders/${draftOrder.id}/edit`,
918 {},
919 adminHeaders
920 )
921
922 await api.post(
923 `/admin/draft-orders/${draftOrder.id}/edit/shipping-methods`,
924 { shipping_option_id: shippingOption.id },
925 adminHeaders
926 )
927
928 await api.post(
929 `/admin/draft-orders/${draftOrder.id}/edit/confirm`,
930 {},
931 adminHeaders
932 )
933
934 let updatedDraftOrder = (
935 await api.get(`/admin/draft-orders/${draftOrder.id}`, adminHeaders)
936 ).data.draft_order
937
938 expect(updatedDraftOrder.shipping_methods[0].name).toEqual(
939 "Option d'expédition de test"
940 )
941
942 await api.post(
943 `/admin/draft-orders/${draftOrder.id}`,
944 { locale: "de-DE" },
945 adminHeaders
946 )
947
948 updatedDraftOrder = (
949 await api.get(`/admin/draft-orders/${draftOrder.id}`, adminHeaders)
950 ).data.draft_order
951
952 expect(updatedDraftOrder.shipping_methods[0]).toEqual(
953 expect.objectContaining({
954 shipping_option_id: shippingOption.id,
955 name: "Test-Versandoption",
956 })
957 )
958 })
959 })
960 })
961 },
962 })