Browse Source

Add tests for fulfillments

Maarten van Grootel 11 years ago
parent
commit
b5b82c2d34
3 changed files with 88 additions and 1 deletions
  1. 1 1
      Gemfile.lock
  2. 49 0
      test/fixtures/fulfillment.json
  3. 38 0
      test/fulfillment_test.rb

+ 1 - 1
Gemfile.lock

@@ -1,7 +1,7 @@
 PATH
   remote: .
   specs:
-    shopify_api (3.1.0)
+    shopify_api (3.1.2)
       activeresource (>= 3.0.0)
       thor (>= 0.14.4)
 

+ 49 - 0
test/fixtures/fulfillment.json

@@ -0,0 +1,49 @@
+{
+  "fulfillment": {
+    "created_at": "2013-11-01T16:06:08-04:00",
+    "id": 255858046,
+    "order_id": 450789469,
+    "service": "manual",
+    "status": "pending",
+    "tracking_company": null,
+    "updated_at": "2013-11-01T16:06:08-04:00",
+    "tracking_number": "1Z2345",
+    "tracking_numbers": [
+      "1Z2345"
+    ],
+    "tracking_url": "http://www.google.com/search?q=1Z2345",
+    "tracking_urls": [
+      "http://www.google.com/search?q=1Z2345"
+    ],
+    "receipt": {
+      "testcase": true,
+      "authorization": "123456"
+    },
+    "line_items": [
+      {
+        "fulfillment_service": "manual",
+        "fulfillment_status": null,
+        "grams": 200,
+        "id": 466157049,
+        "price": "199.00",
+        "product_id": 632910392,
+        "quantity": 1,
+        "requires_shipping": true,
+        "sku": "IPOD2008GREEN",
+        "title": "IPod Nano - 8gb",
+        "variant_id": 39072856,
+        "variant_title": "green",
+        "vendor": null,
+        "name": "IPod Nano - 8gb - green",
+        "variant_inventory_management": "shopify",
+        "properties": [
+          {
+            "name": "Custom Engraving",
+            "value": "Happy Birthday"
+          }
+        ],
+        "product_exists": true
+      }
+    ]
+  }
+}

+ 38 - 0
test/fulfillment_test.rb

@@ -0,0 +1,38 @@
+require 'test_helper'
+
+class FulFillmentTest < Test::Unit::TestCase
+  def setup
+    fake "orders/450789469/fulfillments/255858046", :method => :get, :body => load_fixture('fulfillment')
+  end
+
+  context "Fulfillment" do
+    context "#complete" do
+      should "be able to complete fulfillment" do
+        fulfillment = ShopifyAPI::Fulfillment.find(255858046, :params => {:order_id => 450789469})
+
+        success = ActiveSupport::JSON.decode(load_fixture('fulfillment'))
+        success['fulfillment']['status'] = 'success'
+        fake "orders/450789469/fulfillments/255858046/complete", :method => :post, :body => ActiveSupport::JSON.encode(success)
+
+        assert_equal 'pending', fulfillment.status
+        assert fulfillment.complete
+        assert_equal 'success', fulfillment.status
+      end
+    end
+
+    context "#cancel" do
+      should "be able to cancel fulfillment" do
+        fulfillment = ShopifyAPI::Fulfillment.find(255858046, :params => {:order_id => 450789469})
+
+        cancelled = ActiveSupport::JSON.decode(load_fixture('fulfillment'))
+        cancelled['fulfillment']['status'] = 'cancelled'
+        fake "orders/450789469/fulfillments/255858046/cancel", :method => :post, :body => ActiveSupport::JSON.encode(cancelled)
+
+        assert_equal 'pending', fulfillment.status
+        assert fulfillment.cancel
+        assert_equal 'cancelled', fulfillment.status
+      end
+    end
+  end
+
+end