Skip to content

Commit

Permalink
Add API support for scheduled fulfillment orders
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhao125 committed Nov 2, 2020
1 parent b8bca16 commit b0a70ba
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## Version 9.2.1

* Release new Endpoint `fulfillment_order.open` and `fulfillment_order.reschedule` in 2021-01 REST API version [#797](https://github.com/Shopify/shopify_api/pull/797)

## Version 9.2.0

* Removes the `shopify` binary which will be used by the Shopify CLI
Expand Down
13 changes: 13 additions & 0 deletions lib/shopify_api/resources/fulfillment_order.rb
Expand Up @@ -51,6 +51,19 @@ def cancel
keyed_fulfillment_orders
end

def open
load_attributes_from_response(post(:open, {}, only_id))
end

def reschedule(new_fulfill_at:)
body = {
fulfillment_order: {
new_fulfill_at: new_fulfill_at,
},
}
load_attributes_from_response(post(:reschedule, {}, body.to_json))
end

def close(message: nil)
body = {
fulfillment_order: {
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/assigned_fulfillment_orders.json
Expand Up @@ -13,6 +13,7 @@
"assigned_location_id": 905684977,
"request_status": "cancellation_accepted",
"delivery_category": null,
"fulfill_at": null,
"fulfillment_order_line_items": [
{
"id": 519788021,
Expand Down Expand Up @@ -51,6 +52,7 @@
"assigned_location_id": 905684977,
"request_status": "cancellation_accepted",
"delivery_category": null,
"fulfill_at": null,
"fulfillment_order_line_items": [
{
"id": 519788021,
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/fulfillment_order.json
Expand Up @@ -12,6 +12,7 @@
"assigned_location_id": 905684977,
"request_status": "unsubmitted",
"delivery_category": null,
"fulfill_at": null,
"fulfillment_order_line_items": [
{
"id": 519788021,
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/fulfillment_orders.json
Expand Up @@ -13,6 +13,7 @@
"assigned_location_id": 905684977,
"request_status": "unsubmitted",
"delivery_category": null,
"fulfill_at": null,
"fulfillment_order_line_items": [
{
"id": 519788021,
Expand Down Expand Up @@ -51,6 +52,7 @@
"assigned_location_id": 905684977,
"request_status": "unsubmitted",
"delivery_category": null,
"fulfill_at": null,
"fulfillment_order_line_items": [
{
"id": 519788021,
Expand Down
51 changes: 51 additions & 0 deletions test/fulfillment_order_test.rb
Expand Up @@ -226,6 +226,57 @@ def setup
end
end

context "#open" do
should "be able to open fulfillment order" do
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
fulfillment_order.status = 'scheduled'

opened = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
opened['status'] = 'open'
body = {
fulfillment_order: opened,
}

fake(
'fulfillment_orders',
url: "#{@url_prefix}/fulfillment_orders/519788021/open.json",
method: :post,
body: ActiveSupport::JSON.encode(body)
)
assert(fulfillment_order.open)
assert_equal('open', fulfillment_order.status)
end
end

context "#reschedule" do
should "be able to rescheduled fulfillment order" do
fulfillment_order = ShopifyAPI::FulfillmentOrder.find(519788021)
fulfillment_order.status = 'scheduled'
new_fulfill_at = "2021-11-29"

rescheduled = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
rescheduled['status'] = 'scheduled'
rescheduled['fulfill_at'] = new_fulfill_at
body = {
fulfillment_order: rescheduled,
}

request_body = { fulfillment_order: { new_fulfill_at: new_fulfill_at } }

fake(
'fulfillment_orders',
url: "#{@url_prefix}/fulfillment_orders/519788021/reschedule.json",
method: :post,
request_body: ActiveSupport::JSON.encode(request_body),
body: ActiveSupport::JSON.encode(body)
)

assert(fulfillment_order.reschedule(new_fulfill_at: new_fulfill_at))
assert_equal('scheduled', fulfillment_order.status)
assert_equal(new_fulfill_at, fulfillment_order.fulfill_at)
end
end

context "#request_fulfillment" do
should "make a fulfillment request for a fulfillment order including unsubmitted" do
fake_original_fulfillment_order = ActiveSupport::JSON.decode(load_fixture('fulfillment_order'))
Expand Down

0 comments on commit b0a70ba

Please sign in to comment.