diff --git a/lib/shopify_api/resources/fulfillment_order.rb b/lib/shopify_api/resources/fulfillment_order.rb index 2aa898584..ac45959ad 100644 --- a/lib/shopify_api/resources/fulfillment_order.rb +++ b/lib/shopify_api/resources/fulfillment_order.rb @@ -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, @@ -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 diff --git a/test/fulfillment_order_test.rb b/test/fulfillment_order_test.rb index 49076f443..7930e573a 100644 --- a/test/fulfillment_order_test.rb +++ b/test/fulfillment_order_test.rb @@ -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, @@ -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 @@ -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) @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 440ff34ea..1bc275753 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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