shopify_api 9.2.0 → 9.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +36 -0
- data/.github/workflows/build.yml +41 -0
- data/.gitignore +0 -1
- data/.rubocop.yml +23 -3
- data/.rubocop_todo.yml +75 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +151 -0
- data/Gemfile_ar51 +1 -1
- data/README.md +40 -30
- data/RELEASING +10 -6
- data/Rakefile +10 -6
- data/docs/graphql.md +1 -1
- data/docs/index.md +1 -1
- data/lib/active_resource/connection_ext.rb +1 -0
- data/lib/active_resource/detailed_log_subscriber.rb +6 -7
- data/lib/active_resource/json_errors.rb +8 -2
- data/lib/shopify_api.rb +8 -1
- data/lib/shopify_api/api_access.rb +57 -0
- data/lib/shopify_api/api_version.rb +6 -5
- data/lib/shopify_api/connection.rb +1 -0
- data/lib/shopify_api/countable.rb +3 -2
- data/lib/shopify_api/disable_prefix_check.rb +2 -2
- data/lib/shopify_api/events.rb +2 -1
- data/lib/shopify_api/graphql.rb +8 -6
- data/lib/shopify_api/limits.rb +3 -2
- data/lib/shopify_api/message_enricher.rb +11 -9
- data/lib/shopify_api/meta.rb +0 -1
- data/lib/shopify_api/metafields.rb +5 -4
- data/lib/shopify_api/pagination_link_headers.rb +4 -3
- data/lib/shopify_api/resources.rb +1 -0
- data/lib/shopify_api/resources/access_scope.rb +1 -1
- data/lib/shopify_api/resources/access_token.rb +1 -0
- data/lib/shopify_api/resources/address.rb +1 -0
- data/lib/shopify_api/resources/announcement.rb +2 -1
- data/lib/shopify_api/resources/application_charge.rb +1 -0
- data/lib/shopify_api/resources/application_credit.rb +1 -0
- data/lib/shopify_api/resources/article.rb +3 -2
- data/lib/shopify_api/resources/asset.rb +6 -5
- data/lib/shopify_api/resources/assigned_fulfillment_order.rb +1 -1
- data/lib/shopify_api/resources/base.rb +11 -6
- data/lib/shopify_api/resources/billing_address.rb +1 -0
- data/lib/shopify_api/resources/blog.rb +2 -1
- data/lib/shopify_api/resources/carrier_service.rb +1 -0
- data/lib/shopify_api/resources/cart.rb +2 -1
- data/lib/shopify_api/resources/collect.rb +1 -0
- data/lib/shopify_api/resources/collection_listing.rb +1 -0
- data/lib/shopify_api/resources/comment.rb +20 -5
- data/lib/shopify_api/resources/country.rb +1 -0
- data/lib/shopify_api/resources/custom_collection.rb +4 -3
- data/lib/shopify_api/resources/customer.rb +2 -1
- data/lib/shopify_api/resources/customer_group.rb +1 -0
- data/lib/shopify_api/resources/customer_invite.rb +1 -0
- data/lib/shopify_api/resources/customer_saved_search.rb +2 -1
- data/lib/shopify_api/resources/discount_code.rb +1 -0
- data/lib/shopify_api/resources/discount_code_batch.rb +4 -2
- data/lib/shopify_api/resources/draft_order.rb +1 -0
- data/lib/shopify_api/resources/draft_order_invoice.rb +1 -0
- data/lib/shopify_api/resources/event.rb +1 -0
- data/lib/shopify_api/resources/fulfillment.rb +12 -3
- data/lib/shopify_api/resources/fulfillment_event.rb +1 -0
- data/lib/shopify_api/resources/fulfillment_order.rb +30 -16
- data/lib/shopify_api/resources/fulfillment_order_locations_for_move.rb +1 -0
- data/lib/shopify_api/resources/fulfillment_request.rb +1 -0
- data/lib/shopify_api/resources/fulfillment_service.rb +1 -0
- data/lib/shopify_api/resources/fulfillment_v2.rb +3 -2
- data/lib/shopify_api/resources/gift_card.rb +1 -0
- data/lib/shopify_api/resources/image.rb +2 -1
- data/lib/shopify_api/resources/inventory_level.rb +2 -3
- data/lib/shopify_api/resources/line_item.rb +4 -3
- data/lib/shopify_api/resources/location.rb +1 -1
- data/lib/shopify_api/resources/marketing_event.rb +1 -0
- data/lib/shopify_api/resources/metafield.rb +1 -0
- data/lib/shopify_api/resources/note_attribute.rb +1 -0
- data/lib/shopify_api/resources/option.rb +1 -0
- data/lib/shopify_api/resources/order.rb +2 -1
- data/lib/shopify_api/resources/order_risk.rb +1 -0
- data/lib/shopify_api/resources/page.rb +1 -0
- data/lib/shopify_api/resources/payment_details.rb +1 -0
- data/lib/shopify_api/resources/policy.rb +1 -0
- data/lib/shopify_api/resources/price_rule.rb +1 -1
- data/lib/shopify_api/resources/product.rb +14 -11
- data/lib/shopify_api/resources/product_listing.rb +1 -0
- data/lib/shopify_api/resources/province.rb +1 -0
- data/lib/shopify_api/resources/receipt.rb +1 -0
- data/lib/shopify_api/resources/recurring_application_charge.rb +4 -1
- data/lib/shopify_api/resources/redirect.rb +1 -0
- data/lib/shopify_api/resources/refund.rb +2 -1
- data/lib/shopify_api/resources/report.rb +1 -0
- data/lib/shopify_api/resources/resource_feedback.rb +1 -1
- data/lib/shopify_api/resources/rule.rb +1 -0
- data/lib/shopify_api/resources/script_tag.rb +1 -0
- data/lib/shopify_api/resources/shipping_address.rb +1 -0
- data/lib/shopify_api/resources/shipping_line.rb +1 -0
- data/lib/shopify_api/resources/shipping_zone.rb +1 -0
- data/lib/shopify_api/resources/shop.rb +2 -1
- data/lib/shopify_api/resources/smart_collection.rb +2 -2
- data/lib/shopify_api/resources/storefront_access_token.rb +1 -0
- data/lib/shopify_api/resources/tax_line.rb +1 -0
- data/lib/shopify_api/resources/tax_service.rb +1 -0
- data/lib/shopify_api/resources/theme.rb +1 -0
- data/lib/shopify_api/resources/transaction.rb +1 -0
- data/lib/shopify_api/resources/usage_charge.rb +1 -0
- data/lib/shopify_api/resources/user.rb +1 -0
- data/lib/shopify_api/resources/variant.rb +16 -18
- data/lib/shopify_api/resources/webhook.rb +1 -0
- data/lib/shopify_api/session.rb +20 -12
- data/lib/shopify_api/version.rb +2 -1
- data/lib/verify_docs.rb +1 -0
- data/service.yml +1 -1
- data/shopify_api.gemspec +10 -4
- data/test/access_token_test.rb +6 -5
- data/test/active_resource/json_errors_test.rb +6 -6
- data/test/api_access_test.rb +153 -0
- data/test/api_version_test.rb +3 -3
- data/test/application_charge_test.rb +30 -27
- data/test/application_credit_test.rb +10 -9
- data/test/article_test.rb +34 -35
- data/test/asset_test.rb +14 -6
- data/test/assigned_fulfillment_order_test.rb +5 -4
- data/test/base_test.rb +55 -56
- data/test/blog_test.rb +4 -3
- data/test/carrier_service_test.rb +7 -6
- data/test/cart_test.rb +2 -1
- data/test/collect_test.rb +4 -3
- data/test/collection_listing_test.rb +21 -16
- data/test/collection_publication_test.rb +8 -8
- data/test/collection_test.rb +20 -19
- data/test/countable_test.rb +3 -2
- data/test/currency_test.rb +5 -5
- data/test/custom_collection_test.rb +4 -3
- data/test/customer_saved_search_test.rb +18 -8
- data/test/customer_test.rb +22 -14
- data/test/detailed_log_subscriber_test.rb +15 -11
- data/test/discount_code_batch_test.rb +11 -10
- data/test/discount_code_test.rb +21 -15
- data/test/draft_order_test.rb +68 -52
- data/test/fixtures/assigned_fulfillment_orders.json +2 -0
- data/test/fixtures/fulfillment_order.json +1 -0
- data/test/fixtures/fulfillment_orders.json +2 -0
- data/test/fulfillment_event_test.rb +31 -26
- data/test/fulfillment_order_test.rb +215 -147
- data/test/fulfillment_order_test_helper.rb +1 -0
- data/test/fulfillment_request_test.rb +10 -8
- data/test/fulfillment_service_test.rb +13 -12
- data/test/fulfillment_test.rb +81 -66
- data/test/fulfillment_v2_test.rb +16 -12
- data/test/gift_card_test.rb +6 -4
- data/test/graphql_test.rb +27 -27
- data/test/image_test.rb +19 -17
- data/test/inventory_level_test.rb +24 -15
- data/test/lib/webmock_extensions/last_request.rb +1 -1
- data/test/limits_test.rb +2 -1
- data/test/location_test.rb +2 -1
- data/test/marketing_event_test.rb +20 -20
- data/test/message_enricher_test.rb +6 -6
- data/test/meta_test.rb +7 -9
- data/test/metafield_test.rb +30 -20
- data/test/order_risk_test.rb +17 -16
- data/test/order_test.rb +43 -28
- data/test/pagination_test.rb +89 -56
- data/test/policy_test.rb +6 -5
- data/test/price_rule_test.rb +20 -15
- data/test/product_listing_test.rb +20 -20
- data/test/product_publication_test.rb +8 -8
- data/test/product_test.rb +44 -32
- data/test/publication_test.rb +3 -3
- data/test/recurring_application_charge_test.rb +104 -42
- data/test/redirect_test.rb +4 -3
- data/test/refund_test.rb +22 -17
- data/test/report_test.rb +12 -10
- data/test/resource_feedback_test.rb +14 -13
- data/test/script_tag_test.rb +10 -9
- data/test/session_test.rb +74 -46
- data/test/shipping_zone_test.rb +4 -3
- data/test/shop_test.rb +47 -33
- data/test/smart_collection_test.rb +5 -4
- data/test/storefront_access_token_test.rb +13 -15
- data/test/tax_service_test.rb +7 -4
- data/test/tender_transaction_test.rb +3 -3
- data/test/test_helper.rb +13 -11
- data/test/transaction_test.rb +4 -3
- data/test/usage_charge_test.rb +12 -8
- data/test/user_test.rb +4 -3
- data/test/variant_test.rb +23 -54
- data/test/webhook_test.rb +10 -7
- metadata +14 -9
- data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
- data/.travis.yml +0 -28
data/lib/shopify_api/session.rb
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'openssl'
|
|
2
3
|
require 'rack'
|
|
3
4
|
|
|
4
5
|
module ShopifyAPI
|
|
5
|
-
|
|
6
6
|
class ValidationException < StandardError
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
class Session
|
|
10
|
+
SECONDS_IN_A_DAY = 24 * 60 * 60
|
|
11
|
+
|
|
10
12
|
cattr_accessor :api_key, :secret, :myshopify_domain
|
|
11
13
|
self.myshopify_domain = 'myshopify.com'
|
|
12
14
|
|
|
@@ -15,9 +17,8 @@ module ShopifyAPI
|
|
|
15
17
|
alias_method :url, :domain
|
|
16
18
|
|
|
17
19
|
class << self
|
|
18
|
-
|
|
19
20
|
def setup(params)
|
|
20
|
-
params.each { |k,value| public_send("#{k}=", value) }
|
|
21
|
+
params.each { |k, value| public_send("#{k}=", value) }
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
def temp(domain:, token:, api_version: ShopifyAPI::Base.api_version, &block)
|
|
@@ -56,7 +57,7 @@ module ShopifyAPI
|
|
|
56
57
|
# extract host, removing any username, password or path
|
|
57
58
|
shop = URI.parse("https://#{domain}").host
|
|
58
59
|
# extract subdomain of .myshopify.com
|
|
59
|
-
if idx = shop.index(".")
|
|
60
|
+
if (idx = shop.index("."))
|
|
60
61
|
shop = shop.slice(0, idx)
|
|
61
62
|
end
|
|
62
63
|
return nil if shop.empty?
|
|
@@ -67,9 +68,11 @@ module ShopifyAPI
|
|
|
67
68
|
|
|
68
69
|
def validate_signature(params)
|
|
69
70
|
params = (params.respond_to?(:to_unsafe_hash) ? params.to_unsafe_hash : params).with_indifferent_access
|
|
70
|
-
return false unless signature = params[:hmac]
|
|
71
|
+
return false unless (signature = params[:hmac])
|
|
71
72
|
|
|
72
|
-
calculated_signature = OpenSSL::HMAC.hexdigest(
|
|
73
|
+
calculated_signature = OpenSSL::HMAC.hexdigest(
|
|
74
|
+
OpenSSL::Digest.new('SHA256'), secret, encoded_params_for_signature(params)
|
|
75
|
+
)
|
|
73
76
|
|
|
74
77
|
Rack::Utils.secure_compare(calculated_signature, signature)
|
|
75
78
|
end
|
|
@@ -78,7 +81,7 @@ module ShopifyAPI
|
|
|
78
81
|
|
|
79
82
|
def encoded_params_for_signature(params)
|
|
80
83
|
params = params.except(:signature, :hmac, :action, :controller)
|
|
81
|
-
params.map{|k,v| "#{URI.escape(k.to_s, '&=%')}=#{URI.escape(v.to_s, '&%')}"}.sort.join('&')
|
|
84
|
+
params.map { |k, v| "#{URI.escape(k.to_s, '&=%')}=#{URI.escape(v.to_s, '&%')}" }.sort.join('&')
|
|
82
85
|
end
|
|
83
86
|
|
|
84
87
|
def extract_current_session
|
|
@@ -97,7 +100,7 @@ module ShopifyAPI
|
|
|
97
100
|
end
|
|
98
101
|
|
|
99
102
|
def create_permission_url(scope, redirect_uri, options = {})
|
|
100
|
-
params = { client_id: api_key, scope:
|
|
103
|
+
params = { client_id: api_key, scope: ShopifyAPI::ApiAccess.new(scope).to_s, redirect_uri: redirect_uri }
|
|
101
104
|
params[:state] = options[:state] if options[:state]
|
|
102
105
|
construct_oauth_url("authorize", params)
|
|
103
106
|
end
|
|
@@ -105,7 +108,8 @@ module ShopifyAPI
|
|
|
105
108
|
def request_token(params)
|
|
106
109
|
return token if token
|
|
107
110
|
|
|
108
|
-
|
|
111
|
+
twenty_four_hours_ago = Time.now.utc.to_i - SECONDS_IN_A_DAY
|
|
112
|
+
unless self.class.validate_signature(params) && params[:timestamp].to_i > twenty_four_hours_ago
|
|
109
113
|
raise ShopifyAPI::ValidationException, "Invalid Signature: Possible malicious login"
|
|
110
114
|
end
|
|
111
115
|
|
|
@@ -114,12 +118,12 @@ module ShopifyAPI
|
|
|
114
118
|
self.extra = JSON.parse(response.body)
|
|
115
119
|
self.token = extra.delete('access_token')
|
|
116
120
|
|
|
117
|
-
if expires_in = extra.delete('expires_in')
|
|
121
|
+
if (expires_in = extra.delete('expires_in'))
|
|
118
122
|
extra['expires_at'] = Time.now.utc.to_i + expires_in
|
|
119
123
|
end
|
|
120
124
|
token
|
|
121
125
|
else
|
|
122
|
-
raise
|
|
126
|
+
raise response.msg
|
|
123
127
|
end
|
|
124
128
|
end
|
|
125
129
|
|
|
@@ -132,7 +136,11 @@ module ShopifyAPI
|
|
|
132
136
|
end
|
|
133
137
|
|
|
134
138
|
def api_version=(version)
|
|
135
|
-
@api_version = ApiVersion::NullVersion.matches?(version)
|
|
139
|
+
@api_version = if ApiVersion::NullVersion.matches?(version)
|
|
140
|
+
ApiVersion::NullVersion
|
|
141
|
+
else
|
|
142
|
+
ApiVersion.find_version(version)
|
|
143
|
+
end
|
|
136
144
|
end
|
|
137
145
|
|
|
138
146
|
def valid?
|
data/lib/shopify_api/version.rb
CHANGED
data/lib/verify_docs.rb
CHANGED
data/service.yml
CHANGED
data/shopify_api.gemspec
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
$:.push(File.expand_path("../lib", __FILE__))
|
|
2
3
|
require "shopify_api/version"
|
|
3
4
|
|
|
4
5
|
Gem::Specification.new do |s|
|
|
@@ -7,7 +8,12 @@ Gem::Specification.new do |s|
|
|
|
7
8
|
s.author = "Shopify"
|
|
8
9
|
|
|
9
10
|
s.summary = %q{The Shopify API gem is a lightweight gem for accessing the Shopify admin REST web services}
|
|
10
|
-
s.description =
|
|
11
|
+
s.description = <<~HERE
|
|
12
|
+
The Shopify API gem allows Ruby developers to programmatically access the admin
|
|
13
|
+
section of Shopify stores. The API is implemented as JSON or XML over HTTP using
|
|
14
|
+
all four verbs (GET/POST/PUT/DELETE). Each resource, like Order, Product, or
|
|
15
|
+
Collection, has its own URL and is manipulated in isolation.
|
|
16
|
+
HERE
|
|
11
17
|
s.email = %q{developers@jadedpixel.com}
|
|
12
18
|
s.homepage = %q{http://www.shopify.com/partners/apps}
|
|
13
19
|
|
|
@@ -15,7 +21,7 @@ Gem::Specification.new do |s|
|
|
|
15
21
|
|
|
16
22
|
s.extra_rdoc_files = [
|
|
17
23
|
"LICENSE",
|
|
18
|
-
"README.md"
|
|
24
|
+
"README.md",
|
|
19
25
|
]
|
|
20
26
|
s.files = `git ls-files`.split("\n")
|
|
21
27
|
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
|
@@ -35,7 +41,7 @@ Gem::Specification.new do |s|
|
|
|
35
41
|
s.add_development_dependency("minitest", ">= 4.0")
|
|
36
42
|
s.add_development_dependency("rake")
|
|
37
43
|
s.add_development_dependency("timecop")
|
|
38
|
-
s.add_development_dependency("rubocop")
|
|
44
|
+
s.add_development_dependency("rubocop-shopify")
|
|
39
45
|
s.add_development_dependency("pry")
|
|
40
46
|
s.add_development_dependency("pry-byebug")
|
|
41
47
|
end
|
data/test/access_token_test.rb
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'test_helper'
|
|
2
3
|
|
|
3
4
|
class AccessTokenTest < Test::Unit::TestCase
|
|
4
|
-
|
|
5
5
|
def test_delegate_access_token
|
|
6
|
-
fake
|
|
6
|
+
fake(
|
|
7
|
+
"access_tokens/delegate.json?delegate_access_scope%5B%5D=write_orders&" \
|
|
7
8
|
"delegate_access_scope%5B%5D=read_products&expires_in=",
|
|
8
9
|
method: :post,
|
|
9
10
|
status: 201,
|
|
10
11
|
body: load_fixture('access_token_delegate'),
|
|
11
12
|
extension: false
|
|
12
|
-
|
|
13
|
+
)
|
|
13
14
|
delegate_scope = ['write_orders', 'read_products']
|
|
14
15
|
token = ShopifyAPI::AccessToken.delegate(delegate_scope)
|
|
15
16
|
|
|
16
|
-
assert_equal
|
|
17
|
-
assert_equal
|
|
17
|
+
assert_equal('abracadabra', token.access_token)
|
|
18
|
+
assert_equal('write_orders,read_products', token.scope)
|
|
18
19
|
end
|
|
19
20
|
end
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'test_helper'
|
|
2
3
|
|
|
3
4
|
module ActiveResource
|
|
4
5
|
class JsonErrorsTest < Test::Unit::TestCase
|
|
5
|
-
|
|
6
6
|
def test_parsing_of_error_json_hash
|
|
7
7
|
@model = ShopifyAPI::Order.new
|
|
8
|
-
@model.errors.from_json({errors: {name: ['missing']}}.to_json)
|
|
9
|
-
assert_equal
|
|
8
|
+
@model.errors.from_json({ errors: { name: ['missing'] } }.to_json)
|
|
9
|
+
assert_equal(['missing'], @model.errors[:name])
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def test_parsing_of_error_json_plain_string
|
|
13
13
|
@model = ShopifyAPI::Order.new
|
|
14
|
-
@model.errors.from_json({errors: 'some generic error'}.to_json)
|
|
15
|
-
assert_equal
|
|
16
|
-
assert_equal
|
|
14
|
+
@model.errors.from_json({ errors: 'some generic error' }.to_json)
|
|
15
|
+
assert_equal(['some generic error'], @model.errors[:base])
|
|
16
|
+
assert_equal('some generic error', @model.errors.full_messages.to_sentence)
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
end
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'test_helper'
|
|
3
|
+
|
|
4
|
+
class ApiAccessTest < Minitest::Test
|
|
5
|
+
def test_write_is_the_same_access_as_read_write_on_the_same_resource
|
|
6
|
+
read_write_orders = ShopifyAPI::ApiAccess.new(%w(read_orders write_orders))
|
|
7
|
+
write_orders = ShopifyAPI::ApiAccess.new(%w(write_orders))
|
|
8
|
+
|
|
9
|
+
assert_equal write_orders, read_write_orders
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_write_is_the_same_access_as_read_write_on_the_same_unauthenticated_resource
|
|
13
|
+
unauthenticated_read_write_orders = ShopifyAPI::ApiAccess.new(%w(unauthenticated_read_orders unauthenticated_write_orders))
|
|
14
|
+
unauthenticated_write_orders = ShopifyAPI::ApiAccess.new(%w(unauthenticated_write_orders))
|
|
15
|
+
|
|
16
|
+
assert_equal unauthenticated_write_orders, unauthenticated_read_write_orders
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_read_is_not_the_same_as_read_write_on_the_same_resource
|
|
20
|
+
read_orders = ShopifyAPI::ApiAccess.new(%w(read_orders))
|
|
21
|
+
read_write_orders = ShopifyAPI::ApiAccess.new(%w(write_orders read_orders))
|
|
22
|
+
|
|
23
|
+
refute_equal read_write_orders, read_orders
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_two_different_resources_are_not_equal
|
|
27
|
+
read_orders = ShopifyAPI::ApiAccess.new(%w(read_orders))
|
|
28
|
+
read_products = ShopifyAPI::ApiAccess.new(%w(read_products))
|
|
29
|
+
|
|
30
|
+
refute_equal read_orders, read_products
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_two_identical_scopes_are_equal
|
|
34
|
+
read_orders = ShopifyAPI::ApiAccess.new(%w(read_orders))
|
|
35
|
+
read_orders_identical = ShopifyAPI::ApiAccess.new(%w(read_orders))
|
|
36
|
+
|
|
37
|
+
assert_equal read_orders_identical, read_orders
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_unauthenticated_is_not_implied_by_authenticated_access
|
|
41
|
+
unauthenticated_orders = ShopifyAPI::ApiAccess.new(%w(unauthenticated_read_orders))
|
|
42
|
+
authenticated_read_orders = ShopifyAPI::ApiAccess.new(%w(read_orders))
|
|
43
|
+
authenticated_write_orders = ShopifyAPI::ApiAccess.new(%w(write_orders))
|
|
44
|
+
|
|
45
|
+
refute_equal unauthenticated_orders, authenticated_read_orders
|
|
46
|
+
refute_equal unauthenticated_orders, authenticated_write_orders
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_scopes_covers_is_truthy_for_same_scopes
|
|
50
|
+
read_orders = ShopifyAPI::ApiAccess.new(%w(read_orders))
|
|
51
|
+
read_orders_identical = ShopifyAPI::ApiAccess.new(%w(read_orders))
|
|
52
|
+
|
|
53
|
+
assert read_orders.covers?(read_orders_identical)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_covers_is_falsy_for_different_scopes
|
|
57
|
+
read_orders = ShopifyAPI::ApiAccess.new(%w(read_orders))
|
|
58
|
+
read_products = ShopifyAPI::ApiAccess.new(%w(read_products))
|
|
59
|
+
|
|
60
|
+
refute read_orders.covers?(read_products)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_covers_is_truthy_for_read_when_the_set_has_read_write
|
|
64
|
+
write_products = ShopifyAPI::ApiAccess.new(%w(write_products))
|
|
65
|
+
read_products = ShopifyAPI::ApiAccess.new(%w(read_products))
|
|
66
|
+
|
|
67
|
+
assert write_products.covers?(read_products)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_covers_is_truthy_for_read_when_the_set_has_read_write_for_that_resource_and_others
|
|
71
|
+
write_products_and_orders = ShopifyAPI::ApiAccess.new(%w(write_products, write_orders))
|
|
72
|
+
read_orders = ShopifyAPI::ApiAccess.new(%w(read_orders))
|
|
73
|
+
|
|
74
|
+
assert write_products_and_orders.covers?(read_orders)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_covers_is_truthy_for_write_when_the_set_has_read_write_for_that_resource_and_others
|
|
78
|
+
write_products_and_orders = ShopifyAPI::ApiAccess.new(%w(write_products, write_orders))
|
|
79
|
+
write_orders = ShopifyAPI::ApiAccess.new(%w(write_orders))
|
|
80
|
+
|
|
81
|
+
assert write_products_and_orders.covers?(write_orders)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_covers_is_truthy_for_subset_of_scopes
|
|
85
|
+
write_products_orders_customers = ShopifyAPI::ApiAccess.new(%w(write_products write_orders write_customers))
|
|
86
|
+
write_orders_products = ShopifyAPI::ApiAccess.new(%w(write_orders read_products))
|
|
87
|
+
|
|
88
|
+
assert write_products_orders_customers.covers?(write_orders_products)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_covers_is_falsy_for_sets_of_scopes_that_have_no_common_elements
|
|
92
|
+
write_products_orders_customers = ShopifyAPI::ApiAccess.new(%w(write_products write_orders write_customers))
|
|
93
|
+
write_images_read_content = ShopifyAPI::ApiAccess.new(%w(write_images read_content))
|
|
94
|
+
|
|
95
|
+
refute write_products_orders_customers.covers?(write_images_read_content)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_covers_is_falsy_for_sets_of_scopes_that_have_only_some_common_access
|
|
99
|
+
write_products_orders_customers = ShopifyAPI::ApiAccess.new(%w(write_products write_orders write_customers))
|
|
100
|
+
write_products_read_content = ShopifyAPI::ApiAccess.new(%w(write_products read_content))
|
|
101
|
+
|
|
102
|
+
refute write_products_orders_customers.covers?(write_products_read_content)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_duplicate_scopes_resolve_to_one_scope
|
|
106
|
+
read_orders_duplicated = ShopifyAPI::ApiAccess.new(%w(read_orders read_orders read_orders read_orders))
|
|
107
|
+
read_orders = ShopifyAPI::ApiAccess.new(%w(read_orders))
|
|
108
|
+
|
|
109
|
+
assert_equal read_orders, read_orders_duplicated
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def test_to_s_outputs_scopes_as_a_comma_separated_list_without_implied_read_scopes
|
|
113
|
+
serialized_read_products_write_orders = "read_products,write_orders"
|
|
114
|
+
read_products_write_orders = ShopifyAPI::ApiAccess.new(%w(read_products read_orders write_orders))
|
|
115
|
+
|
|
116
|
+
assert_equal read_products_write_orders.to_s, serialized_read_products_write_orders
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def test_to_a_outputs_scopes_as_an_array_of_strings_without_implied_read_scopes
|
|
120
|
+
serialized_read_products_write_orders = %w(write_orders read_products)
|
|
121
|
+
read_products_write_orders = ShopifyAPI::ApiAccess.new(%w(read_products read_orders write_orders))
|
|
122
|
+
|
|
123
|
+
assert_equal read_products_write_orders.to_a.sort, serialized_read_products_write_orders.sort
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def test_creating_scopes_removes_extra_whitespace_from_scope_name_and_blank_scope_names
|
|
127
|
+
deserialized_read_products_write_orders = ShopifyAPI::ApiAccess.new([' read_products', ' ', 'write_orders '])
|
|
128
|
+
serialized_read_products_write_orders = deserialized_read_products_write_orders.to_s
|
|
129
|
+
expected_read_products_write_orders = ShopifyAPI::ApiAccess.new(%w(read_products write_orders))
|
|
130
|
+
|
|
131
|
+
assert_equal expected_read_products_write_orders, ShopifyAPI::ApiAccess.new(serialized_read_products_write_orders)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def test_creating_scopes_from_a_string_works_with_a_comma_separated_list
|
|
135
|
+
deserialized_read_products_write_orders = ShopifyAPI::ApiAccess.new("read_products,write_orders")
|
|
136
|
+
serialized_read_products_write_orders = deserialized_read_products_write_orders.to_s
|
|
137
|
+
expected_read_products_write_orders = ShopifyAPI::ApiAccess.new(%w(read_products write_orders))
|
|
138
|
+
|
|
139
|
+
assert_equal expected_read_products_write_orders, ShopifyAPI::ApiAccess.new(serialized_read_products_write_orders)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def test_using_to_s_from_one_scopes_to_construct_another_will_be_equal
|
|
143
|
+
read_products_write_orders = ShopifyAPI::ApiAccess.new(%w(read_products write_orders))
|
|
144
|
+
|
|
145
|
+
assert_equal read_products_write_orders, ShopifyAPI::ApiAccess.new(read_products_write_orders.to_s)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def test_using_to_a_from_one_scopes_to_construct_another_will_be_equal
|
|
149
|
+
read_products_write_orders = ShopifyAPI::ApiAccess.new(%w(read_products write_orders))
|
|
150
|
+
|
|
151
|
+
assert_equal read_products_write_orders, ShopifyAPI::ApiAccess.new(read_products_write_orders.to_a)
|
|
152
|
+
end
|
|
153
|
+
end
|
data/test/api_version_test.rb
CHANGED
|
@@ -45,7 +45,7 @@ class ApiVersionTest < Test::Unit::TestCase
|
|
|
45
45
|
test "find_version does raise when coercing a string if no versions are defined when version_lookup_mode is :raise_on_unknown" do
|
|
46
46
|
refute ShopifyAPI::ApiVersion.versions['made up version']
|
|
47
47
|
ShopifyAPI::ApiVersion.version_lookup_mode = :raise_on_unknown
|
|
48
|
-
assert_raises
|
|
48
|
+
assert_raises(ShopifyAPI::ApiVersion::UnknownVersion) do
|
|
49
49
|
ShopifyAPI::ApiVersion.find_version('made up version')
|
|
50
50
|
end
|
|
51
51
|
end
|
|
@@ -54,7 +54,7 @@ class ApiVersionTest < Test::Unit::TestCase
|
|
|
54
54
|
ShopifyAPI::ApiVersion.clear_known_versions
|
|
55
55
|
ShopifyAPI::ApiVersion.version_lookup_mode = :define_on_unknown
|
|
56
56
|
assert_equal :define_on_unknown, ShopifyAPI::ApiVersion.version_lookup_mode
|
|
57
|
-
assert_raises
|
|
57
|
+
assert_raises(ArgumentError) do
|
|
58
58
|
ShopifyAPI::ApiVersion.find_version(ShopifyAPI::ApiVersion::NullVersion)
|
|
59
59
|
end
|
|
60
60
|
end
|
|
@@ -108,7 +108,6 @@ class ApiVersionTest < Test::Unit::TestCase
|
|
|
108
108
|
}
|
|
109
109
|
)
|
|
110
110
|
silence_warnings do
|
|
111
|
-
|
|
112
111
|
refute_equal(
|
|
113
112
|
ShopifyAPI::ApiVersion.new(handle: '2019-01'),
|
|
114
113
|
ShopifyAPI::ApiVersion.latest_stable_version
|
|
@@ -151,6 +150,7 @@ class ApiVersionTest < Test::Unit::TestCase
|
|
|
151
150
|
|
|
152
151
|
class TestApiVersion < ShopifyAPI::ApiVersion
|
|
153
152
|
def initialize(name)
|
|
153
|
+
super(name)
|
|
154
154
|
@version_name = name
|
|
155
155
|
end
|
|
156
156
|
end
|
|
@@ -1,79 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'test_helper'
|
|
2
3
|
|
|
3
4
|
class ApplicationChargeTest < Test::Unit::TestCase
|
|
4
|
-
|
|
5
5
|
def test_application_charge_create
|
|
6
|
-
fake
|
|
6
|
+
fake("application_charges", method: :post, status: 201, body: load_fixture('application_charge'))
|
|
7
7
|
|
|
8
8
|
charge = ShopifyAPI::ApplicationCharge.create(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
name: "iPod Cleaning",
|
|
10
|
+
price: 5.00,
|
|
11
|
+
return_url: "http://google.com"
|
|
12
12
|
)
|
|
13
13
|
|
|
14
|
-
assert_equal
|
|
14
|
+
assert_equal(
|
|
15
|
+
'https://this-is-my-test-shop.myshopify.com/admin/charges/803742/confirm_application_charge?' \
|
|
16
|
+
'signature=BAhpA55DDA%3D%3D--55b44e274e438c619be4631c804abcbcb6ee915a',
|
|
17
|
+
charge.confirmation_url
|
|
18
|
+
)
|
|
15
19
|
end
|
|
16
20
|
|
|
17
21
|
def test_get_application_charge
|
|
18
|
-
fake
|
|
22
|
+
fake("application_charges/803742", method: :get, status: 201, body: load_fixture('application_charge'))
|
|
19
23
|
|
|
20
24
|
charge = ShopifyAPI::ApplicationCharge.find(803742)
|
|
21
25
|
|
|
22
|
-
assert_equal
|
|
26
|
+
assert_equal("iPod Cleaning", charge.name)
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
def test_list_application_charges
|
|
26
|
-
fake
|
|
30
|
+
fake("application_charges", method: :get, status: 201, body: load_fixture('application_charges'))
|
|
27
31
|
|
|
28
32
|
charges = ShopifyAPI::ApplicationCharge.find(:all)
|
|
29
33
|
|
|
30
|
-
assert_equal
|
|
31
|
-
assert_equal
|
|
34
|
+
assert_equal(4, charges.size)
|
|
35
|
+
assert_equal("iPhone Case", charges.last.name)
|
|
32
36
|
end
|
|
33
37
|
|
|
34
38
|
def test_list_pending_application_charges
|
|
35
|
-
fake
|
|
39
|
+
fake("application_charges", method: :get, status: 201, body: load_fixture('application_charges'))
|
|
36
40
|
|
|
37
41
|
pending_charges = ShopifyAPI::ApplicationCharge.pending
|
|
38
42
|
|
|
39
|
-
assert_equal
|
|
40
|
-
assert_equal
|
|
43
|
+
assert_equal(1, pending_charges.size)
|
|
44
|
+
assert_equal("Screen Replacement", pending_charges.first.name)
|
|
41
45
|
end
|
|
42
46
|
|
|
43
47
|
def test_list_expired_application_charges
|
|
44
|
-
fake
|
|
48
|
+
fake("application_charges", method: :get, status: 201, body: load_fixture('application_charges'))
|
|
45
49
|
|
|
46
50
|
expired_charges = ShopifyAPI::ApplicationCharge.expired
|
|
47
51
|
|
|
48
|
-
assert_equal
|
|
49
|
-
assert_equal
|
|
52
|
+
assert_equal(1, expired_charges.size)
|
|
53
|
+
assert_equal("iPod Cleaning", expired_charges.first.name)
|
|
50
54
|
end
|
|
51
55
|
|
|
52
56
|
def test_list_accepted_application_charges
|
|
53
|
-
fake
|
|
57
|
+
fake("application_charges", method: :get, status: 201, body: load_fixture('application_charges'))
|
|
54
58
|
|
|
55
59
|
accepted_charges = ShopifyAPI::ApplicationCharge.accepted
|
|
56
60
|
|
|
57
|
-
assert_equal
|
|
58
|
-
assert_equal
|
|
61
|
+
assert_equal(1, accepted_charges.size)
|
|
62
|
+
assert_equal("iPhone Case", accepted_charges.first.name)
|
|
59
63
|
end
|
|
60
64
|
|
|
61
65
|
def test_list_declined_application_charges
|
|
62
|
-
fake
|
|
66
|
+
fake("application_charges", method: :get, status: 201, body: load_fixture('application_charges'))
|
|
63
67
|
|
|
64
68
|
declined_charges = ShopifyAPI::ApplicationCharge.declined
|
|
65
69
|
|
|
66
|
-
assert_equal
|
|
67
|
-
assert_equal
|
|
70
|
+
assert_equal(1, declined_charges.size)
|
|
71
|
+
assert_equal("Magic Mouse", declined_charges.first.name)
|
|
68
72
|
end
|
|
69
73
|
|
|
70
74
|
def test_activate_application_charge
|
|
71
|
-
fake
|
|
72
|
-
fake
|
|
75
|
+
fake("application_charges", method: :get, status: 201, body: load_fixture('application_charges'))
|
|
76
|
+
fake("application_charges/803740/activate", method: :post, status: 200, body: "{}")
|
|
73
77
|
|
|
74
78
|
charge = ShopifyAPI::ApplicationCharge.accepted
|
|
75
79
|
|
|
76
|
-
assert
|
|
80
|
+
assert(charge.last.activate)
|
|
77
81
|
end
|
|
78
|
-
|
|
79
82
|
end
|