Browse Source

Added cart resource to the api

Dennis O'Connor 13 years ago
parent
commit
c7a8ca2dd9
4 changed files with 61 additions and 0 deletions
  1. 1 0
      lib/shopify_api/resources.rb
  2. 4 0
      lib/shopify_api/resources/cart.rb
  3. 13 0
      test/cart_test.rb
  4. 43 0
      test/fixtures/carts.json

+ 1 - 0
lib/shopify_api/resources.rb

@@ -5,6 +5,7 @@ require 'shopify_api/resources/article'
 require 'shopify_api/resources/asset'
 require 'shopify_api/resources/billing_address'
 require 'shopify_api/resources/blog'
+require 'shopify_api/resources/cart'
 require 'shopify_api/resources/collect'
 require 'shopify_api/resources/comment'
 require 'shopify_api/resources/country'

+ 4 - 0
lib/shopify_api/resources/cart.rb

@@ -0,0 +1,4 @@
+module ShopifyAPI
+  class Cart < Base
+  end
+end

+ 13 - 0
test/cart_test.rb

@@ -0,0 +1,13 @@
+require 'test_helper'
+
+class CartTest < Test::Unit::TestCase
+  test 'all should return all carts' do
+    fake 'carts'
+    carts = ShopifyAPI::Cart.all
+    assert_equal carts.size, 2
+    assert_equal 2, carts.first.id
+    assert_equal "3eed8183d4281db6ea82ee2b8f23e9cc", carts.first.token
+    assert_equal 1, carts.first.line_items.size
+    assert_equal 'test', carts.first.line_items.first.title
+  end
+end

+ 43 - 0
test/fixtures/carts.json

@@ -0,0 +1,43 @@
+{
+  "carts": [
+    {
+      "id": 2,
+      "note": null,
+      "token": "3eed8183d4281db6ea82ee2b8f23e9cc",
+      "updated_at": "2012-02-13T14:39:37-05:00",
+      "line_items": 
+      [
+        {
+          "id": 1,
+          "title": "test",
+          "price": "1.00",
+          "line_price": "1.00",
+          "quantity": 1,
+          "sku": "",
+          "grams": 1000,
+          "vendor": "test",
+          "variant_id": 1
+        }
+      ]
+    },
+    {
+      "id": 1,
+      "note": "",
+      "token": "49801807939c296be1e9a4bf6783a705",
+      "updated_at": "2012-02-13T14:39:12-05:00",
+      "line_items":[
+        {
+          "id": 1,
+          "title": "test",
+          "price": "1.00",
+          "line_price": "1.00",
+          "quantity": 1,
+          "sku": "",
+          "grams": 1000,
+          "vendor": "test",
+          "variant_id": 1
+        }
+      ]
+    }
+  ]
+}