Sfoglia il codice sorgente

Added version check

Siddhant Bajaj 5 anni fa
parent
commit
0be270c7a4
2 ha cambiato i file con 32 aggiunte e 1 eliminazioni
  1. 2 0
      lib/shopify_api/resources/collection.rb
  2. 30 1
      test/collection_test.rb

+ 2 - 0
lib/shopify_api/resources/collection.rb

@@ -6,6 +6,8 @@ module ShopifyAPI
     include Metafields
 
     def products(options = {})
+      available_in_version = ShopifyAPI::ApiVersion.find_version(:unstable)
+      raise NotImplementedError unless ShopifyAPI::Base.api_version >= available_in_version
       Product.find(:all, from: "#{self.class.prefix}collections/#{id}/products.json", params: options)
     end
   end

+ 30 - 1
test/collection_test.rb

@@ -1,7 +1,7 @@
 require 'test_helper'
 
 class CollectionTest < Test::Unit::TestCase
-  test "Collection get products gets all products in a collection" do
+  test "Collection get products gets all products in a collection on unstable version" do
     unstable_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: :unstable)
     ShopifyAPI::Base.activate_session(unstable_version)
 
@@ -26,4 +26,33 @@ class CollectionTest < Test::Unit::TestCase
     )
     assert_equal [632910392, 921728736], collection.products.map(&:id)
   end
+
+  test "Collection get products fails on older api version" do
+    unstable_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: '2019-07')
+    ShopifyAPI::Base.activate_session(unstable_version)
+
+    fake(
+        'collections',
+        url: 'https://shop2.myshopify.com/admin/api/2019-07/collections/1.json',
+        method: :get,
+        status: 200,
+        body: load_fixture('collection'),
+        extension: false
+    )
+
+    collection = ShopifyAPI::Collection.find(1)
+
+    fake(
+        'products',
+        url: 'https://shop2.myshopify.com/admin/api/2019-07/collections/1/products.json',
+        method: :get,
+        status: 200,
+        body: load_fixture('collection_products'),
+        extension: false
+    )
+
+    assert_raises NotImplementedError do
+      collection.products
+    end
+  end
 end