-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add save, update_tracking, and cancel actions to FulfillmentOrderFulf…
…illment resource
- Loading branch information
Showing
4 changed files
with
211 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module ShopifyAPI | ||
class FulfillmentV2 < Base | ||
self.element_name = 'fulfillment' | ||
|
||
def update_tracking(tracking_info:, notify_customer:) | ||
body = { | ||
fulfillment: { | ||
tracking_info: tracking_info, | ||
notify_customer: notify_customer | ||
} | ||
} | ||
load_attributes_from_response(post(:update_tracking, {}, body.to_json)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'test_helper' | ||
|
||
class FulfillmentV2Test < Test::Unit::TestCase | ||
context "FulfillmentV2" do | ||
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 | ||
end | ||
end |