@@ -16,6 +16,7 @@ medusaIntegrationTestRunner({
16
16
let stockLocation : HttpTypes . AdminStockLocation
17
17
let testDraftOrder : HttpTypes . AdminDraftOrder
18
18
let shippingOption : HttpTypes . AdminShippingOption
19
+ let shippingOptionHeavy : HttpTypes . AdminShippingOption
19
20
20
21
beforeEach ( async ( ) => {
21
22
const container = getContainer ( )
@@ -55,6 +56,14 @@ medusaIntegrationTestRunner({
55
56
)
56
57
) . data . shipping_profile
57
58
59
+ const shippingProfileHeavy = (
60
+ await api . post (
61
+ `/admin/shipping-profiles` ,
62
+ { name : "test shipping profile heavy" , type : "heavy" } ,
63
+ adminHeaders
64
+ )
65
+ ) . data . shipping_profile
66
+
58
67
const fulfillmentSets = (
59
68
await api . post (
60
69
`/admin/stock-locations/${ stockLocation . id } /fulfillment-sets?fields=*fulfillment_sets` ,
@@ -103,7 +112,28 @@ medusaIntegrationTestRunner({
103
112
description : "Test description" ,
104
113
code : "test-code" ,
105
114
} ,
106
- prices : [ { currency_code : "usd" , amount : 1000 } ] ,
115
+ prices : [ { currency_code : "usd" , amount : 5 } ] ,
116
+ rules : [ ] ,
117
+ } ,
118
+ adminHeaders
119
+ )
120
+ ) . data . shipping_option
121
+
122
+ shippingOptionHeavy = (
123
+ await api . post (
124
+ `/admin/shipping-options` ,
125
+ {
126
+ name : `Test shipping option ${ fulfillmentSet . id } ` ,
127
+ service_zone_id : fulfillmentSet . service_zones [ 0 ] . id ,
128
+ shipping_profile_id : shippingProfileHeavy . id ,
129
+ provider_id : "manual_test-provider" ,
130
+ price_type : "flat" ,
131
+ type : {
132
+ label : "Test type" ,
133
+ description : "Test description" ,
134
+ code : "test-code" ,
135
+ } ,
136
+ prices : [ { currency_code : "usd" , amount : 10 } ] ,
107
137
rules : [ ] ,
108
138
} ,
109
139
adminHeaders
@@ -117,6 +147,13 @@ medusaIntegrationTestRunner({
117
147
118
148
region_id : region . id ,
119
149
sales_channel_id : salesChannel . id ,
150
+ shipping_address : {
151
+ address_1 : "123 Main St" ,
152
+ city : "Anytown" ,
153
+ country_code : "US" ,
154
+ postal_code : "12345" ,
155
+ first_name : "John" ,
156
+ } ,
120
157
} ,
121
158
adminHeaders
122
159
)
@@ -610,6 +647,152 @@ medusaIntegrationTestRunner({
610
647
611
648
expect ( order . shipping_methods . length ) . toBe ( 0 )
612
649
} )
650
+
651
+ it ( "should ensure that the shipping method is removed from the order and tax lines are updated with multiple shipping methods" , async ( ) => {
652
+ /**
653
+ * Add Heavy SO
654
+ */
655
+
656
+ edit = (
657
+ await api . post (
658
+ `/admin/draft-orders/${ testDraftOrder . id } /edit` ,
659
+ { } ,
660
+ adminHeaders
661
+ )
662
+ ) . data . draft_order_preview
663
+
664
+ await api . post (
665
+ `/admin/draft-orders/${ testDraftOrder . id } /edit/shipping-methods` ,
666
+ {
667
+ shipping_option_id : shippingOptionHeavy . id ,
668
+ } ,
669
+ adminHeaders
670
+ )
671
+
672
+ edit = (
673
+ await api . post (
674
+ `/admin/draft-orders/${ testDraftOrder . id } /edit/confirm` ,
675
+ { } ,
676
+ adminHeaders
677
+ )
678
+ ) . data . draft_order_preview
679
+
680
+ /**
681
+ * Tax rate -> 2%
682
+ *
683
+ * One product -> 10$
684
+ * Shipping method 1 -> 5$
685
+ * Shipping method 2 -> 10$
686
+ */
687
+
688
+ expect ( edit ) . toEqual (
689
+ expect . objectContaining ( {
690
+ total : 25.5 ,
691
+ subtotal : 25 ,
692
+ tax_total : 0.5 ,
693
+
694
+ items : [
695
+ expect . objectContaining ( {
696
+ subtotal : 10 ,
697
+ total : 10.2 ,
698
+ tax_total : 0.2 ,
699
+ tax_lines : [
700
+ expect . objectContaining ( {
701
+ rate : 2 ,
702
+ } ) ,
703
+ ] ,
704
+ } ) ,
705
+ ] ,
706
+ shipping_methods : expect . arrayContaining ( [
707
+ expect . objectContaining ( {
708
+ shipping_option_id : shippingOption . id ,
709
+ amount : 5 ,
710
+ subtotal : 5 ,
711
+ total : 5.1 ,
712
+ tax_total : 0.1 ,
713
+ } ) ,
714
+ expect . objectContaining ( {
715
+ shipping_option_id : shippingOptionHeavy . id ,
716
+ amount : 10 ,
717
+ subtotal : 10 ,
718
+ total : 10.2 ,
719
+ tax_total : 0.2 ,
720
+ } ) ,
721
+ ] ) ,
722
+ } )
723
+ )
724
+
725
+ /**
726
+ * Remove Heavy shipping method
727
+ */
728
+
729
+ edit = (
730
+ await api . post (
731
+ `/admin/draft-orders/${ testDraftOrder . id } /edit` ,
732
+ { } ,
733
+ adminHeaders
734
+ )
735
+ ) . data . draft_order_preview
736
+
737
+ const response = await api . delete (
738
+ `/admin/draft-orders/${
739
+ testDraftOrder . id
740
+ } /edit/shipping-methods/method/${
741
+ edit . shipping_methods . find (
742
+ ( sm ) => sm . shipping_option_id === shippingOptionHeavy . id
743
+ ) . id
744
+ } `,
745
+ adminHeaders
746
+ )
747
+
748
+ expect ( response . status ) . toBe ( 200 )
749
+ expect ( response . data . draft_order_preview . shipping_methods . length ) . toBe (
750
+ 1
751
+ )
752
+
753
+ await api . post (
754
+ `/admin/draft-orders/${ testDraftOrder . id } /edit/confirm` ,
755
+ { } ,
756
+ adminHeaders
757
+ )
758
+
759
+ const order = (
760
+ await api . get (
761
+ `/admin/draft-orders/${ testDraftOrder . id } ?fields=+total,+subtotal,+tax_total,+items.subtotal,+items.total,+items.tax_total,+shipping_methods.amount,+shipping_methods.subtotal,+shipping_methods.total,+shipping_methods.tax_total` ,
762
+ adminHeaders
763
+ )
764
+ ) . data . draft_order
765
+
766
+ expect ( order ) . toEqual (
767
+ expect . objectContaining ( {
768
+ total : 15.3 ,
769
+ subtotal : 15 ,
770
+ tax_total : 0.3 ,
771
+
772
+ items : [
773
+ expect . objectContaining ( {
774
+ subtotal : 10 ,
775
+ total : 10.2 ,
776
+ tax_total : 0.2 ,
777
+ tax_lines : [
778
+ expect . objectContaining ( {
779
+ rate : 2 ,
780
+ } ) ,
781
+ ] ,
782
+ } ) ,
783
+ ] ,
784
+ shipping_methods : expect . arrayContaining ( [
785
+ expect . objectContaining ( {
786
+ shipping_option_id : shippingOption . id ,
787
+ amount : 5 ,
788
+ subtotal : 5 ,
789
+ total : 5.1 ,
790
+ tax_total : 0.1 ,
791
+ } ) ,
792
+ ] ) ,
793
+ } )
794
+ )
795
+ } )
613
796
} )
614
797
} ,
615
798
} )
0 commit comments