Skip to content

Commit

Permalink
Updates from PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
karmakaze committed Nov 13, 2019
1 parent c10ebe9 commit 6dae6dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
14 changes: 11 additions & 3 deletions lib/shopify_api/resources/fulfillment_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ def fulfillments(options = {})

def move(new_location_id:)
body = { fulfillment_order: { new_location_id: new_location_id } }
load_values(post(:move, body, only_id))
keyed_fos = load_keyed_attributes_from_response(post(:move, body, only_id))
if keyed_fos&.fetch('original_fulfillment_order', nil)&.attributes
load(keyed_fos['original_fulfillment_order'].attributes, false, true)
end
keyed_fos
end

def cancel
load_values(post(:cancel, {}, only_id))
keyed_fos = load_keyed_attributes_from_response(post(:cancel, {}, only_id))
if keyed_fos&.fetch('fulfillment_order', nil)&.attributes
load(keyed_fos['fulfillment_order'].attributes, false, true)
end
keyed_fos
end

def close
Expand All @@ -26,7 +34,7 @@ def close

private

def load_values(response)
def load_keyed_attributes_from_response(response)
return load_attributes_from_response(response) if response.code != '200'

keyed_fulfillments = ActiveSupport::JSON.decode(response.body)
Expand Down
19 changes: 11 additions & 8 deletions test/fulfillment_order_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,24 @@ def setup
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
new_location_id = 5

original = fulfillment_order.clone
original.status = 'closed'
moved = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
moved['assigned_location_id'] = new_location_id
fulfillment_order.status = 'closed'

body = {
original_fulfillment_order: fulfillment_order,
original_fulfillment_order: original,
moved_fulfillment_order: moved,
remaining_fulfillment_order: nil,
}
api_version = ShopifyAPI::ApiVersion.find_version('2019-01')
endpoint = "fulfillment_orders/519788021/move"
extension = ".json"
url = "https://this-is-my-test-shop.myshopify.com#{api_version.construct_api_path("#{endpoint}#{extension}")}"
url = url + "?fulfillment_order%5Bnew_location_id%5D=5"
fake endpoint, :method => :post, :url => url, :body => ActiveSupport::JSON.encode(body)
fake_query = "?fulfillment_order%5Bnew_location_id%5D=5"
fake "fulfillment_orders/519788021/move.json#{fake_query}", :method => :post, extension: false,
:body => ActiveSupport::JSON.encode(body)

response_fos = fulfillment_order.move(new_location_id: new_location_id)

assert_equal 'closed', fulfillment_order.status

assert_equal 3, response_fos.count
original_fulfillment_order = response_fos['original_fulfillment_order']
refute_nil original_fulfillment_order
Expand Down Expand Up @@ -102,6 +103,8 @@ def setup
fake "fulfillment_orders/519788021/cancel", :method => :post, :body => ActiveSupport::JSON.encode(body)

response_fos = fulfillment_order.cancel

assert_equal 'cancelled', fulfillment_order.status
assert_equal 2, response_fos.count
fulfillment_order = response_fos['fulfillment_order']
assert_equal 'cancelled', fulfillment_order.status
Expand Down

0 comments on commit 6dae6dd

Please sign in to comment.