@@ -45,7 +45,6 @@ def setup
45
45
context "#fulfillments" do
46
46
should "be able to list fulfillments for a fulfillment order" do
47
47
fulfillment_order = ShopifyAPI ::FulfillmentOrder . find ( 519788021 )
48
-
49
48
fake "fulfillment_orders/#{ fulfillment_order . id } /fulfillments" , method : :get ,
50
49
body : load_fixture ( 'fulfillments' )
51
50
@@ -57,5 +56,91 @@ def setup
57
56
assert_equal 450789469 , fulfillment . order_id
58
57
end
59
58
end
59
+
60
+ context "#move" do
61
+ should "move a fulfillment order to a new_location_id" do
62
+ fulfillment_order = ShopifyAPI ::FulfillmentOrder . find ( 519788021 )
63
+ new_location_id = 5
64
+
65
+ fake_original_fulfillment_order = fulfillment_order . clone
66
+ fake_original_fulfillment_order . status = 'closed'
67
+ fake_moved_fulfillment_order = ActiveSupport ::JSON . decode ( load_fixture ( 'fulfillment_order' ) )
68
+ fake_moved_fulfillment_order [ 'assigned_location_id' ] = new_location_id
69
+
70
+ request_body = { fulfillment_order : { new_location_id : 5 } }
71
+ body = {
72
+ original_fulfillment_order : fake_original_fulfillment_order ,
73
+ moved_fulfillment_order : fake_moved_fulfillment_order ,
74
+ remaining_fulfillment_order : nil ,
75
+ }
76
+ fake "fulfillment_orders/519788021/move" , :method => :post ,
77
+ :request_body => ActiveSupport ::JSON . encode ( request_body ) ,
78
+ :body => ActiveSupport ::JSON . encode ( body )
79
+
80
+ response_fulfillment_orders = fulfillment_order . move ( new_location_id : new_location_id )
81
+
82
+ assert_equal 'closed' , fulfillment_order . status
83
+
84
+ assert_equal 3 , response_fulfillment_orders . count
85
+ original_fulfillment_order = response_fulfillment_orders [ 'original_fulfillment_order' ]
86
+ refute_nil original_fulfillment_order
87
+ assert original_fulfillment_order . is_a? ( ShopifyAPI ::FulfillmentOrder )
88
+ assert_equal 'closed' , original_fulfillment_order . status
89
+
90
+ moved_fulfillment_order = response_fulfillment_orders [ 'moved_fulfillment_order' ]
91
+ refute_nil moved_fulfillment_order
92
+ assert moved_fulfillment_order . is_a? ( ShopifyAPI ::FulfillmentOrder )
93
+ assert_equal 'open' , moved_fulfillment_order . status
94
+ assert_equal new_location_id , moved_fulfillment_order . assigned_location_id
95
+
96
+ remaining_fulfillment_order = response_fulfillment_orders [ 'remaining_fulfillment_order' ]
97
+ assert_nil remaining_fulfillment_order
98
+ end
99
+ end
100
+
101
+ context "#cancel" do
102
+ should "cancel a fulfillment order" do
103
+ fulfillment_order = ShopifyAPI ::FulfillmentOrder . find ( 519788021 )
104
+ assert_equal 'open' , fulfillment_order . status
105
+
106
+ cancelled = ActiveSupport ::JSON . decode ( load_fixture ( 'fulfillment_order' ) )
107
+ cancelled [ 'status' ] = 'cancelled'
108
+ body = {
109
+ fulfillment_order : cancelled ,
110
+ replacement_fulfillment_order : fulfillment_order ,
111
+ }
112
+ fake "fulfillment_orders/519788021/cancel" , :method => :post , :body => ActiveSupport ::JSON . encode ( body )
113
+
114
+ response_fulfillment_orders = fulfillment_order . cancel
115
+
116
+ assert_equal 'cancelled' , fulfillment_order . status
117
+ assert_equal 2 , response_fulfillment_orders . count
118
+ fulfillment_order = response_fulfillment_orders [ 'fulfillment_order' ]
119
+ assert_equal 'cancelled' , fulfillment_order . status
120
+ replacement_fulfillment_order = response_fulfillment_orders [ 'replacement_fulfillment_order' ]
121
+ assert_equal 'open' , replacement_fulfillment_order . status
122
+ end
123
+ end
124
+
125
+ context "#close" do
126
+ should "be able to close fulfillment order" do
127
+ fulfillment_order = ShopifyAPI ::FulfillmentOrder . find ( 519788021 )
128
+ fulfillment_order . status = 'in_progress'
129
+
130
+ closed = ActiveSupport ::JSON . decode ( load_fixture ( 'fulfillment_order' ) )
131
+ closed [ 'status' ] = 'incomplete'
132
+ request_body = {
133
+ fulfillment_order : {
134
+ message : "Test close message."
135
+ }
136
+ }
137
+ fake "fulfillment_orders/519788021/close" , :method => :post ,
138
+ :request_body => ActiveSupport ::JSON . encode ( request_body ) ,
139
+ :body => ActiveSupport ::JSON . encode ( closed )
140
+
141
+ assert fulfillment_order . close ( message : "Test close message." )
142
+ assert_equal 'incomplete' , fulfillment_order . status
143
+ end
144
+ end
60
145
end
61
146
end
0 commit comments