Skip to content

Commit

Permalink
Merge branch 'master' into enable-cla-bot
Browse files Browse the repository at this point in the history
  • Loading branch information
nwtn authored Nov 6, 2018
2 parents 888fea2 + 42a2212 commit b572d39
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
== Version 5.2.0

* Added `ShopifyAPI::Currency` to fetch list of supported currencies on a shop
* Added `ShopifyAPI::TenderTransaction` to fetch list of transactions on a shop
* Fixed bug with X-Shopify-Checkout-Version on ShopifyAPI::Checkout header being applied to all requests

== Version 5.1.0

* Added `ShopifyAPI::Publications`
Expand Down
5 changes: 4 additions & 1 deletion lib/shopify_api/resources/checkout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
module ShopifyAPI
class Checkout < Base
self.primary_key = :token
headers['X-Shopify-Checkout-Version'] = '2016-09-06'

def self.headers
super.merge('X-Shopify-Checkout-Version' => '2016-09-06')
end

def complete
post(:complete)
Expand Down
6 changes: 6 additions & 0 deletions lib/shopify_api/resources/currency.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

module ShopifyAPI
class Currency < Base
end
end
2 changes: 1 addition & 1 deletion lib/shopify_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ShopifyAPI
VERSION = "5.1.0"
VERSION = "5.2.0"
end
5 changes: 5 additions & 0 deletions test/checkouts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def setup
@expected_checkout_id = JSON.parse(load_fixture('checkout'))['checkout']['token']
end

test ".headers includes a version" do
assert_equal "2016-09-06", ShopifyAPI::Checkout.headers["X-Shopify-Checkout-Version"]
assert_nil ShopifyAPI::Base.headers["X-Shopify-Checkout-Version"]
end

test ":create creates a checkout" do
fake 'checkouts', method: :post, status: 201, body: load_fixture('checkout')

Expand Down
21 changes: 21 additions & 0 deletions test/currency_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# frozen_string_literal: true
require 'test_helper'
class CurrencyTest < Test::Unit::TestCase
def setup
super
fake "currencies", method: :get, body: load_fixture('currencies')
end

context "Currency" do
should 'return a list of enabled currencies' do
currencies = ShopifyAPI::Currency.all
assert_equal 4, currencies.count
assert_equal %w(AUD EUR GBP HKD), currencies.map(&:currency)
assert_equal [true, true, true, false], currencies.map(&:enabled)
currencies.each do |currency|
assert_equal "2018-10-03T14:44:08-04:00", currency.rate_updated_at
end
end
end
end
5 changes: 2 additions & 3 deletions test/detailed_log_subscriber_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def setup
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"
Expand All @@ -29,7 +28,7 @@ def set_logger(logger)
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}, #{@ver_header}}", @logger.logged(:info)[2]
assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_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
Expand All @@ -44,7 +43,7 @@ def set_logger(logger)
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}, #{@ver_header}}", @logger.logged(:info)[2]
assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_header}}", @logger.logged(:info)[2]
assert_equal "Response:", @logger.logged(:info)[3]
end
end
25 changes: 25 additions & 0 deletions test/fixtures/currencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"currencies": [
{
"currency": "AUD",
"rate_updated_at": "2018-10-03T14:44:08-04:00",
"enabled": true
},
{
"currency": "EUR",
"rate_updated_at": "2018-10-03T14:44:08-04:00",
"enabled": true
},
{
"currency": "GBP",
"rate_updated_at": "2018-10-03T14:44:08-04:00",
"enabled": true
},
{
"currency": "HKD",
"rate_updated_at": "2018-10-03T14:44:08-04:00",
"enabled": false
}
]
}

0 comments on commit b572d39

Please sign in to comment.