shopify_api 4.9.0 → 9.4.1
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 +5 -5
- data/.github/CODEOWNERS +1 -0
- data/.github/ISSUE_TEMPLATE.md +36 -0
- data/.github/probots.yml +2 -0
- data/.github/workflows/build.yml +41 -0
- data/.gitignore +5 -1
- data/.rubocop.yml +28 -0
- data/.rubocop_todo.yml +75 -0
- data/CHANGELOG.md +491 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +6 -2
- data/Gemfile.lock +151 -0
- data/Gemfile_ar41 +5 -0
- data/Gemfile_ar50 +5 -0
- data/Gemfile_ar51 +5 -0
- data/Gemfile_ar_master +0 -1
- data/README.md +492 -100
- data/RELEASING +10 -9
- data/Rakefile +21 -5
- data/SECURITY.md +59 -0
- data/docker-compose.yml +13 -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 +241 -0
- data/docs/index.md +639 -0
- data/lib/active_resource/connection_ext.rb +1 -0
- data/lib/active_resource/detailed_log_subscriber.rb +43 -7
- data/lib/active_resource/json_errors.rb +8 -2
- data/lib/shopify_api.rb +16 -6
- data/lib/shopify_api/api_access.rb +57 -0
- data/lib/shopify_api/api_version.rb +206 -0
- data/lib/shopify_api/connection.rb +7 -4
- data/lib/shopify_api/countable.rb +3 -2
- data/lib/shopify_api/disable_prefix_check.rb +31 -0
- data/lib/shopify_api/events.rb +2 -1
- data/lib/shopify_api/graphql.rb +103 -0
- data/lib/shopify_api/graphql/http_client.rb +22 -0
- data/lib/shopify_api/graphql/railtie.rb +17 -0
- data/lib/shopify_api/graphql/task.rake +100 -0
- data/lib/shopify_api/limits.rb +9 -9
- data/lib/shopify_api/message_enricher.rb +25 -0
- data/lib/shopify_api/meta.rb +14 -0
- data/lib/shopify_api/metafields.rb +5 -4
- data/lib/shopify_api/paginated_collection.rb +69 -0
- data/lib/shopify_api/pagination_link_headers.rb +34 -0
- data/lib/shopify_api/resources.rb +3 -1
- data/lib/shopify_api/resources/abandoned_checkout.rb +7 -0
- data/lib/shopify_api/resources/access_scope.rb +10 -0
- 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/api_permission.rb +9 -0
- 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/array_base.rb +13 -0
- data/lib/shopify_api/resources/article.rb +3 -2
- data/lib/shopify_api/resources/asset.rb +28 -23
- data/lib/shopify_api/resources/assigned_fulfillment_order.rb +16 -0
- data/lib/shopify_api/resources/base.rb +101 -24
- data/lib/shopify_api/resources/billing_address.rb +2 -1
- 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/checkout.rb +27 -1
- data/lib/shopify_api/resources/collect.rb +2 -0
- data/lib/shopify_api/resources/collection.rb +14 -0
- data/lib/shopify_api/resources/collection_listing.rb +11 -1
- data/lib/shopify_api/resources/collection_publication.rb +10 -0
- data/lib/shopify_api/resources/comment.rb +20 -5
- data/lib/shopify_api/resources/country.rb +1 -0
- data/lib/shopify_api/resources/currency.rb +6 -0
- data/lib/shopify_api/resources/custom_collection.rb +7 -6
- 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_message.rb → customer_invite.rb} +1 -0
- data/lib/shopify_api/resources/customer_saved_search.rb +4 -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 +2 -0
- data/lib/shopify_api/resources/fulfillment.rb +46 -3
- data/lib/shopify_api/resources/fulfillment_event.rb +2 -1
- data/lib/shopify_api/resources/fulfillment_order.rb +151 -0
- data/lib/shopify_api/resources/fulfillment_order_locations_for_move.rb +5 -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 +21 -0
- data/lib/shopify_api/resources/gift_card.rb +1 -0
- data/lib/shopify_api/resources/image.rb +4 -3
- data/lib/shopify_api/resources/inventory_item.rb +6 -0
- data/lib/shopify_api/resources/inventory_level.rb +54 -0
- data/lib/shopify_api/resources/line_item.rb +10 -1
- data/lib/shopify_api/resources/location.rb +4 -0
- data/lib/shopify_api/resources/marketing_event.rb +3 -0
- data/lib/shopify_api/resources/metafield.rb +2 -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 +25 -5
- 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.rb +7 -0
- data/lib/shopify_api/resources/payment_details.rb +1 -0
- data/lib/shopify_api/resources/ping.rb +3 -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 +33 -7
- data/lib/shopify_api/resources/product_listing.rb +9 -1
- data/lib/shopify_api/resources/product_publication.rb +10 -0
- data/lib/shopify_api/resources/province.rb +1 -0
- data/lib/shopify_api/resources/publication.rb +5 -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 +6 -4
- 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 +2 -1
- data/lib/shopify_api/resources/shipping_rate.rb +7 -0
- data/lib/shopify_api/resources/shipping_zone.rb +1 -0
- data/lib/shopify_api/resources/shop.rb +10 -7
- data/lib/shopify_api/resources/smart_collection.rb +3 -3
- 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/tender_transaction.rb +6 -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 +109 -45
- data/lib/shopify_api/version.rb +2 -1
- data/lib/verify_docs.rb +8 -0
- data/service.yml +8 -0
- data/shopify_api.gemspec +19 -8
- data/test/abandoned_checkouts_test.rb +29 -0
- data/test/access_scope_test.rb +23 -0
- 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_permission_test.rb +9 -0
- data/test/api_version_test.rb +157 -0
- 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 +78 -0
- data/test/base_test.rb +147 -59
- data/test/blog_test.rb +4 -3
- data/test/carrier_service_test.rb +7 -6
- data/test/cart_test.rb +2 -1
- data/test/checkouts_test.rb +72 -4
- data/test/collect_test.rb +4 -3
- data/test/collection_listing_test.rb +56 -13
- data/test/collection_publication_test.rb +40 -0
- data/test/collection_test.rb +50 -0
- data/test/countable_test.rb +3 -2
- data/test/currency_test.rb +21 -0
- 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 +113 -19
- data/test/discount_code_batch_test.rb +41 -0
- data/test/discount_code_test.rb +22 -16
- data/test/draft_order_test.rb +68 -52
- data/test/fixtures/abandoned_checkout.json +184 -0
- data/test/fixtures/abandoned_checkouts.json +186 -0
- data/test/fixtures/access_scopes.json +10 -0
- data/test/fixtures/api_versions.json +38 -0
- data/test/fixtures/apis.json +42 -0
- data/test/fixtures/assigned_fulfillment_orders.json +80 -0
- data/test/fixtures/checkout.json +160 -0
- data/test/fixtures/checkouts.json +25 -49
- data/test/fixtures/collection.json +17 -0
- data/test/fixtures/collection_listing_product_ids2.json +1 -0
- data/test/fixtures/collection_products.json +47 -0
- data/test/fixtures/collection_publication.json +11 -0
- data/test/fixtures/collection_publications.json +13 -0
- data/test/fixtures/currencies.json +25 -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 +39 -0
- data/test/fixtures/fulfillment_order_locations_for_move.json +18 -0
- data/test/fixtures/fulfillment_orders.json +80 -0
- data/test/fixtures/fulfillments.json +53 -0
- data/test/fixtures/graphql/2019-10.json +1083 -0
- data/test/fixtures/graphql/dummy_schema.rb +16 -0
- data/test/fixtures/graphql/unstable.json +1083 -0
- data/test/fixtures/inventory_level.json +7 -0
- data/test/fixtures/inventory_levels.json +24 -0
- data/test/fixtures/order_with_properties.json +373 -0
- data/test/fixtures/payment.json +7 -0
- data/test/fixtures/payments.json +9 -0
- data/test/fixtures/ping/conversation.json +1 -0
- data/test/fixtures/ping/failed_delivery_confirmation.json +1 -0
- data/test/fixtures/ping/message.json +1 -0
- data/test/fixtures/ping/successful_delivery_confirmation.json +1 -0
- data/test/fixtures/product_listing_product_ids.json +1 -1
- data/test/fixtures/product_listing_product_ids2.json +1 -0
- data/test/fixtures/product_publication.json +11 -0
- data/test/fixtures/product_publications.json +13 -0
- data/test/fixtures/publications.json +9 -0
- data/test/fixtures/shipping_rates.json +12 -0
- data/test/fixtures/smart_collection_products.json +155 -0
- data/test/fixtures/tender_transactions.json +52 -0
- data/test/fulfillment_event_test.rb +31 -26
- data/test/fulfillment_order_test.rb +530 -0
- data/test/fulfillment_order_test_helper.rb +8 -0
- data/test/fulfillment_request_test.rb +10 -8
- data/test/fulfillment_service_test.rb +13 -12
- data/test/fulfillment_test.rb +198 -20
- data/test/fulfillment_v2_test.rb +66 -0
- data/test/gift_card_test.rb +6 -4
- data/test/graphql/http_client_test.rb +26 -0
- data/test/graphql_test.rb +190 -0
- data/test/image_test.rb +19 -17
- data/test/inventory_level_test.rb +68 -0
- data/test/lib/webmock_extensions/last_request.rb +16 -0
- data/test/limits_test.rb +4 -3
- data/test/location_test.rb +15 -0
- data/test/marketing_event_test.rb +21 -21
- data/test/message_enricher_test.rb +45 -0
- data/test/meta_test.rb +47 -0
- data/test/metafield_test.rb +30 -20
- data/test/order_risk_test.rb +17 -16
- data/test/order_test.rb +110 -17
- data/test/pagination_test.rb +290 -0
- data/test/payment_test.rb +19 -0
- data/test/policy_test.rb +6 -5
- data/test/price_rule_test.rb +20 -15
- data/test/product_listing_test.rb +72 -15
- data/test/product_publication_test.rb +40 -0
- data/test/product_test.rb +80 -19
- data/test/publication_test.rb +12 -0
- data/test/recurring_application_charge_test.rb +105 -50
- 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 +497 -111
- data/test/shipping_rate_test.rb +17 -0
- 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 -3
- data/test/tender_transaction_test.rb +18 -0
- data/test/test_helper.rb +98 -67
- 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 -20
- data/test/webhook_test.rb +10 -7
- metadata +196 -37
- data/.travis.yml +0 -36
- data/CHANGELOG +0 -292
- data/Gemfile_ar30 +0 -6
- data/Gemfile_ar31 +0 -6
- data/Gemfile_ar32 +0 -6
- data/Gemfile_ar40 +0 -6
- data/bin/shopify +0 -3
- data/lib/active_resource/base_ext.rb +0 -21
- data/lib/active_resource/disable_prefix_check.rb +0 -36
- data/lib/active_resource/to_query.rb +0 -10
- data/lib/shopify_api/json_format.rb +0 -18
- data/lib/shopify_api/resources/discount.rb +0 -11
- data/lib/shopify_api/resources/o_auth.rb +0 -9
- data/test/discount_test.rb +0 -52
- data/test/fixtures/discount.json +0 -17
- data/test/fixtures/discount_disabled.json +0 -17
- data/test/fixtures/discounts.json +0 -34
- data/test/fixtures/o_auth_revoke.json +0 -5
- data/test/o_auth_test.rb +0 -8
data/lib/shopify_api/version.rb
CHANGED
data/lib/verify_docs.rb
ADDED
data/service.yml
ADDED
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,30 +8,40 @@ 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}
|
|
24
31
|
s.license = "MIT"
|
|
25
32
|
|
|
26
|
-
s.required_ruby_version = ">= 2.
|
|
33
|
+
s.required_ruby_version = ">= 2.4"
|
|
27
34
|
|
|
28
|
-
s.add_runtime_dependency("activeresource", ">=
|
|
35
|
+
s.add_runtime_dependency("activeresource", ">= 4.1.0", "< 6.0.0")
|
|
29
36
|
s.add_runtime_dependency("rack")
|
|
37
|
+
s.add_runtime_dependency("graphql-client")
|
|
30
38
|
|
|
31
|
-
s.add_development_dependency("mocha", ">=
|
|
32
|
-
s.add_development_dependency("
|
|
39
|
+
s.add_development_dependency("mocha", ">= 1.4.0")
|
|
40
|
+
s.add_development_dependency("webmock")
|
|
33
41
|
s.add_development_dependency("minitest", ">= 4.0")
|
|
34
42
|
s.add_development_dependency("rake")
|
|
35
43
|
s.add_development_dependency("timecop")
|
|
44
|
+
s.add_development_dependency("rubocop-shopify")
|
|
45
|
+
s.add_development_dependency("pry")
|
|
46
|
+
s.add_development_dependency("pry-byebug")
|
|
36
47
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'test_helper'
|
|
3
|
+
|
|
4
|
+
class AbandonedCheckoutsTest < Test::Unit::TestCase
|
|
5
|
+
def setup
|
|
6
|
+
super
|
|
7
|
+
|
|
8
|
+
@expected_checkouts = JSON.parse(load_fixture('abandoned_checkouts'))['checkouts']
|
|
9
|
+
@expected_checkout_id = JSON.parse(load_fixture('abandoned_checkout'))['checkout']['id']
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test ":create creates a checkout" do
|
|
13
|
+
fake 'checkouts', method: :post, status: 201, body: load_fixture('abandoned_checkout')
|
|
14
|
+
|
|
15
|
+
checkout = ShopifyAPI::AbandonedCheckout.create
|
|
16
|
+
|
|
17
|
+
assert_equal @expected_checkout_id, checkout.id
|
|
18
|
+
assert_equal true, checkout.attributes.include?(:abandoned_checkout_url)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test "get all checkouts indexed by token" do
|
|
22
|
+
fake 'checkouts', method: :get, status: 200, body: load_fixture('abandoned_checkouts')
|
|
23
|
+
|
|
24
|
+
checkouts = ShopifyAPI::AbandonedCheckout.all
|
|
25
|
+
|
|
26
|
+
assert_equal @expected_checkout_id, checkouts.first.id
|
|
27
|
+
assert_equal @expected_checkouts.size, checkouts.size
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'test_helper'
|
|
3
|
+
|
|
4
|
+
class AccessScopeTest < Test::Unit::TestCase
|
|
5
|
+
test 'access scope does not use the versioned resource urls' do
|
|
6
|
+
fake(
|
|
7
|
+
'access_scopes',
|
|
8
|
+
url: 'https://shop2.myshopify.com/admin/oauth/access_scopes.json',
|
|
9
|
+
method: :get,
|
|
10
|
+
status: 201,
|
|
11
|
+
body: load_fixture('access_scopes'),
|
|
12
|
+
extension: false
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
unstable_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: :unstable)
|
|
16
|
+
|
|
17
|
+
ShopifyAPI::Base.activate_session(unstable_version)
|
|
18
|
+
|
|
19
|
+
scope_handles = ShopifyAPI::AccessScope.find(:all).map(&:handle)
|
|
20
|
+
|
|
21
|
+
assert_equal(['write_product_listings', 'read_shipping'], scope_handles)
|
|
22
|
+
end
|
|
23
|
+
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
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'test_helper'
|
|
3
|
+
|
|
4
|
+
class ApiPermissionTest < Test::Unit::TestCase
|
|
5
|
+
test "revoke access token" do
|
|
6
|
+
fake "api_permissions/current", method: :delete, status: 200, body: "{}"
|
|
7
|
+
assert ShopifyAPI::ApiPermission.destroy
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'test_helper'
|
|
3
|
+
|
|
4
|
+
class ApiVersionTest < Test::Unit::TestCase
|
|
5
|
+
test "find_version returns any version object given" do
|
|
6
|
+
version = ShopifyAPI::ApiVersion.new(handle: :unstable)
|
|
7
|
+
assert_same(version, ShopifyAPI::ApiVersion.find_version(version))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test "find_version converts a known version into a version object" do
|
|
11
|
+
versions = [
|
|
12
|
+
ShopifyAPI::ApiVersion.new(handle: :unstable),
|
|
13
|
+
ShopifyAPI::ApiVersion.new(handle: '2019-01'),
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
assert_equal(versions, [
|
|
17
|
+
ShopifyAPI::ApiVersion.find_version('unstable'),
|
|
18
|
+
ShopifyAPI::ApiVersion.find_version('2019-01'),
|
|
19
|
+
])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
test "find_version removes unverified versions from version set if mode is set to :raise_on_unknown" do
|
|
23
|
+
ShopifyAPI::ApiVersion.version_lookup_mode = :define_on_unknown
|
|
24
|
+
assert ShopifyAPI::ApiVersion.versions.values.all?(&:verified?)
|
|
25
|
+
assert_equal 6, ShopifyAPI::ApiVersion.versions.size
|
|
26
|
+
|
|
27
|
+
ShopifyAPI::ApiVersion.find_version('2019-30')
|
|
28
|
+
refute ShopifyAPI::ApiVersion.versions.values.all?(&:verified?)
|
|
29
|
+
assert_equal 7, ShopifyAPI::ApiVersion.versions.size
|
|
30
|
+
ShopifyAPI::ApiVersion.version_lookup_mode = :raise_on_unknown
|
|
31
|
+
|
|
32
|
+
assert ShopifyAPI::ApiVersion.versions.values.all?(&:verified?)
|
|
33
|
+
assert_equal 6, ShopifyAPI::ApiVersion.versions.size
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test "find_version does not raise when coercing a string if no versions are defined when version_lookup_mode is :define_on_unknown" do
|
|
37
|
+
ShopifyAPI::ApiVersion.clear_known_versions
|
|
38
|
+
ShopifyAPI::ApiVersion.version_lookup_mode = :define_on_unknown
|
|
39
|
+
assert_equal :define_on_unknown, ShopifyAPI::ApiVersion.version_lookup_mode
|
|
40
|
+
assert_nothing_raised do
|
|
41
|
+
ShopifyAPI::ApiVersion.find_version('made up version')
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
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
|
+
refute ShopifyAPI::ApiVersion.versions['made up version']
|
|
47
|
+
ShopifyAPI::ApiVersion.version_lookup_mode = :raise_on_unknown
|
|
48
|
+
assert_raises(ShopifyAPI::ApiVersion::UnknownVersion) do
|
|
49
|
+
ShopifyAPI::ApiVersion.find_version('made up version')
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
test "find_version raises ArgumentError when given an ShopifyAPI::ApiVersion::NullVersion object" do
|
|
54
|
+
ShopifyAPI::ApiVersion.clear_known_versions
|
|
55
|
+
ShopifyAPI::ApiVersion.version_lookup_mode = :define_on_unknown
|
|
56
|
+
assert_equal :define_on_unknown, ShopifyAPI::ApiVersion.version_lookup_mode
|
|
57
|
+
assert_raises(ArgumentError) do
|
|
58
|
+
ShopifyAPI::ApiVersion.find_version(ShopifyAPI::ApiVersion::NullVersion)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
test 'two versions with the same version number are equal' do
|
|
63
|
+
version_1 = ShopifyAPI::ApiVersion.new(handle: '2018-09')
|
|
64
|
+
version_2 = ShopifyAPI::ApiVersion.new(handle: '2018-09')
|
|
65
|
+
|
|
66
|
+
assert_equal version_2, version_1
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
test 'two versions with the different version numbers are not equal' do
|
|
70
|
+
version_1 = ShopifyAPI::ApiVersion.new(handle: '2019-07')
|
|
71
|
+
version_2 = ShopifyAPI::ApiVersion.new(handle: '2019-11')
|
|
72
|
+
|
|
73
|
+
refute_equal version_2, version_1
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
test 'versions are ordered by version number with unstable always being the newest' do
|
|
77
|
+
version_1 = ShopifyAPI::ApiVersion.new(handle: '2017-11')
|
|
78
|
+
version_2 = ShopifyAPI::ApiVersion.new(handle: '2019-11')
|
|
79
|
+
version_3 = ShopifyAPI::ApiVersion.new(handle: '2039-01')
|
|
80
|
+
version_4 = ShopifyAPI::ApiVersion.new(handle: '2039-02')
|
|
81
|
+
unstable = ShopifyAPI::ApiVersion.new(handle: :unstable)
|
|
82
|
+
|
|
83
|
+
assert_equal([
|
|
84
|
+
version_1,
|
|
85
|
+
version_2,
|
|
86
|
+
version_3,
|
|
87
|
+
version_4,
|
|
88
|
+
unstable,
|
|
89
|
+
], [
|
|
90
|
+
version_3,
|
|
91
|
+
version_1,
|
|
92
|
+
version_4,
|
|
93
|
+
unstable,
|
|
94
|
+
version_2,
|
|
95
|
+
].sort)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
test 'latest_stable_version will return the version that is newest and stable' do
|
|
99
|
+
assert_equal(
|
|
100
|
+
ShopifyAPI::ApiVersion.versions,
|
|
101
|
+
{
|
|
102
|
+
"2019-01" => ShopifyAPI::ApiVersion.new(handle: '2019-01', supported: true, latest_supported: false),
|
|
103
|
+
"2019-04" => ShopifyAPI::ApiVersion.new(handle: '2019-04', supported: true, latest_supported: false),
|
|
104
|
+
"2019-07" => ShopifyAPI::ApiVersion.new(handle: '2019-07', supported: true, latest_supported: false),
|
|
105
|
+
"2019-10" => ShopifyAPI::ApiVersion.new(handle: '2019-10', supported: false, latest_supported: false),
|
|
106
|
+
"2020-01" => ShopifyAPI::ApiVersion.new(handle: '2020-01', supported: false, latest_supported: true),
|
|
107
|
+
"unstable" => ShopifyAPI::ApiVersion.new(handle: 'unstable', supported: false, latest_supported: false),
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
silence_warnings do
|
|
111
|
+
refute_equal(
|
|
112
|
+
ShopifyAPI::ApiVersion.new(handle: '2019-01'),
|
|
113
|
+
ShopifyAPI::ApiVersion.latest_stable_version
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
assert_equal(
|
|
117
|
+
ShopifyAPI::ApiVersion.new(handle: '2020-01'),
|
|
118
|
+
ShopifyAPI::ApiVersion.latest_stable_version
|
|
119
|
+
)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
test "NullVersion raises ApiVersionNotSetError" do
|
|
124
|
+
assert_raises(ShopifyAPI::ApiVersion::ApiVersionNotSetError) do
|
|
125
|
+
ShopifyAPI::ApiVersion::NullVersion.construct_api_path(:string)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
assert_raises(ShopifyAPI::ApiVersion::ApiVersionNotSetError) do
|
|
129
|
+
ShopifyAPI::ApiVersion::NullVersion.construct_graphql_path
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
assert_raises(ShopifyAPI::ApiVersion::ApiVersionNotSetError) do
|
|
133
|
+
ShopifyAPI::ApiVersion::NullVersion.stable?
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
test "NullVersion cannot be instantiated and raises NoMethodError if attempted" do
|
|
138
|
+
assert_raises(NoMethodError) do
|
|
139
|
+
ShopifyAPI::ApiVersion::NullVersion.new
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
test "handle_to_date converts a version handle to a date" do
|
|
144
|
+
version_1 = ShopifyAPI::ApiVersion.new(handle: '2019-01')
|
|
145
|
+
version_2 = ShopifyAPI::ApiVersion.new(handle: 'unstable')
|
|
146
|
+
|
|
147
|
+
assert_equal(version_1.handle_as_date, Time.utc(2019, 01, 01))
|
|
148
|
+
assert_equal(version_2.handle_as_date, ShopifyAPI::ApiVersion::UNSTABLE_AS_DATE)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
class TestApiVersion < ShopifyAPI::ApiVersion
|
|
152
|
+
def initialize(name)
|
|
153
|
+
super(name)
|
|
154
|
+
@version_name = name
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|