collection_test.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. require 'test_helper'
  2. class CollectionTest < Test::Unit::TestCase
  3. test "Collection get products gets all products in a collection on unstable version" do
  4. unstable_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: :unstable)
  5. ShopifyAPI::Base.activate_session(unstable_version)
  6. fake(
  7. 'collections',
  8. url: 'https://shop2.myshopify.com/admin/api/unstable/collections/1.json',
  9. method: :get,
  10. status: 200,
  11. body: load_fixture('collection'),
  12. extension: false
  13. )
  14. collection = ShopifyAPI::Collection.find(1)
  15. fake(
  16. 'products',
  17. url: 'https://shop2.myshopify.com/admin/api/unstable/collections/1/products.json',
  18. method: :get,
  19. status: 200,
  20. body: load_fixture('collection_products'),
  21. extension: false
  22. )
  23. assert_equal [632910392, 921728736], collection.products.map(&:id)
  24. end
  25. test "Collection get products fails on older api version" do
  26. unstable_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: '2019-07')
  27. ShopifyAPI::Base.activate_session(unstable_version)
  28. fake(
  29. 'collections',
  30. url: 'https://shop2.myshopify.com/admin/api/2019-07/collections/1.json',
  31. method: :get,
  32. status: 200,
  33. body: load_fixture('collection'),
  34. extension: false
  35. )
  36. collection = ShopifyAPI::Collection.find(1)
  37. fake(
  38. 'products',
  39. url: 'https://shop2.myshopify.com/admin/api/2019-07/collections/1/products.json',
  40. method: :get,
  41. status: 200,
  42. body: load_fixture('collection_products'),
  43. extension: false
  44. )
  45. assert_raises NotImplementedError do
  46. collection.products
  47. end
  48. end
  49. end