image_test.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. require 'test_helper'
  2. class ImageTest < Test::Unit::TestCase
  3. def test_create_image
  4. fake("products/632910392/images", method: :post, body: load_fixture('image'))
  5. image = ShopifyAPI::Image.new(product_id: 632910392)
  6. image.position = 1
  7. image.attachment = "R0lGODlhbgCMAPf/APbr48VySrxTO7IgKt2qmKQdJeK8lsFjROG5p/nz7Zg3MN" \
  8. "mnd7Q1MLNVS9GId71hSJMZIuzTu4UtKbeEeakhKMl8U8WYjfr18YQaIbAf=="
  9. image.save
  10. assert_equal('http://cdn.shopify.com/s/files/1/0006/9093/3842/products/ipod-nano.png?v=1389388540', image.src)
  11. assert_equal(850703190, image.id)
  12. end
  13. def test_get_images
  14. fake("products/632910392/images", method: :get, body: load_fixture('images'))
  15. image = ShopifyAPI::Image.find(:all, params: { product_id: 632910392 })
  16. assert_equal(2, image.size)
  17. end
  18. def test_get_image
  19. fake("products/632910392/images/850703190", method: :get, body: load_fixture('image'))
  20. image = ShopifyAPI::Image.find(850703190, params: { product_id: 632910392 })
  21. assert_equal(850703190, image.id)
  22. end
  23. def test_delete_image
  24. fake("products/632910392/images/850703190", method: :get, body: load_fixture('image'))
  25. fake("products/632910392/images/850703190", method: :delete, body: "destroyed")
  26. image = ShopifyAPI::Image.find(850703190, params: { product_id: 632910392 })
  27. assert(image.destroy)
  28. end
  29. def test_delete_image_without_fetching
  30. fake("products/632910392/images/850703190", method: :delete, body: "destroyed")
  31. image = ShopifyAPI::Image.new(product_id: 632910392, id: 850703190)
  32. assert(image.destroy)
  33. end
  34. end