collection_test.rb 1.5 KB

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