shopify_api 8.1.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +22 -10
- data/docs/graphql.md +191 -0
- data/lib/shopify_api.rb +2 -0
- data/lib/shopify_api/api_version.rb +1 -1
- data/lib/shopify_api/graphql.rb +79 -0
- data/lib/shopify_api/graphql/http_client.rb +22 -0
- data/lib/shopify_api/graphql/railtie.rb +17 -0
- data/lib/shopify_api/graphql/task.rake +100 -0
- data/lib/shopify_api/resources/assigned_fulfillment_order.rb +16 -0
- data/lib/shopify_api/resources/base.rb +8 -0
- data/lib/shopify_api/resources/fulfillment.rb +34 -0
- data/lib/shopify_api/resources/fulfillment_order.rb +137 -0
- data/lib/shopify_api/resources/fulfillment_order_locations_for_move.rb +4 -0
- data/lib/shopify_api/resources/fulfillment_v2.rb +20 -0
- data/lib/shopify_api/resources/order.rb +7 -0
- data/lib/shopify_api/session.rb +3 -3
- data/lib/shopify_api/version.rb +1 -1
- data/test/assigned_fulfillment_order_test.rb +77 -0
- data/test/base_test.rb +14 -0
- data/test/fixtures/assigned_fulfillment_orders.json +78 -0
- data/test/fixtures/fulfillment_order.json +38 -0
- data/test/fixtures/fulfillment_order_locations_for_move.json +18 -0
- data/test/fixtures/fulfillment_orders.json +78 -0
- data/test/fixtures/fulfillments.json +53 -0
- data/test/fixtures/graphql/2019-10.json +1083 -0
- data/test/fixtures/graphql/dummy_schema.rb +16 -0
- data/test/fixtures/graphql/unstable.json +1083 -0
- data/test/fulfillment_order_test.rb +462 -0
- data/test/fulfillment_order_test_helper.rb +7 -0
- data/test/fulfillment_test.rb +164 -1
- data/test/fulfillment_v2_test.rb +62 -0
- data/test/graphql/http_client_test.rb +26 -0
- data/test/graphql_test.rb +147 -0
- data/test/order_test.rb +50 -0
- data/test/session_test.rb +26 -13
- data/test/test_helper.rb +4 -1
- metadata +25 -3
- data/lib/shopify_api/resources/graphql.rb +0 -22
@@ -0,0 +1,462 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'fulfillment_order_test_helper'
|
3
|
+
|
4
|
+
class FulFillmentOrderTest < Test::Unit::TestCase
|
5
|
+
include FulfillmentOrderTestHelper
|
6
|
+
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
@url_prefix = url_prefix_for_activated_session_for('2020-01')
|
10
|
+
|
11
|
+
fake 'fulfillment_orders',
|
12
|
+
url: "#{@url_prefix}/fulfillment_orders/519788021.json",
|
13
|
+
method: :get,
|
14
|
+
body: load_fixture('fulfillment_order')
|
15
|
+
end
|
16
|
+
|
17
|
+
context "FulfillmentOrder" do
|
18
|
+
context ".new" do
|
19
|
+
should "raise NotImplementedError when api_version is older than 2020-01" do
|
20
|
+
url_prefix_for_activated_session_for('2019-10')
|
21
|
+
fulfillment_order = load_fixture('fulfillment_order')
|
22
|
+
|
23
|
+
exception = assert_raises NotImplementedError do
|
24
|
+
ShopifyAPI::FulfillmentOrder.new(ActiveSupport::JSON.decode(fulfillment_order))
|
25
|
+
end
|
26
|
+
assert_equal(
|
27
|
+
"The minimum supported version is 2020-01.",
|
28
|
+
exception.message
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context ".find and .all" do
|
34
|
+
should "raise NotImplementedError when api_version is older than 2020-01" do
|
35
|
+
@url_prefix = url_prefix_for_activated_session_for('2019-10')
|
36
|
+
|
37
|
+
fake 'fulfillment_orders',
|
38
|
+
url: "#{@url_prefix}/fulfillment_orders/519788021.json",
|
39
|
+
method: :get,
|
40
|
+
body: load_fixture('fulfillment_order')
|
41
|
+
|
42
|
+
exception = assert_raises NotImplementedError do
|
43
|
+
ShopifyAPI::FulfillmentOrder.find(519788021)
|
44
|
+
end
|
45
|
+
assert_equal(
|
46
|
+
"The minimum supported version is 2020-01.",
|
47
|
+
exception.message
|
48
|
+
)
|
49
|
+
|
50
|
+
assert_raises NotImplementedError do
|
51
|
+
ShopifyAPI::FulfillmentOrder.all(params: { order_id: 450789469 })
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "#find" do
|
57
|
+
should "be able to find fulfillment order" do
|
58
|
+
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
59
|
+
assert fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder)
|
60
|
+
assert_equal 519788021, fulfillment_order.id
|
61
|
+
assert_equal 450789469, fulfillment_order.order_id
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "#all" do
|
66
|
+
should "be able to list fulfillment orders for an order" do
|
67
|
+
fake 'orders',
|
68
|
+
url: "#{@url_prefix}/orders/450789469/fulfillment_orders.json",
|
69
|
+
method: :get,
|
70
|
+
body: load_fixture('fulfillment_orders')
|
71
|
+
|
72
|
+
fulfillment_orders = ShopifyAPI::FulfillmentOrder.all(
|
73
|
+
params: { order_id: 450789469 }
|
74
|
+
)
|
75
|
+
|
76
|
+
assert_equal [519788021, 519788022], fulfillment_orders.map(&:id).sort
|
77
|
+
fulfillment_orders.each do |fulfillment_order|
|
78
|
+
assert fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder)
|
79
|
+
assert_equal 450789469, fulfillment_order.order_id
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
should "require order_id" do
|
84
|
+
assert_raises ShopifyAPI::ValidationException do
|
85
|
+
ShopifyAPI::FulfillmentOrder.all
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "#fulfillments" do
|
91
|
+
should "be able to list fulfillments for a fulfillment order" do
|
92
|
+
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
93
|
+
fake 'fulfillment_orders',
|
94
|
+
url: "#{@url_prefix}/fulfillment_orders/#{fulfillment_order.id}/fulfillments.json",
|
95
|
+
method: :get,
|
96
|
+
body: load_fixture('fulfillments')
|
97
|
+
|
98
|
+
fulfillments = fulfillment_order.fulfillments
|
99
|
+
|
100
|
+
assert_equal 1, fulfillments.count
|
101
|
+
fulfillment = fulfillments.first
|
102
|
+
assert fulfillment.is_a?(ShopifyAPI::Fulfillment)
|
103
|
+
assert_equal 450789469, fulfillment.order_id
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "#locations_for_move" do
|
108
|
+
should "be able to list locations for a fulfillment order" do
|
109
|
+
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
110
|
+
fake 'fulfillment_orders',
|
111
|
+
url: "#{@url_prefix}/fulfillment_orders/#{fulfillment_order.id}/locations_for_move.json",
|
112
|
+
method: :get,
|
113
|
+
body: load_fixture('fulfillment_order_locations_for_move')
|
114
|
+
|
115
|
+
locations_for_move = fulfillment_order.locations_for_move
|
116
|
+
|
117
|
+
assert_equal 2, locations_for_move.count
|
118
|
+
location_for_move = locations_for_move.first
|
119
|
+
assert location_for_move.is_a?(ShopifyAPI::FulfillmentOrderLocationsForMove)
|
120
|
+
|
121
|
+
location = location_for_move.location
|
122
|
+
assert location.is_a?(ShopifyAPI::Location)
|
123
|
+
assert_equal 1059367776,location.id
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "#move" do
|
128
|
+
should "move a fulfillment order to a new_location_id" do
|
129
|
+
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
130
|
+
new_location_id = 5
|
131
|
+
|
132
|
+
fake_original_fulfillment_order = fulfillment_order.clone
|
133
|
+
fake_original_fulfillment_order.status = 'closed'
|
134
|
+
fake_moved_fulfillment_order = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
|
135
|
+
fake_moved_fulfillment_order['assigned_location_id'] = new_location_id
|
136
|
+
|
137
|
+
request_body = { fulfillment_order: { new_location_id: 5 } }
|
138
|
+
body = {
|
139
|
+
original_fulfillment_order: fake_original_fulfillment_order,
|
140
|
+
moved_fulfillment_order: fake_moved_fulfillment_order,
|
141
|
+
remaining_fulfillment_order: nil,
|
142
|
+
}
|
143
|
+
fake 'fulfillment_orders',
|
144
|
+
url: "#{@url_prefix}/fulfillment_orders/519788021/move.json",
|
145
|
+
:method => :post,
|
146
|
+
:request_body => ActiveSupport::JSON.encode(request_body),
|
147
|
+
:body => ActiveSupport::JSON.encode(body)
|
148
|
+
|
149
|
+
response_fulfillment_orders = fulfillment_order.move(new_location_id: new_location_id)
|
150
|
+
|
151
|
+
assert_equal 'closed', fulfillment_order.status
|
152
|
+
|
153
|
+
assert_equal 3, response_fulfillment_orders.count
|
154
|
+
original_fulfillment_order = response_fulfillment_orders['original_fulfillment_order']
|
155
|
+
refute_nil original_fulfillment_order
|
156
|
+
assert original_fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder)
|
157
|
+
assert_equal 'closed', original_fulfillment_order.status
|
158
|
+
|
159
|
+
moved_fulfillment_order = response_fulfillment_orders['moved_fulfillment_order']
|
160
|
+
refute_nil moved_fulfillment_order
|
161
|
+
assert moved_fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder)
|
162
|
+
assert_equal 'open', moved_fulfillment_order.status
|
163
|
+
assert_equal new_location_id, moved_fulfillment_order.assigned_location_id
|
164
|
+
|
165
|
+
remaining_fulfillment_order = response_fulfillment_orders['remaining_fulfillment_order']
|
166
|
+
assert_nil remaining_fulfillment_order
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context "#cancel" do
|
171
|
+
should "cancel a fulfillment order" do
|
172
|
+
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
173
|
+
assert_equal 'open', fulfillment_order.status
|
174
|
+
|
175
|
+
cancelled = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
|
176
|
+
cancelled['status'] = 'cancelled'
|
177
|
+
body = {
|
178
|
+
fulfillment_order: cancelled,
|
179
|
+
replacement_fulfillment_order: fulfillment_order,
|
180
|
+
}
|
181
|
+
fake 'fulfillment_orders',
|
182
|
+
url: "#{@url_prefix}/fulfillment_orders/519788021/cancel.json",
|
183
|
+
:method => :post,
|
184
|
+
:body => ActiveSupport::JSON.encode(body)
|
185
|
+
|
186
|
+
response_fulfillment_orders = fulfillment_order.cancel
|
187
|
+
|
188
|
+
assert_equal 'cancelled', fulfillment_order.status
|
189
|
+
assert_equal 2, response_fulfillment_orders.count
|
190
|
+
fulfillment_order = response_fulfillment_orders['fulfillment_order']
|
191
|
+
assert_equal 'cancelled', fulfillment_order.status
|
192
|
+
replacement_fulfillment_order = response_fulfillment_orders['replacement_fulfillment_order']
|
193
|
+
assert_equal 'open', replacement_fulfillment_order.status
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context "#close" do
|
198
|
+
should "be able to close fulfillment order" do
|
199
|
+
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
200
|
+
fulfillment_order.status = 'in_progress'
|
201
|
+
|
202
|
+
closed = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
|
203
|
+
closed['status'] = 'incomplete'
|
204
|
+
request_body = {
|
205
|
+
fulfillment_order: {
|
206
|
+
message: "Test close message."
|
207
|
+
}
|
208
|
+
}
|
209
|
+
fake 'fulfillment_orders',
|
210
|
+
url: "#{@url_prefix}/fulfillment_orders/519788021/close.json",
|
211
|
+
:method => :post,
|
212
|
+
:request_body => ActiveSupport::JSON.encode(request_body),
|
213
|
+
:body => ActiveSupport::JSON.encode(closed)
|
214
|
+
|
215
|
+
assert fulfillment_order.close(message: "Test close message.")
|
216
|
+
assert_equal 'incomplete', fulfillment_order.status
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context "#request_fulfillment" do
|
221
|
+
should "make a fulfillment request for a fulfillment order including unsubmitted" do
|
222
|
+
fake_original_fulfillment_order = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
|
223
|
+
fake_original_fulfillment_order['status'] = 'closed'
|
224
|
+
fake_submitted_fulfillment_order = fake_original_fulfillment_order.clone
|
225
|
+
fake_submitted_fulfillment_order['id'] = 2
|
226
|
+
fake_submitted_fulfillment_order['status'] = 'open'
|
227
|
+
fake_submitted_fulfillment_order['request_status'] = 'submitted'
|
228
|
+
fake_unsubmitted_fulfillment_order = fake_original_fulfillment_order.clone
|
229
|
+
fake_unsubmitted_fulfillment_order['id'] = 3
|
230
|
+
fake_unsubmitted_fulfillment_order['status'] = 'open'
|
231
|
+
fake_unsubmitted_fulfillment_order['request_status'] = 'unsubmitted'
|
232
|
+
body = {
|
233
|
+
original_fulfillment_order: fake_original_fulfillment_order,
|
234
|
+
submitted_fulfillment_order: fake_submitted_fulfillment_order,
|
235
|
+
unsubmitted_fulfillment_order: fake_unsubmitted_fulfillment_order
|
236
|
+
}
|
237
|
+
request_body = {
|
238
|
+
fulfillment_request: {
|
239
|
+
fulfillment_order_line_items: [
|
240
|
+
{ id: 1, quantity: 1 }
|
241
|
+
],
|
242
|
+
message: 'Fulfill this FO, please.'
|
243
|
+
}
|
244
|
+
}
|
245
|
+
fake 'fulfillment_orders',
|
246
|
+
url: "#{@url_prefix}/fulfillment_orders/519788021/fulfillment_request.json",
|
247
|
+
:method => :post,
|
248
|
+
:request_body => ActiveSupport::JSON.encode(request_body),
|
249
|
+
:body => ActiveSupport::JSON.encode(body)
|
250
|
+
|
251
|
+
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
252
|
+
params = {
|
253
|
+
fulfillment_order_line_items: [{ id: 1, quantity: 1 }],
|
254
|
+
message: "Fulfill this FO, please."
|
255
|
+
}
|
256
|
+
response_fulfillment_orders = fulfillment_order.request_fulfillment(params)
|
257
|
+
|
258
|
+
assert_equal 'closed', fulfillment_order.status
|
259
|
+
assert_equal 3, response_fulfillment_orders.size
|
260
|
+
|
261
|
+
original_fulfillment_order = response_fulfillment_orders['original_fulfillment_order']
|
262
|
+
assert_equal 519788021, original_fulfillment_order.id
|
263
|
+
assert_equal 'closed', original_fulfillment_order.status
|
264
|
+
|
265
|
+
submitted_fulfillment_order = response_fulfillment_orders['submitted_fulfillment_order']
|
266
|
+
assert_equal 2, submitted_fulfillment_order.id
|
267
|
+
assert_equal 'open', submitted_fulfillment_order.status
|
268
|
+
assert_equal 'submitted', submitted_fulfillment_order.request_status
|
269
|
+
|
270
|
+
unsubmitted_fulfillment_order = response_fulfillment_orders['unsubmitted_fulfillment_order']
|
271
|
+
assert_equal 3, unsubmitted_fulfillment_order.id
|
272
|
+
assert_equal 'open', unsubmitted_fulfillment_order.status
|
273
|
+
assert_equal 'unsubmitted', unsubmitted_fulfillment_order.request_status
|
274
|
+
end
|
275
|
+
|
276
|
+
should "make a fulfillment request for a fulfillment order excluding unsubmitted" do
|
277
|
+
fake_original_fulfillment_order = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
|
278
|
+
fake_original_fulfillment_order['status'] = 'closed'
|
279
|
+
fake_submitted_fulfillment_order = fake_original_fulfillment_order.clone
|
280
|
+
fake_submitted_fulfillment_order['id'] = 2
|
281
|
+
fake_submitted_fulfillment_order['status'] = 'open'
|
282
|
+
fake_submitted_fulfillment_order['request_status'] = 'submitted'
|
283
|
+
body = {
|
284
|
+
original_fulfillment_order: fake_original_fulfillment_order,
|
285
|
+
submitted_fulfillment_order: fake_submitted_fulfillment_order,
|
286
|
+
unsubmitted_fulfillment_order: nil,
|
287
|
+
}
|
288
|
+
request_body = {
|
289
|
+
fulfillment_request: {
|
290
|
+
fulfillment_order_line_items: [
|
291
|
+
{ id: 1, quantity: 1 }
|
292
|
+
],
|
293
|
+
message: 'Fulfill this FO, please.'
|
294
|
+
}
|
295
|
+
}
|
296
|
+
fake 'fulfillment_orders',
|
297
|
+
url: "#{@url_prefix}/fulfillment_orders/519788021/fulfillment_request.json",
|
298
|
+
:method => :post,
|
299
|
+
:request_body => ActiveSupport::JSON.encode(request_body),
|
300
|
+
:body => ActiveSupport::JSON.encode(body)
|
301
|
+
|
302
|
+
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
303
|
+
params = {
|
304
|
+
fulfillment_order_line_items: [{ id: 1, quantity: 1 }],
|
305
|
+
message: "Fulfill this FO, please."
|
306
|
+
}
|
307
|
+
response_fulfillment_orders = fulfillment_order.request_fulfillment(params)
|
308
|
+
|
309
|
+
assert_equal 'closed', fulfillment_order.status
|
310
|
+
assert_equal 3, response_fulfillment_orders.size
|
311
|
+
|
312
|
+
original_fulfillment_order = response_fulfillment_orders['original_fulfillment_order']
|
313
|
+
assert_equal 519788021, original_fulfillment_order.id
|
314
|
+
assert_equal 'closed', original_fulfillment_order.status
|
315
|
+
|
316
|
+
submitted_fulfillment_order = response_fulfillment_orders['submitted_fulfillment_order']
|
317
|
+
assert_equal 2, submitted_fulfillment_order.id
|
318
|
+
assert_equal 'open', submitted_fulfillment_order.status
|
319
|
+
assert_equal 'submitted', submitted_fulfillment_order.request_status
|
320
|
+
|
321
|
+
assert_nil response_fulfillment_orders['unsubmitted_fulfillment_order']
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
context "#accept_fulfillment_request" do
|
326
|
+
should "accept a fulfillment request for a fulfillment order" do
|
327
|
+
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
328
|
+
|
329
|
+
message = "LGTM. Accept this FO fulfillment request"
|
330
|
+
request_body = {
|
331
|
+
'fulfillment_request' => {
|
332
|
+
'message' => message
|
333
|
+
}
|
334
|
+
}
|
335
|
+
fake_response = {
|
336
|
+
fulfillment_order: fulfillment_order.attributes.merge(status: 'in_progress', request_status: 'accepted')
|
337
|
+
}
|
338
|
+
fake 'fulfillment_orders',
|
339
|
+
url: "#{@url_prefix}/fulfillment_orders/519788021/fulfillment_request/accept.json",
|
340
|
+
:method => :post,
|
341
|
+
:request_body => ActiveSupport::JSON.encode(request_body),
|
342
|
+
:body => ActiveSupport::JSON.encode(fake_response)
|
343
|
+
|
344
|
+
accepted = fulfillment_order.accept_fulfillment_request(message: message)
|
345
|
+
|
346
|
+
assert_equal true, accepted
|
347
|
+
assert_equal 'in_progress', fulfillment_order.status
|
348
|
+
assert_equal 'accepted', fulfillment_order.request_status
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
context "#reject_fulfillment_request" do
|
353
|
+
should "reject a fulfillment request for a fulfillment order" do
|
354
|
+
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
355
|
+
|
356
|
+
message = "LBTM. Reject this FO fulfillment request"
|
357
|
+
request_body = {
|
358
|
+
'fulfillment_request' => {
|
359
|
+
'message' => message
|
360
|
+
}
|
361
|
+
}
|
362
|
+
fake_response = {
|
363
|
+
fulfillment_order: fulfillment_order.attributes.merge(status: 'open', request_status: 'rejected')
|
364
|
+
}
|
365
|
+
fake 'fulfillment_orders',
|
366
|
+
url: "#{@url_prefix}/fulfillment_orders/519788021/fulfillment_request/reject.json",
|
367
|
+
:method => :post,
|
368
|
+
:request_body => ActiveSupport::JSON.encode(request_body),
|
369
|
+
:body => ActiveSupport::JSON.encode(fake_response)
|
370
|
+
|
371
|
+
rejected = fulfillment_order.reject_fulfillment_request(message: message)
|
372
|
+
|
373
|
+
assert_equal true, rejected
|
374
|
+
assert_equal 'open', fulfillment_order.status
|
375
|
+
assert_equal 'rejected', fulfillment_order.request_status
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
context "#request_cancellation" do
|
380
|
+
should "make a cancellation request for a fulfillment order" do
|
381
|
+
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
382
|
+
|
383
|
+
message = "Cancelling this please."
|
384
|
+
request_body = {
|
385
|
+
'cancellation_request' => {
|
386
|
+
'message' => message
|
387
|
+
}
|
388
|
+
}
|
389
|
+
cancelling = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
|
390
|
+
cancelling['status'] = 'in_progress'
|
391
|
+
cancelling['request_status'] = 'cancellation_requested'
|
392
|
+
fake 'fulfillment_orders',
|
393
|
+
url: "#{@url_prefix}/fulfillment_orders/519788021/cancellation_request.json",
|
394
|
+
:method => :post,
|
395
|
+
:request_body => ActiveSupport::JSON.encode(request_body),
|
396
|
+
:body => ActiveSupport::JSON.encode({ fulfillment_order: cancelling })
|
397
|
+
|
398
|
+
cancelled = fulfillment_order.request_cancellation(message: "Cancelling this please.")
|
399
|
+
|
400
|
+
assert_equal true, cancelled
|
401
|
+
assert_equal 'in_progress', fulfillment_order.status
|
402
|
+
assert_equal 'cancellation_requested', fulfillment_order.request_status
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
context "#accept_cancellation_request" do
|
407
|
+
should "accept a cancellation request for a fulfillment order" do
|
408
|
+
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
409
|
+
|
410
|
+
message = 'Already in-progress. Reject this FO cancellation request'
|
411
|
+
request_body = {
|
412
|
+
'cancellation_request' => {
|
413
|
+
'message' => message
|
414
|
+
}
|
415
|
+
}
|
416
|
+
fake_response = {
|
417
|
+
fulfillment_order: fulfillment_order.attributes.merge(status: 'cancelled',
|
418
|
+
request_status: 'cancellation_accepted')
|
419
|
+
}
|
420
|
+
fake 'fulfillment_orders',
|
421
|
+
url: "#{@url_prefix}/fulfillment_orders/519788021/cancellation_request/accept.json",
|
422
|
+
:method => :post,
|
423
|
+
:request_body => ActiveSupport::JSON.encode(request_body),
|
424
|
+
:body => ActiveSupport::JSON.encode(fake_response)
|
425
|
+
|
426
|
+
accepted = fulfillment_order.accept_cancellation_request(message: message)
|
427
|
+
|
428
|
+
assert_equal true, accepted
|
429
|
+
assert_equal 'cancelled', fulfillment_order.status
|
430
|
+
assert_equal 'cancellation_accepted', fulfillment_order.request_status
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
context "#reject_cancellation_request" do
|
435
|
+
should "reject a cancellation request for a fulfillment order" do
|
436
|
+
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
|
437
|
+
|
438
|
+
message = "Already in-progress. Reject this FO cancellation request"
|
439
|
+
request_body = {
|
440
|
+
'cancellation_request' => {
|
441
|
+
'message' => message
|
442
|
+
}
|
443
|
+
}
|
444
|
+
fake_response = {
|
445
|
+
fulfillment_order: fulfillment_order.attributes.merge(status: 'in_progress',
|
446
|
+
request_status: 'cancellation_rejected')
|
447
|
+
}
|
448
|
+
fake 'fulfillment_orders',
|
449
|
+
url: "#{@url_prefix}/fulfillment_orders/519788021/cancellation_request/reject.json",
|
450
|
+
:method => :post,
|
451
|
+
:request_body => request_body,
|
452
|
+
:body => ActiveSupport::JSON.encode(fake_response)
|
453
|
+
|
454
|
+
rejected = fulfillment_order.reject_cancellation_request(message: message)
|
455
|
+
|
456
|
+
assert_equal true, rejected
|
457
|
+
assert_equal 'in_progress', fulfillment_order.status
|
458
|
+
assert_equal 'cancellation_rejected', fulfillment_order.request_status
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|