Sfoglia il codice sorgente

Add API support for scheduled fulfillment orders

Lin Zhao 4 anni fa
parent
commit
d3998c23ce

+ 2 - 0
CHANGELOG.md

@@ -1,5 +1,7 @@
 ## Unreleased
 
+* [#797](https://github.com/Shopify/shopify_api/pull/797) Release new Endpoint `fulfillment_order.open` and `fulfillment_order.reschedule`.
+
 * [#818](https://github.com/Shopify/shopify_api/pull/818) Avoid depending on ActiveSupport in Sesssion class.
 
 * Freeze all string literals. This should have no impact unless your application is modifying ('monkeypatching') the internals of the library in an unusual way.

+ 13 - 0
lib/shopify_api/resources/fulfillment_order.rb

@@ -52,6 +52,19 @@ module ShopifyAPI
       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: {

+ 2 - 0
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,

+ 1 - 0
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,

+ 2 - 0
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,

+ 51 - 0
test/fulfillment_order_test.rb

@@ -227,6 +227,57 @@ class FulFillmentOrderTest < Test::Unit::TestCase
       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'))