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 26, 2019
1 parent ba84987 commit 130deca
Showing 1 changed file with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class FulfillmentOrderFulfillmentTest < Test::Unit::TestCase
class FulfillmentV2Test < Test::Unit::TestCase
def setup
super
fake "fulfillment_orders/519788021", method: :get,
Expand All @@ -25,18 +25,14 @@ def setup
}
]
}
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
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)

assert_equal true, saved
fulfillment = ShopifyAPI::FulfillmentV2.new(create_fulfillment_attributes)
assert fulfillment.save
assert_equal 346743624, fulfillment.id
end
end
Expand All @@ -48,7 +44,13 @@ def setup
url: 'https://example.com/fulfillment_tracking/JSDHFHAG',
company: 'ACME co',
}
fake_f = ActiveSupport::JSON.decode(load_fixture('fulfillment').gsub(/1Z2345/, 'JSDHFHAG'))['fulfillment']
fake_f = ActiveSupport::JSON.decode(load_fixture('fulfillment'))['fulfillment']
fake_f['tracking_number'] = tracking_info[:number]
fake_f['tracking_numbers'] = [tracking_info[:number]]
fake_f['tracking_url'] = tracking_info[:url]
fake_f['tracking_urls'] = [tracking_info[:url]]
fake_f['tracking_company'] = tracking_info[:company]

request_body = {
fulfillment: {
tracking_info: tracking_info,
Expand All @@ -59,25 +61,30 @@ def setup
request_body: ActiveSupport::JSON.encode(request_body),
body: ActiveSupport::JSON.encode(fulfillment: fake_f)

fulfillment = ShopifyAPI::FulfillmentOrderFulfillment.new(id: fake_f['id'])
fulfillment = ShopifyAPI::FulfillmentV2.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
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_f = ActiveSupport::JSON.decode(load_fixture('fulfillment'))['fulfillment']
fake_f['status'] = 'cancelled'
fake "fulfillments/#{fake_f['id']}/cancel", method: :post,
body: ActiveSupport::JSON.encode(fulfillment: fake_f)

fulfillment = ShopifyAPI::FulfillmentOrderFulfillment.new(id: fake_f['id'])
fulfillment = ShopifyAPI::FulfillmentV2.new(id: fake_f['id'])
cancelled = fulfillment.cancel

assert_equal true, cancelled
assert_equal 'pending', fulfillment.status
assert_equal 'cancelled', fulfillment.status
end
end
end
Expand Down

0 comments on commit 130deca

Please sign in to comment.