Browse Source

Split Checkout and AbandonedCheckout resources

The Abandoned Checkout ActiveResource is mapped to the same RESTful
resource as the Checkout ActiveResource.
Emmanuel Milou 6 năm trước cách đây
mục cha
commit
de10174a03

+ 7 - 0
lib/shopify_api/resources/abandoned_checkout.rb

@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+module ShopifyAPI
+  class AbandonedCheckout < Base
+    self.element_name = "checkout"
+  end
+end

+ 5 - 1
lib/shopify_api/resources/checkout.rb

@@ -1,4 +1,8 @@
+# frozen_string_literal: true
+
 module ShopifyAPI
   class Checkout < Base
+    self.primary_key = :token
+    headers['X-Shopify-Checkout-Version'] = '2016-09-06'
   end
-end
+end

+ 9 - 0
test/abandoned_checkouts_test.rb

@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class AbandonedCheckoutsTest < Test::Unit::TestCase
+  test "get all should get all orders" do
+    fake 'checkouts', :method => :get, :status => 200, :body => load_fixture('checkouts')
+    abandoned_checkout = ShopifyAPI::AbandonedCheckout.all
+    assert_equal 450789469, abandoned_checkout.first.id
+  end
+end

+ 2 - 2
test/checkouts_test.rb

@@ -1,9 +1,9 @@
 require 'test_helper'
 
 class CheckoutsTest < Test::Unit::TestCase
-  test "get all should get all orders" do
+  test "get all checkouts indexed by token" do
     fake 'checkouts', :method => :get, :status => 200, :body => load_fixture('checkouts')
     checkout = ShopifyAPI::Checkout.all
-    assert_equal 450789469, checkout.first.id
+    assert_equal '2a1ace52255252df566af0faaedfbfa7', checkout.first.id
   end
 end

+ 3 - 2
test/detailed_log_subscriber_test.rb

@@ -8,6 +8,7 @@ class LogSubscriberTest < Test::Unit::TestCase
     super
     @page = { :page => { :id => 1, :title => 'Shopify API' } }.to_json
     @ua_header = "\"User-Agent\"=>\"ShopifyAPI/#{ShopifyAPI::VERSION} ActiveResource/#{ActiveResource::VERSION::STRING} Ruby/#{RUBY_VERSION}\""
+    @ver_header = "\"X-Shopify-Checkout-Version\"=>\"2016-09-06\""
 
     ShopifyAPI::Base.clear_session
     ShopifyAPI::Base.site = "https://this-is-my-test-shop.myshopify.com/admin"
@@ -28,7 +29,7 @@ class LogSubscriberTest < Test::Unit::TestCase
     assert_equal 4, @logger.logged(:info).size
     assert_equal "GET https://this-is-my-test-shop.myshopify.com:443/admin/pages/1.json", @logger.logged(:info)[0]
     assert_match /\-\-\> 200/, @logger.logged(:info)[1]
-    assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_header}}", @logger.logged(:info)[2]
+    assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_header}, #{@ver_header}}", @logger.logged(:info)[2]
     assert_match /Response:\n\{\"page\"\:\{((\"id\"\:1)|(\"title\"\:\"Shopify API\")),((\"id\"\:1)|(\"title\"\:\"Shopify API\"))\}\}/,  @logger.logged(:info)[3]
 
   end
@@ -43,7 +44,7 @@ class LogSubscriberTest < Test::Unit::TestCase
     assert_equal 4, @logger.logged(:info).size
     assert_equal "GET https://this-is-my-test-shop.myshopify.com:443/admin/pages/2.json", @logger.logged(:info)[0]
     assert_match /\-\-\> 404/, @logger.logged(:info)[1]
-    assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_header}}", @logger.logged(:info)[2]
+    assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_header}, #{@ver_header}}", @logger.logged(:info)[2]
     assert_equal "Response:", @logger.logged(:info)[3]
   end
 end