image_test.rb 1.6 KB

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