Explorar o código

Add tests for images

Maarten van Grootel %!s(int64=11) %!d(string=hai) anos
pai
achega
60ecdaa455
Modificáronse 3 ficheiros con 57 adicións e 0 borrados
  1. 10 0
      test/fixtures/image.json
  2. 20 0
      test/fixtures/images.json
  3. 27 0
      test/image_test.rb

+ 10 - 0
test/fixtures/image.json

@@ -0,0 +1,10 @@
+{
+  "image": {
+    "created_at": "2014-01-10T16:15:40-05:00",
+    "id": 850703190,
+    "position": 1,
+    "product_id": 632910392,
+    "updated_at": "2014-01-10T16:15:40-05:00",
+    "src": "http://cdn.shopify.com/s/files/1/0006/9093/3842/products/ipod-nano.png?v=1389388540"
+  }
+}

+ 20 - 0
test/fixtures/images.json

@@ -0,0 +1,20 @@
+{
+  "images": [
+    {
+      "created_at": "2014-01-17T16:11:52-05:00",
+      "id": 850703190,
+      "position": 1,
+      "product_id": 632910392,
+      "updated_at": "2014-01-17T16:11:52-05:00",
+      "src": "http://cdn.shopify.com/s/files/1/0006/9093/3842/products/ipod-nano.png?v=1389993112"
+    },
+    {
+      "created_at": "2014-01-17T16:11:52-05:00",
+      "id": 562641783,
+      "position": 2,
+      "product_id": 632910392,
+      "updated_at": "2014-01-17T16:11:52-05:00",
+      "src": "http://cdn.shopify.com/s/files/1/0006/9093/3842/products/ipod-nano-2.png?v=1389993112"
+    }
+  ]
+}

+ 27 - 0
test/image_test.rb

@@ -0,0 +1,27 @@
+require 'test_helper'
+require 'uri'
+
+class ImageTest < Test::Unit::TestCase
+  def test_create_image
+    fake "products/632910392/images", :method => :post, :body => load_fixture('image')
+    image = ShopifyAPI::Image.new(:product_id => 632910392)
+    image.position = 1
+    image.attachment = "R0lGODlhbgCMAPf/APbr48VySrxTO7IgKt2qmKQdJeK8lsFjROG5p/nz7Zg3MNmnd7Q1MLNVS9GId71hSJMZIuzTu4UtKbeEeakhKMl8U8WYjfr18YQaIbAf=="
+    image.save
+
+    assert_equal 'http://cdn.shopify.com/s/files/1/0006/9093/3842/products/ipod-nano.png?v=1389388540', image.src
+    assert_equal 850703190, image.id
+  end
+
+  def test_get_images
+    fake "products/632910392/images", :method => :get, :body => load_fixture('images')
+    image = ShopifyAPI::Image.find(:all, :params => {:product_id => 632910392})
+    assert_equal 2, image.size
+  end
+
+  def test_get_image
+    fake "products/632910392/images/850703190", :method => :get, :body => load_fixture('image')
+    image = ShopifyAPI::Image.find(850703190, :params => {:product_id => 632910392})
+    assert_equal 850703190, image.id
+  end
+end