shopify_api 9.0.2 → 9.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +36 -0
- data/.github/workflows/build.yml +41 -0
- data/.gitignore +2 -1
- data/.rubocop.yml +23 -3
- data/.rubocop_todo.yml +75 -0
- data/CHANGELOG.md +43 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +5 -0
- data/Gemfile.lock +151 -0
- data/Gemfile_ar51 +1 -1
- data/README.md +47 -31
- data/RELEASING +10 -6
- data/Rakefile +16 -5
- data/SECURITY.md +59 -0
- data/docs/_config.yml +1 -0
- data/docs/_includes/footer.html +28 -0
- data/docs/_includes/head.html +28 -0
- data/docs/_layouts/index.html +57 -0
- data/docs/graphql.md +47 -2
- data/docs/index.md +639 -0
- 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 +28 -8
- 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 +5 -4
- 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 +12 -8
- 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 +34 -0
- 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 +3 -4
- 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 +27 -3
- 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 +4 -8
- 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 +35 -0
- data/lib/shopify_api/resources/webhook.rb +1 -0
- data/lib/shopify_api/session.rb +43 -14
- data/lib/shopify_api/version.rb +2 -1
- data/lib/verify_docs.rb +8 -0
- data/service.yml +1 -1
- data/shopify_api.gemspec +13 -6
- 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 +64 -49
- 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 +41 -0
- 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/discount_code_batch.json +14 -0
- data/test/fixtures/discount_code_batch_discount_codes.json +21 -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 +55 -23
- 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 +71 -20
- 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 +234 -43
- data/test/shipping_zone_test.rb +4 -3
- data/test/shop_test.rb +47 -33
- data/test/smart_collection_test.rb +5 -29
- 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 +14 -12
- 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 +50 -23
- data/test/webhook_test.rb +10 -7
- metadata +30 -15
- data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
- data/.travis.yml +0 -23
- data/bin/shopify +0 -3
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,12 +17,11 @@ 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
|
-
def temp(domain:, token:, api_version
|
24
|
+
def temp(domain:, token:, api_version: ShopifyAPI::Base.api_version, &block)
|
24
25
|
session = new(domain: domain, token: token, api_version: api_version)
|
25
26
|
|
26
27
|
with_session(session, &block)
|
@@ -28,12 +29,17 @@ module ShopifyAPI
|
|
28
29
|
|
29
30
|
def with_session(session, &_block)
|
30
31
|
original_session = extract_current_session
|
32
|
+
original_user = ShopifyAPI::Base.user
|
33
|
+
original_password = ShopifyAPI::Base.password
|
31
34
|
|
32
35
|
begin
|
36
|
+
ShopifyAPI::Base.clear_session
|
33
37
|
ShopifyAPI::Base.activate_session(session)
|
34
38
|
yield
|
35
39
|
ensure
|
36
40
|
ShopifyAPI::Base.activate_session(original_session)
|
41
|
+
ShopifyAPI::Base.user = original_user
|
42
|
+
ShopifyAPI::Base.password = original_password
|
37
43
|
end
|
38
44
|
end
|
39
45
|
|
@@ -51,7 +57,7 @@ module ShopifyAPI
|
|
51
57
|
# extract host, removing any username, password or path
|
52
58
|
shop = URI.parse("https://#{domain}").host
|
53
59
|
# extract subdomain of .myshopify.com
|
54
|
-
if idx = shop.index(".")
|
60
|
+
if (idx = shop.index("."))
|
55
61
|
shop = shop.slice(0, idx)
|
56
62
|
end
|
57
63
|
return nil if shop.empty?
|
@@ -62,9 +68,11 @@ module ShopifyAPI
|
|
62
68
|
|
63
69
|
def validate_signature(params)
|
64
70
|
params = (params.respond_to?(:to_unsafe_hash) ? params.to_unsafe_hash : params).with_indifferent_access
|
65
|
-
return false unless signature = params[:hmac]
|
71
|
+
return false unless (signature = params[:hmac])
|
66
72
|
|
67
|
-
calculated_signature = OpenSSL::HMAC.hexdigest(
|
73
|
+
calculated_signature = OpenSSL::HMAC.hexdigest(
|
74
|
+
OpenSSL::Digest.new('SHA256'), secret, encoded_params_for_signature(params)
|
75
|
+
)
|
68
76
|
|
69
77
|
Rack::Utils.secure_compare(calculated_signature, signature)
|
70
78
|
end
|
@@ -73,7 +81,7 @@ module ShopifyAPI
|
|
73
81
|
|
74
82
|
def encoded_params_for_signature(params)
|
75
83
|
params = params.except(:signature, :hmac, :action, :controller)
|
76
|
-
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('&')
|
77
85
|
end
|
78
86
|
|
79
87
|
def extract_current_session
|
@@ -84,7 +92,7 @@ module ShopifyAPI
|
|
84
92
|
end
|
85
93
|
end
|
86
94
|
|
87
|
-
def initialize(domain:, token:, api_version
|
95
|
+
def initialize(domain:, token:, api_version: ShopifyAPI::Base.api_version, extra: {})
|
88
96
|
self.domain = self.class.prepare_domain(domain)
|
89
97
|
self.api_version = api_version
|
90
98
|
self.token = token
|
@@ -92,7 +100,7 @@ module ShopifyAPI
|
|
92
100
|
end
|
93
101
|
|
94
102
|
def create_permission_url(scope, redirect_uri, options = {})
|
95
|
-
params = { client_id: api_key, scope:
|
103
|
+
params = { client_id: api_key, scope: ShopifyAPI::ApiAccess.new(scope).to_s, redirect_uri: redirect_uri }
|
96
104
|
params[:state] = options[:state] if options[:state]
|
97
105
|
construct_oauth_url("authorize", params)
|
98
106
|
end
|
@@ -100,7 +108,8 @@ module ShopifyAPI
|
|
100
108
|
def request_token(params)
|
101
109
|
return token if token
|
102
110
|
|
103
|
-
|
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
|
104
113
|
raise ShopifyAPI::ValidationException, "Invalid Signature: Possible malicious login"
|
105
114
|
end
|
106
115
|
|
@@ -109,12 +118,12 @@ module ShopifyAPI
|
|
109
118
|
self.extra = JSON.parse(response.body)
|
110
119
|
self.token = extra.delete('access_token')
|
111
120
|
|
112
|
-
if expires_in = extra.delete('expires_in')
|
121
|
+
if (expires_in = extra.delete('expires_in'))
|
113
122
|
extra['expires_at'] = Time.now.utc.to_i + expires_in
|
114
123
|
end
|
115
124
|
token
|
116
125
|
else
|
117
|
-
raise
|
126
|
+
raise response.msg
|
118
127
|
end
|
119
128
|
end
|
120
129
|
|
@@ -127,7 +136,11 @@ module ShopifyAPI
|
|
127
136
|
end
|
128
137
|
|
129
138
|
def api_version=(version)
|
130
|
-
@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
|
131
144
|
end
|
132
145
|
|
133
146
|
def valid?
|
@@ -149,6 +162,22 @@ module ShopifyAPI
|
|
149
162
|
expires_in <= 0
|
150
163
|
end
|
151
164
|
|
165
|
+
def hash
|
166
|
+
state.hash
|
167
|
+
end
|
168
|
+
|
169
|
+
def ==(other)
|
170
|
+
self.class == other.class && state == other.state
|
171
|
+
end
|
172
|
+
|
173
|
+
alias_method :eql?, :==
|
174
|
+
|
175
|
+
protected
|
176
|
+
|
177
|
+
def state
|
178
|
+
[domain, token, api_version, extra]
|
179
|
+
end
|
180
|
+
|
152
181
|
private
|
153
182
|
|
154
183
|
def parameterize(params)
|
data/lib/shopify_api/version.rb
CHANGED
data/lib/verify_docs.rb
ADDED
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,17 +8,23 @@ 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
|
|
20
|
+
s.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
|
14
22
|
s.extra_rdoc_files = [
|
15
23
|
"LICENSE",
|
16
|
-
"README.md"
|
24
|
+
"README.md",
|
17
25
|
]
|
18
26
|
s.files = `git ls-files`.split("\n")
|
19
27
|
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
20
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
28
|
|
22
29
|
s.rdoc_options = ["--charset=UTF-8"]
|
23
30
|
s.summary = %q{ShopifyAPI is a lightweight gem for accessing the Shopify admin REST web services}
|
@@ -29,12 +36,12 @@ Gem::Specification.new do |s|
|
|
29
36
|
s.add_runtime_dependency("rack")
|
30
37
|
s.add_runtime_dependency("graphql-client")
|
31
38
|
|
32
|
-
s.add_development_dependency("mocha", ">=
|
39
|
+
s.add_development_dependency("mocha", ">= 1.4.0")
|
33
40
|
s.add_development_dependency("webmock")
|
34
41
|
s.add_development_dependency("minitest", ">= 4.0")
|
35
42
|
s.add_development_dependency("rake")
|
36
43
|
s.add_development_dependency("timecop")
|
37
|
-
s.add_development_dependency("rubocop")
|
44
|
+
s.add_development_dependency("rubocop-shopify")
|
38
45
|
s.add_development_dependency("pry")
|
39
46
|
s.add_development_dependency("pry-byebug")
|
40
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
|