image_test.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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/nz7Zg3MNmnd7Q1MLNVS9GId71hSJMZIuzTu4UtKbeEeakhKMl8U8WYjfr18YQaIbAf=="
  8. image.save
  9. assert_equal('http://cdn.shopify.com/s/files/1/0006/9093/3842/products/ipod-nano.png?v=1389388540', image.src)
  10. assert_equal(850703190, image.id)
  11. end
  12. def test_get_images
  13. fake("products/632910392/images", method: :get, body: load_fixture('images'))
  14. image = ShopifyAPI::Image.find(:all, params: { product_id: 632910392 })
  15. assert_equal(2, image.size)
  16. end
  17. def test_get_image
  18. fake("products/632910392/images/850703190", method: :get, body: load_fixture('image'))
  19. image = ShopifyAPI::Image.find(850703190, params: { product_id: 632910392 })
  20. assert_equal(850703190, image.id)
  21. end
  22. def test_delete_image
  23. fake("products/632910392/images/850703190", method: :get, body: load_fixture('image'))
  24. fake("products/632910392/images/850703190", method: :delete, body: "destroyed")
  25. image = ShopifyAPI::Image.find(850703190, params: { product_id: 632910392 })
  26. assert(image.destroy)
  27. end
  28. def test_delete_image_without_fetching
  29. fake("products/632910392/images/850703190", method: :delete, body: "destroyed")
  30. image = ShopifyAPI::Image.new(product_id: 632910392, id: 850703190)
  31. assert(image.destroy)
  32. end
  33. end