From 0c557e7772e6909af35e8c86decfb65bcf05efd8 Mon Sep 17 00:00:00 2001 From: Keith Kim Date: Tue, 26 Nov 2019 14:59:24 -0500 Subject: [PATCH] Updates from PR review --- test/fulfillment_order_fulfillment_test.rb | 84 ---------------------- test/fulfillment_v2_test.rb | 82 +++++++++++++++++++++ 2 files changed, 82 insertions(+), 84 deletions(-) delete mode 100644 test/fulfillment_order_fulfillment_test.rb create mode 100644 test/fulfillment_v2_test.rb diff --git a/test/fulfillment_order_fulfillment_test.rb b/test/fulfillment_order_fulfillment_test.rb deleted file mode 100644 index c6376e817..000000000 --- a/test/fulfillment_order_fulfillment_test.rb +++ /dev/null @@ -1,84 +0,0 @@ -require 'test_helper' - -class FulfillmentOrderFulfillmentTest < Test::Unit::TestCase - def setup - super - fake "fulfillment_orders/519788021", method: :get, - body: load_fixture('fulfillment_order') - end - - context "FulfillmentOrderFulfillment" do - context "#create" do - should "be able to create a fulfillment order fulfillment" do - create_fulfillment_attributes = { - message: "The message for this FO fulfillment", - notify_customer: true, - tracking_info: { - number: "XSDFHYR23475", - url: "https://tracking.example.com/XSDFHYR23475", - company: "TFTC - the fulfillment/tracking company" - }, - line_items_by_fulfillment_order: [ - { - fulfillment_order_id: 3, - fulfillment_order_line_items: [{ id: 2, quantity: 1 }] - } - ] - } - stub_request(:post, "https://this-is-my-test-shop.myshopify.com/admin/api/2019-01/fulfillments.json").with( - body: { - fulfillment: create_fulfillment_attributes - } - ).to_return(status: 200, body: ActiveSupport::JSON.encode(create_fulfillment_attributes.merge(id: 346743624)), - headers: { content_type: "text/x-json" }) - - fulfillment = ShopifyAPI::FulfillmentOrderFulfillment.new(create_fulfillment_attributes) - - saved = fulfillment.save - - assert_equal true, saved - assert_equal 346743624, fulfillment.id - end - end - - context "#update_tracking" do - should "be able to update tracking info for a fulfillment" do - tracking_info = { - number: 'JSDHFHAG', - url: 'https://example.com/fulfillment_tracking/JSDHFHAG', - company: 'ACME co', - } - fake_f = ActiveSupport::JSON.decode(load_fixture('fulfillment').gsub(/1Z2345/, 'JSDHFHAG'))['fulfillment'] - request_body = { - fulfillment: { - tracking_info: tracking_info, - notify_customer: true - } - } - fake "fulfillments/#{fake_f['id']}/update_tracking", method: :post, - request_body: ActiveSupport::JSON.encode(request_body), - body: ActiveSupport::JSON.encode(fulfillment: fake_f) - - fulfillment = ShopifyAPI::FulfillmentOrderFulfillment.new(id: fake_f['id']) - updated = fulfillment.update_tracking(tracking_info: tracking_info, notify_customer: true) - - assert_equal true, updated - assert_equal 'JSDHFHAG', fulfillment.tracking_number - end - end - - context "#cancel" do - should "be able to cancel a fulfillment" do - fake_f = ActiveSupport::JSON.decode(load_fixture('fulfillment'))['fulfillment'] - fake "fulfillments/#{fake_f['id']}/cancel", method: :post, - body: ActiveSupport::JSON.encode(fulfillment: fake_f) - - fulfillment = ShopifyAPI::FulfillmentOrderFulfillment.new(id: fake_f['id']) - cancelled = fulfillment.cancel - - assert_equal true, cancelled - assert_equal 'pending', fulfillment.status - end - end - end -end diff --git a/test/fulfillment_v2_test.rb b/test/fulfillment_v2_test.rb new file mode 100644 index 000000000..9a8252689 --- /dev/null +++ b/test/fulfillment_v2_test.rb @@ -0,0 +1,82 @@ +require 'test_helper' + +class FulfillmentV2Test < Test::Unit::TestCase + context "FulfillmentV2" do + context "#create" do + should "be able to create a fulfillment order fulfillment" do + create_fulfillment_attributes = { + message: "The message for this FO fulfillment", + notify_customer: true, + tracking_info: { + number: "XSDFHYR23475", + url: "https://tracking.example.com/XSDFHYR23475", + company: "TFTC - the fulfillment/tracking company" + }, + line_items_by_fulfillment_order: [ + { + fulfillment_order_id: 3, + fulfillment_order_line_items: [{ id: 2, quantity: 1 }] + } + ] + } + request_body = { fulfillment: create_fulfillment_attributes } + response_body = { fulfillment: create_fulfillment_attributes.merge(id: 346743624) } + fake "fulfillments", :method => :post, + :request_body => ActiveSupport::JSON.encode(request_body), + :body => ActiveSupport::JSON.encode(response_body) + + fulfillment = ShopifyAPI::FulfillmentV2.new(create_fulfillment_attributes) + assert fulfillment.save + assert_equal 346743624, fulfillment.id + end + end + + context "#update_tracking" do + should "be able to update tracking info for a fulfillment" do + tracking_info = { + number: 'JSDHFHAG', + url: 'https://example.com/fulfillment_tracking/JSDHFHAG', + company: 'ACME co', + } + fake_fulfillment = ActiveSupport::JSON.decode(load_fixture('fulfillment'))['fulfillment'] + fake_fulfillment['tracking_number'] = tracking_info[:number] + fake_fulfillment['tracking_numbers'] = [tracking_info[:number]] + fake_fulfillment['tracking_url'] = tracking_info[:url] + fake_fulfillment['tracking_urls'] = [tracking_info[:url]] + fake_fulfillment['tracking_company'] = tracking_info[:company] + + request_body = { + fulfillment: { + tracking_info: tracking_info, + notify_customer: true + } + } + fake "fulfillments/#{fake_fulfillment['id']}/update_tracking", method: :post, + request_body: ActiveSupport::JSON.encode(request_body), + body: ActiveSupport::JSON.encode(fulfillment: fake_fulfillment) + + fulfillment = ShopifyAPI::FulfillmentV2.new(id: fake_fulfillment['id']) + assert fulfillment.update_tracking(tracking_info: tracking_info, notify_customer: true) + + assert_equal tracking_info[:number], fulfillment.tracking_number + assert_equal [tracking_info[:number]], fulfillment.tracking_numbers + assert_equal tracking_info[:url], fulfillment.tracking_url + assert_equal [tracking_info[:url]], fulfillment.tracking_urls + assert_equal tracking_info[:company], fulfillment.tracking_company + end + end + + context "#cancel" do + should "be able to cancel a fulfillment" do + fake_fulfillment = ActiveSupport::JSON.decode(load_fixture('fulfillment'))['fulfillment'] + fake_fulfillment['status'] = 'cancelled' + fake "fulfillments/#{fake_fulfillment['id']}/cancel", method: :post, + body: ActiveSupport::JSON.encode(fulfillment: fake_fulfillment) + + fulfillment = ShopifyAPI::FulfillmentV2.new(id: fake_fulfillment['id']) + assert fulfillment.cancel + assert_equal 'cancelled', fulfillment.status + end + end + end +end