diff --git a/CHANGELOG.md b/CHANGELOG.md index 65de4bc74..56c09e869 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/lib/shopify_api/resources/fulfillment_order.rb b/lib/shopify_api/resources/fulfillment_order.rb index 474006d02..3bc348924 100644 --- a/lib/shopify_api/resources/fulfillment_order.rb +++ b/lib/shopify_api/resources/fulfillment_order.rb @@ -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: { diff --git a/test/fixtures/assigned_fulfillment_orders.json b/test/fixtures/assigned_fulfillment_orders.json index 0d405e2dc..248c28a61 100644 --- a/test/fixtures/assigned_fulfillment_orders.json +++ b/test/fixtures/assigned_fulfillment_orders.json @@ -13,6 +13,7 @@ "assigned_location_id": 905684977, "request_status": "cancellation_accepted", "delivery_category": null, + "fulfill_at": null, "fulfillment_order_line_items": [ { "id": 519788021, @@ -51,6 +52,7 @@ "assigned_location_id": 905684977, "request_status": "cancellation_accepted", "delivery_category": null, + "fulfill_at": null, "fulfillment_order_line_items": [ { "id": 519788021, diff --git a/test/fixtures/fulfillment_order.json b/test/fixtures/fulfillment_order.json index 54ef71589..d3cdf48e2 100644 --- a/test/fixtures/fulfillment_order.json +++ b/test/fixtures/fulfillment_order.json @@ -12,6 +12,7 @@ "assigned_location_id": 905684977, "request_status": "unsubmitted", "delivery_category": null, + "fulfill_at": null, "fulfillment_order_line_items": [ { "id": 519788021, diff --git a/test/fixtures/fulfillment_orders.json b/test/fixtures/fulfillment_orders.json index ef44616b3..b6685f73d 100644 --- a/test/fixtures/fulfillment_orders.json +++ b/test/fixtures/fulfillment_orders.json @@ -13,6 +13,7 @@ "assigned_location_id": 905684977, "request_status": "unsubmitted", "delivery_category": null, + "fulfill_at": null, "fulfillment_order_line_items": [ { "id": 519788021, @@ -51,6 +52,7 @@ "assigned_location_id": 905684977, "request_status": "unsubmitted", "delivery_category": null, + "fulfill_at": null, "fulfillment_order_line_items": [ { "id": 519788021, diff --git a/test/fulfillment_order_test.rb b/test/fulfillment_order_test.rb index 594973a3e..e0330fd75 100644 --- a/test/fulfillment_order_test.rb +++ b/test/fulfillment_order_test.rb @@ -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'))