Skip to content

Commit

Permalink
Updates from PR review 2
Browse files Browse the repository at this point in the history
  • Loading branch information
karmakaze committed Nov 21, 2019
1 parent 90ab4b6 commit 366a1e8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/shopify_api/resources/fulfillment_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def close
load_attributes_from_response(post(:close, {}, only_id))
end

def fulfillment_request(fulfillment_order_line_items:, message:)
def request_fulfillment(fulfillment_order_line_items:, message:)
body = {
fulfillment_request: {
fulfillment_order_line_items: fulfillment_order_line_items,
Expand All @@ -56,7 +56,7 @@ def reject_fulfillment_request(params)
load_attributes_from_response(post('fulfillment_request/reject', {}, params.to_json))
end

def cancellation_request(message:)
def request_cancellation(message:)
body = {
cancellation_request: {
message: message
Expand Down
70 changes: 59 additions & 11 deletions test/fulfillment_order_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,18 @@ def setup
end
end

context "#fulfillment_request" do
should "make a fulfillment request for a fulfillment order" do
context "#request_fulfillment" do
should "make a fulfillment request for a fulfillment order including unsubmitted" do
original_fulfillment_order = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
original_fulfillment_order['status'] = 'closed'
submitted_fulfillment_order = original_fulfillment_order.clone
submitted_fulfillment_order['id'] = 2
submitted_fulfillment_order['status'] = 'open'
submitted_fulfillment_order['request_status'] = 'submitted'
unsubmitted_fulfillment_order = original_fulfillment_order.clone
unsubmitted_fulfillment_order['id'] = 3
unsubmitted_fulfillment_order['status'] = 'open'
unsubmitted_fulfillment_order['request_status'] = 'unsubmitted'
original_fulfillment_order['status'] = 'in_progress'
body = {
original_fulfillment_order: original_fulfillment_order,
submitted_fulfillment_order: submitted_fulfillment_order,
Expand All @@ -166,24 +167,71 @@ def setup
fulfillment_order_line_items: [{ id: 1, quantity: 1 }],
message: "Fulfill this FO, please."
}
original_submitted_unsubmitted_fos = fulfillment_order.fulfillment_request(params)
response_fulfillment_orders = fulfillment_order.request_fulfillment(params)

assert_equal 'in_progress', fulfillment_order.status
assert_equal 'closed', fulfillment_order.status
assert_equal 3, response_fulfillment_orders.size

original_fo = original_submitted_unsubmitted_fos['original_fulfillment_order']
original_fo = response_fulfillment_orders['original_fulfillment_order']
assert_equal 519788021, original_fo.id
assert_equal 'in_progress', original_fo.status
assert_equal 'closed', original_fo.status

submitted_fo = original_submitted_unsubmitted_fos['submitted_fulfillment_order']
submitted_fo = response_fulfillment_orders['submitted_fulfillment_order']
assert_equal 2, submitted_fo.id
assert_equal 'open', submitted_fo.status
assert_equal 'submitted', submitted_fo.request_status

unsubmitted_fo = original_submitted_unsubmitted_fos['unsubmitted_fulfillment_order']
unsubmitted_fo = response_fulfillment_orders['unsubmitted_fulfillment_order']
assert_equal 3, unsubmitted_fo.id
assert_equal 'open', unsubmitted_fo.status
assert_equal 'unsubmitted', unsubmitted_fo.request_status
end

should "make a fulfillment request for a fulfillment order excluding unsubmitted" do
original_fulfillment_order = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
original_fulfillment_order['status'] = 'closed'
submitted_fulfillment_order = original_fulfillment_order.clone
submitted_fulfillment_order['id'] = 2
submitted_fulfillment_order['status'] = 'open'
submitted_fulfillment_order['request_status'] = 'submitted'
body = {
original_fulfillment_order: original_fulfillment_order,
submitted_fulfillment_order: submitted_fulfillment_order,
unsubmitted_fulfillment_order: nil,
}
request_body = {
fulfillment_request: {
fulfillment_order_line_items: [
{ id: 1, quantity: 1 }
],
message: 'Fulfill this FO, please.'
}
}
fake "fulfillment_orders/519788021/fulfillment_request", :method => :post,
:request_body => ActiveSupport::JSON.encode(request_body),
:body => ActiveSupport::JSON.encode(body)

fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
params = {
fulfillment_order_line_items: [{ id: 1, quantity: 1 }],
message: "Fulfill this FO, please."
}
response_fulfillment_orders = fulfillment_order.request_fulfillment(params)

assert_equal 'closed', fulfillment_order.status
assert_equal 3, response_fulfillment_orders.size

original_fo = response_fulfillment_orders['original_fulfillment_order']
assert_equal 519788021, original_fo.id
assert_equal 'closed', original_fo.status

submitted_fo = response_fulfillment_orders['submitted_fulfillment_order']
assert_equal 2, submitted_fo.id
assert_equal 'open', submitted_fo.status
assert_equal 'submitted', submitted_fo.request_status

assert_nil response_fulfillment_orders['unsubmitted_fulfillment_order']
end
end

context "#accept_fulfillment_request" do
Expand Down Expand Up @@ -234,7 +282,7 @@ def setup
end
end

context "#cancellation_request" do
context "#request_cancellation" do
should "make a cancellation request for a fulfillment order" do
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)

Expand All @@ -244,7 +292,7 @@ def setup
fake "fulfillment_orders/519788021/cancellation_request", :method => :post,
:body => ActiveSupport::JSON.encode(cancelling)

cancelled = fulfillment_order.cancellation_request(message: "Cancelling this please.")
cancelled = fulfillment_order.request_cancellation(message: "Cancelling this please.")

assert_equal true, cancelled
assert_equal 'in_progress', fulfillment_order.status
Expand Down
5 changes: 0 additions & 5 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ def fake(endpoint, options={})
)
end

def query_string(hash)
return '' if hash.nil? || hash.empty?
'?' + hash.map { |k, v| URI::encode(k.to_s) + '=' + URI::encode(v.to_s) }.join('&')
end

def ar_version_before?(version_string)
Gem::Version.new(ActiveResource::VERSION::STRING) < Gem::Version.new(version_string)
end
Expand Down

0 comments on commit 366a1e8

Please sign in to comment.