shopify_api 9.2.0 → 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 +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
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class ApplicationCreditTest < Test::Unit::TestCase
|
4
5
|
def test_application_credit_create
|
5
|
-
fake
|
6
|
+
fake("application_credits", method: :post, status: 201, body: load_fixture('application_credit'))
|
6
7
|
|
7
8
|
credit = ShopifyAPI::ApplicationCredit.create(
|
8
9
|
description: "refund for application charge",
|
@@ -11,25 +12,25 @@ class ApplicationCreditTest < Test::Unit::TestCase
|
|
11
12
|
shop_id: 487168
|
12
13
|
)
|
13
14
|
|
14
|
-
assert_equal
|
15
|
-
assert_equal
|
15
|
+
assert_equal('refund for application charge', credit.description)
|
16
|
+
assert_equal('5.00', credit.amount)
|
16
17
|
end
|
17
18
|
|
18
19
|
def test_get_application_credit
|
19
|
-
fake
|
20
|
+
fake("application_credits/803742", method: :get, status: 201, body: load_fixture('application_credit'))
|
20
21
|
|
21
22
|
credit = ShopifyAPI::ApplicationCredit.find(803742)
|
22
23
|
|
23
|
-
assert_equal
|
24
|
-
assert_equal
|
24
|
+
assert_equal('refund for application charge', credit.description)
|
25
|
+
assert_equal('5.00', credit.amount)
|
25
26
|
end
|
26
27
|
|
27
28
|
def test_list_application_credits
|
28
|
-
fake
|
29
|
+
fake("application_credits", method: :get, status: 201, body: load_fixture('application_credits'))
|
29
30
|
|
30
31
|
credit = ShopifyAPI::ApplicationCredit.find(:all)
|
31
32
|
|
32
|
-
assert_equal
|
33
|
-
assert_equal
|
33
|
+
assert_equal(2, credit.size)
|
34
|
+
assert_equal('10.00', credit.last.amount)
|
34
35
|
end
|
35
36
|
end
|
data/test/article_test.rb
CHANGED
@@ -1,73 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class ArticleTest < Test::Unit::TestCase
|
4
|
-
|
5
5
|
def test_create_article
|
6
|
-
fake
|
7
|
-
article = ShopifyAPI::Article.new(:
|
6
|
+
fake("blogs/1008414260/articles", method: :post, body: load_fixture('article'))
|
7
|
+
article = ShopifyAPI::Article.new(blog_id: 1008414260)
|
8
8
|
article.save
|
9
|
-
assert_equal
|
9
|
+
assert_equal("First Post", article.title)
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_get_article
|
13
|
-
fake
|
13
|
+
fake("articles/6242736", method: :get, body: load_fixture('article'))
|
14
14
|
article = ShopifyAPI::Article.find(6242736)
|
15
|
-
assert_equal
|
16
|
-
assert_equal
|
15
|
+
assert_equal("First Post", article.title)
|
16
|
+
assert_equal(1008414260, article.blog_id)
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_get_articles
|
20
|
-
fake
|
20
|
+
fake("articles", method: :get, body: load_fixture('articles'))
|
21
21
|
articles = ShopifyAPI::Article.all
|
22
|
-
assert_equal
|
23
|
-
assert_equal
|
22
|
+
assert_equal(3, articles.length)
|
23
|
+
assert_equal(1008414260, articles.first.blog_id)
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_get_articles_namespaced
|
27
|
-
fake
|
28
|
-
articles = ShopifyAPI::Article.find(:all, :
|
29
|
-
assert_equal
|
30
|
-
assert_equal
|
27
|
+
fake("blogs/1008414260/articles", method: :get, body: load_fixture('articles'))
|
28
|
+
articles = ShopifyAPI::Article.find(:all, params: { blog_id: 1008414260 })
|
29
|
+
assert_equal(3, articles.length)
|
30
|
+
assert_equal(1008414260, articles.first.blog_id)
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_get_article_namespaced
|
34
|
-
fake
|
35
|
-
article = ShopifyAPI::Article.find(6242736, :
|
36
|
-
assert_equal
|
37
|
-
assert_equal
|
34
|
+
fake("blogs/1008414260/articles/6242736", method: :get, body: load_fixture('article'))
|
35
|
+
article = ShopifyAPI::Article.find(6242736, params: { blog_id: 1008414260 })
|
36
|
+
assert_equal("First Post", article.title)
|
37
|
+
assert_equal(1008414260, article.blog_id)
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_get_authors
|
41
|
-
fake
|
41
|
+
fake("articles/authors", method: :get, body: load_fixture('authors'))
|
42
42
|
authors = ShopifyAPI::Article.authors
|
43
|
-
assert_equal
|
44
|
-
assert_equal
|
43
|
+
assert_equal("Shopify", authors.first)
|
44
|
+
assert_equal("development shop", authors.last)
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_get_authors_for_blog_id
|
48
|
-
fake
|
49
|
-
authors = ShopifyAPI::Article.authors(:
|
50
|
-
assert_equal
|
48
|
+
fake("blogs/1008414260/articles/authors", method: :get, body: load_fixture('authors'))
|
49
|
+
authors = ShopifyAPI::Article.authors(blog_id: 1008414260)
|
50
|
+
assert_equal(3, authors.length)
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_get_tags
|
54
|
-
fake
|
54
|
+
fake("articles/tags", method: :get, body: load_fixture('tags'))
|
55
55
|
tags = ShopifyAPI::Article.tags
|
56
|
-
assert_equal
|
57
|
-
assert_equal
|
56
|
+
assert_equal("consequuntur", tags.first)
|
57
|
+
assert_equal("repellendus", tags.last)
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_get_tags_for_blog_id
|
61
|
-
fake
|
62
|
-
tags = ShopifyAPI::Article.tags(:
|
63
|
-
assert_equal
|
64
|
-
assert_equal
|
61
|
+
fake("blogs/1008414260/articles/tags", method: :get, body: load_fixture('tags'))
|
62
|
+
tags = ShopifyAPI::Article.tags(blog_id: 1008414260)
|
63
|
+
assert_equal("consequuntur", tags.first)
|
64
|
+
assert_equal("repellendus", tags.last)
|
65
65
|
end
|
66
66
|
|
67
67
|
def test_get_popular_tags
|
68
|
-
fake
|
69
|
-
tags = ShopifyAPI::Article.tags(:
|
70
|
-
assert_equal
|
68
|
+
fake("articles/tags.json?limit=1&popular=1", extension: false, method: :get, body: load_fixture('tags'))
|
69
|
+
tags = ShopifyAPI::Article.tags(popular: 1, limit: 1)
|
70
|
+
assert_equal(3, tags.length)
|
71
71
|
end
|
72
|
-
|
73
72
|
end
|
data/test/asset_test.rb
CHANGED
@@ -1,18 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class AssetTest < Test::Unit::TestCase
|
4
5
|
def test_get_assetss
|
5
|
-
fake
|
6
|
-
|
6
|
+
fake("themes/1/assets", method: :get, body: load_fixture('assets'))
|
7
|
+
ShopifyAPI::Asset.find(:all, params: { theme_id: 1 })
|
7
8
|
end
|
8
9
|
|
9
10
|
def test_get_asset_namespaced
|
10
|
-
fake
|
11
|
-
|
11
|
+
fake(
|
12
|
+
"themes/1/assets.json?asset%5Bkey%5D=templates%2Findex.liquid&theme_id=1",
|
13
|
+
extension: false,
|
14
|
+
method: :get,
|
15
|
+
body: load_fixture('asset')
|
16
|
+
)
|
17
|
+
ShopifyAPI::Asset.find('templates/index.liquid', params: { theme_id: 1 })
|
12
18
|
end
|
13
19
|
|
14
20
|
def test_get_asset
|
15
|
-
fake
|
16
|
-
|
21
|
+
fake(
|
22
|
+
"assets.json?asset%5Bkey%5D=templates%2Findex.liquid", extension: false, method: :get, body: load_fixture('asset')
|
23
|
+
)
|
24
|
+
ShopifyAPI::Asset.find('templates/index.liquid')
|
17
25
|
end
|
18
26
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
require 'fulfillment_order_test_helper'
|
3
4
|
|
@@ -15,7 +16,7 @@ class AssignedFulFillmentOrderTest < Test::Unit::TestCase
|
|
15
16
|
should "raise NotImplementedError when api_version is older than 2020-01" do
|
16
17
|
url_prefix_for_activated_session_for('2019-10')
|
17
18
|
|
18
|
-
assert_raises
|
19
|
+
assert_raises(NotImplementedError) do
|
19
20
|
ShopifyAPI::AssignedFulfillmentOrder.new(ActiveSupport::JSON.decode(@fulfillment_order_fixture))
|
20
21
|
end
|
21
22
|
end
|
@@ -31,7 +32,7 @@ class AssignedFulFillmentOrderTest < Test::Unit::TestCase
|
|
31
32
|
body: @fulfillment_order_fixture,
|
32
33
|
extension: false
|
33
34
|
|
34
|
-
assert_raises
|
35
|
+
assert_raises(NotImplementedError) do
|
35
36
|
ShopifyAPI::AssignedFulfillmentOrder.all(params: { assigned_status: 'cancellation_requested' })
|
36
37
|
end
|
37
38
|
end
|
@@ -44,7 +45,7 @@ class AssignedFulFillmentOrderTest < Test::Unit::TestCase
|
|
44
45
|
extension: false
|
45
46
|
|
46
47
|
assigned_fulfillment_orders = ShopifyAPI::AssignedFulfillmentOrder.all(
|
47
|
-
|
48
|
+
params: { assigned_status: 'cancellation_requested' }
|
48
49
|
)
|
49
50
|
|
50
51
|
assert_equal 2, assigned_fulfillment_orders.count
|
@@ -63,7 +64,7 @@ class AssignedFulFillmentOrderTest < Test::Unit::TestCase
|
|
63
64
|
body: @fulfillment_order_fixture, extension: false
|
64
65
|
|
65
66
|
assigned_fulfillment_orders = ShopifyAPI::AssignedFulfillmentOrder.all(
|
66
|
-
|
67
|
+
params: { location_ids: [assigned_location_id] }
|
67
68
|
)
|
68
69
|
|
69
70
|
assert_equal 2, assigned_fulfillment_orders.count
|
data/test/base_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'test_helper'
|
2
3
|
require "active_support/log_subscriber/test_helper"
|
3
4
|
|
@@ -14,93 +15,92 @@ class BaseTest < Test::Unit::TestCase
|
|
14
15
|
end
|
15
16
|
|
16
17
|
test '#activate_session should set site and headers for given session' do
|
17
|
-
ShopifyAPI::Base.activate_session
|
18
|
+
ShopifyAPI::Base.activate_session(@session1)
|
18
19
|
|
19
|
-
assert_nil
|
20
|
-
assert_equal
|
21
|
-
assert_equal
|
20
|
+
assert_nil(ActiveResource::Base.site)
|
21
|
+
assert_equal('https://shop1.myshopify.com', ShopifyAPI::Base.site.to_s)
|
22
|
+
assert_equal('https://shop1.myshopify.com', ShopifyAPI::Shop.site.to_s)
|
22
23
|
|
23
|
-
assert_nil
|
24
|
-
assert_equal
|
25
|
-
assert_equal
|
24
|
+
assert_nil(ActiveResource::Base.headers['X-Shopify-Access-Token'])
|
25
|
+
assert_equal('token1', ShopifyAPI::Base.headers['X-Shopify-Access-Token'])
|
26
|
+
assert_equal('token1', ShopifyAPI::Shop.headers['X-Shopify-Access-Token'])
|
26
27
|
end
|
27
28
|
|
28
29
|
test '#clear_session should clear base site settings from Base' do
|
29
30
|
ShopifyAPI::Base.site = "https://foo:bar@www.zombo.com"
|
30
31
|
|
31
|
-
assert_equal
|
32
|
-
assert_equal
|
32
|
+
assert_equal("foo", ShopifyAPI::Base.user)
|
33
|
+
assert_equal("bar", ShopifyAPI::Base.password)
|
33
34
|
|
34
35
|
ShopifyAPI::Base.clear_session
|
35
36
|
|
36
|
-
assert_nil
|
37
|
-
assert_nil
|
38
|
-
assert_nil
|
37
|
+
assert_nil(ShopifyAPI::Base.user)
|
38
|
+
assert_nil(ShopifyAPI::Base.password)
|
39
|
+
assert_nil(ShopifyAPI::Base.site)
|
39
40
|
end
|
40
41
|
|
41
42
|
# test to check session reset api version remains the same after session reset
|
42
43
|
test '#clear_session should not change the api_version' do
|
43
44
|
ShopifyAPI::Base.site = "https://zoo:lion@www.zoo.com"
|
44
45
|
|
45
|
-
|
46
|
-
assert_equal
|
47
|
-
assert_equal "lion", ShopifyAPI::Base.password
|
46
|
+
assert_equal("zoo", ShopifyAPI::Base.user)
|
47
|
+
assert_equal("lion", ShopifyAPI::Base.password)
|
48
48
|
|
49
49
|
ShopifyAPI::Base.clear_session
|
50
50
|
|
51
|
-
assert_nil
|
52
|
-
assert_nil
|
53
|
-
assert_nil
|
54
|
-
assert_equal
|
51
|
+
assert_nil(ShopifyAPI::Base.user)
|
52
|
+
assert_nil(ShopifyAPI::Base.password)
|
53
|
+
assert_nil(ShopifyAPI::Base.site)
|
54
|
+
assert_equal(ShopifyAPI::Base.api_version, @session1.api_version)
|
55
55
|
end
|
56
56
|
|
57
57
|
test '#clear_session should clear site and headers from Base' do
|
58
|
-
ShopifyAPI::Base.activate_session
|
58
|
+
ShopifyAPI::Base.activate_session(@session1)
|
59
59
|
ShopifyAPI::Base.clear_session
|
60
60
|
|
61
|
-
assert_nil
|
62
|
-
assert_nil
|
63
|
-
assert_nil
|
61
|
+
assert_nil(ActiveResource::Base.site)
|
62
|
+
assert_nil(ShopifyAPI::Base.site)
|
63
|
+
assert_nil(ShopifyAPI::Shop.site)
|
64
64
|
|
65
|
-
assert_nil
|
66
|
-
assert_nil
|
67
|
-
assert_nil
|
65
|
+
assert_nil(ActiveResource::Base.headers['X-Shopify-Access-Token'])
|
66
|
+
assert_nil(ShopifyAPI::Base.headers['X-Shopify-Access-Token'])
|
67
|
+
assert_nil(ShopifyAPI::Shop.headers['X-Shopify-Access-Token'])
|
68
68
|
end
|
69
69
|
|
70
70
|
test '#activate_session with one session, then clearing and activating with another session should send request to correct shop' do
|
71
|
-
ShopifyAPI::Base.activate_session
|
71
|
+
ShopifyAPI::Base.activate_session(@session1)
|
72
72
|
ShopifyAPI::Base.clear_session
|
73
|
-
ShopifyAPI::Base.activate_session
|
73
|
+
ShopifyAPI::Base.activate_session(@session2)
|
74
74
|
|
75
|
-
assert_nil
|
76
|
-
assert_equal
|
77
|
-
assert_equal
|
75
|
+
assert_nil(ActiveResource::Base.site)
|
76
|
+
assert_equal('https://shop2.myshopify.com', ShopifyAPI::Base.site.to_s)
|
77
|
+
assert_equal('https://shop2.myshopify.com', ShopifyAPI::Shop.site.to_s)
|
78
78
|
|
79
|
-
assert_nil
|
80
|
-
assert_equal
|
81
|
-
assert_equal
|
79
|
+
assert_nil(ActiveResource::Base.headers['X-Shopify-Access-Token'])
|
80
|
+
assert_equal('token2', ShopifyAPI::Base.headers['X-Shopify-Access-Token'])
|
81
|
+
assert_equal('token2', ShopifyAPI::Shop.headers['X-Shopify-Access-Token'])
|
82
82
|
end
|
83
83
|
|
84
84
|
test '#activate_session with nil raises an InvalidSessionError' do
|
85
|
-
assert_raises
|
86
|
-
ShopifyAPI::Base.activate_session
|
85
|
+
assert_raises(ShopifyAPI::Base::InvalidSessionError) do
|
86
|
+
ShopifyAPI::Base.activate_session(nil)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
test "#delete should send custom headers with request" do
|
91
|
-
ShopifyAPI::Base.activate_session
|
91
|
+
ShopifyAPI::Base.activate_session(@session1)
|
92
92
|
ShopifyAPI::Base.headers['X-Custom'] = 'abc'
|
93
93
|
ShopifyAPI::Base.connection
|
94
94
|
.expects(:delete)
|
95
95
|
.with('/admin/api/2019-01/bases/1.json', has_entry('X-Custom', 'abc'))
|
96
|
-
ShopifyAPI::Base.delete
|
96
|
+
ShopifyAPI::Base.delete("1")
|
97
97
|
end
|
98
98
|
|
99
99
|
test "#headers includes the User-Agent" do
|
100
100
|
assert_not_includes ActiveResource::Base.headers.keys, 'User-Agent'
|
101
|
-
assert_includes
|
101
|
+
assert_includes(ShopifyAPI::Base.headers.keys, 'User-Agent')
|
102
102
|
thread = Thread.new do
|
103
|
-
assert_includes
|
103
|
+
assert_includes(ShopifyAPI::Base.headers.keys, 'User-Agent')
|
104
104
|
end
|
105
105
|
thread.join
|
106
106
|
end
|
@@ -116,28 +116,28 @@ class BaseTest < Test::Unit::TestCase
|
|
116
116
|
end
|
117
117
|
|
118
118
|
test "prefix= will raise an error if value starts with with /admin" do
|
119
|
-
assert_raises
|
119
|
+
assert_raises(ArgumentError) do
|
120
120
|
TestResource.prefix = '/admin/old/prefix/structure/'
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
124
|
test "#headers propagates changes to subclasses" do
|
125
125
|
ShopifyAPI::Base.headers['X-Custom'] = "the value"
|
126
|
-
assert_equal
|
127
|
-
assert_equal
|
126
|
+
assert_equal("the value", ShopifyAPI::Base.headers['X-Custom'])
|
127
|
+
assert_equal("the value", ShopifyAPI::Product.headers['X-Custom'])
|
128
128
|
end
|
129
129
|
|
130
130
|
test "#headers clears changes to subclasses" do
|
131
131
|
ShopifyAPI::Base.headers['X-Custom'] = "the value"
|
132
|
-
assert_equal
|
132
|
+
assert_equal("the value", ShopifyAPI::Product.headers['X-Custom'])
|
133
133
|
ShopifyAPI::Base.headers['X-Custom'] = nil
|
134
|
-
assert_nil
|
134
|
+
assert_nil(ShopifyAPI::Product.headers['X-Custom'])
|
135
135
|
end
|
136
136
|
|
137
137
|
test "#headers set in the main thread affect spawned threads" do
|
138
138
|
ShopifyAPI::Base.headers['X-Custom'] = "the value"
|
139
139
|
Thread.new do
|
140
|
-
assert_equal
|
140
|
+
assert_equal("the value", ShopifyAPI::Base.headers['X-Custom'])
|
141
141
|
end.join
|
142
142
|
end
|
143
143
|
|
@@ -145,7 +145,7 @@ class BaseTest < Test::Unit::TestCase
|
|
145
145
|
Thread.new do
|
146
146
|
ShopifyAPI::Base.headers['X-Custom'] = "the value"
|
147
147
|
end.join
|
148
|
-
assert_nil
|
148
|
+
assert_nil(ShopifyAPI::Base.headers['X-Custom'])
|
149
149
|
end
|
150
150
|
|
151
151
|
test "using a different version changes the url" do
|
@@ -168,41 +168,40 @@ class BaseTest < Test::Unit::TestCase
|
|
168
168
|
)
|
169
169
|
|
170
170
|
ShopifyAPI::Base.activate_session(release_2019_01)
|
171
|
-
assert_equal
|
171
|
+
assert_equal(1, ShopifyAPI::Shop.current.id)
|
172
172
|
|
173
173
|
ShopifyAPI::Base.activate_session(unstable_version)
|
174
|
-
assert_equal
|
174
|
+
assert_equal(2, ShopifyAPI::Shop.current.id)
|
175
175
|
end
|
176
176
|
|
177
177
|
test "#api_version= should set ApiVersion" do
|
178
178
|
ShopifyAPI::Base.api_version = '2019-04'
|
179
|
-
assert_equal
|
179
|
+
assert_equal('2019-04', ShopifyAPI::Base.api_version.to_s)
|
180
180
|
end
|
181
181
|
|
182
182
|
test "#api_version= nil should set ApiVersion to ShopifyAPI::ApiVersion::NullVersion" do
|
183
183
|
ShopifyAPI::Base.api_version = nil
|
184
|
-
assert_equal
|
184
|
+
assert_equal(ShopifyAPI::ApiVersion::NullVersion, ShopifyAPI::Base.api_version)
|
185
185
|
end
|
186
186
|
|
187
187
|
test "#api_version= ShopifyAPI::ApiVersion::NullVersion should set ApiVersion to ShopifyAPI::ApiVersion::NullVersion" do
|
188
188
|
ShopifyAPI::Base.api_version = ShopifyAPI::ApiVersion::NullVersion
|
189
|
-
assert_equal
|
189
|
+
assert_equal(ShopifyAPI::ApiVersion::NullVersion, ShopifyAPI::Base.api_version)
|
190
190
|
end
|
191
191
|
|
192
192
|
test "#version_validation! does not raise is api_version is newer or equal to minimum supported version" do
|
193
193
|
ShopifyAPI::Base.api_version = '2020-01'
|
194
|
-
assert_nil
|
194
|
+
assert_nil(ShopifyAPI::Base::version_validation!('2020-01'))
|
195
195
|
end
|
196
196
|
|
197
197
|
test "#version_validation! raises NotImplemetedError if api_version is older than minimum supported version" do
|
198
198
|
ShopifyAPI::Base.api_version = '2019-10'
|
199
|
-
exception = assert_raises
|
199
|
+
exception = assert_raises(NotImplementedError) do
|
200
200
|
ShopifyAPI::Base::version_validation!('2020-01')
|
201
201
|
end
|
202
|
-
assert_equal
|
202
|
+
assert_equal('The minimum supported version is 2020-01.', exception.message)
|
203
203
|
end
|
204
204
|
|
205
|
-
|
206
205
|
def clear_header(header)
|
207
206
|
[ActiveResource::Base, ShopifyAPI::Base, ShopifyAPI::Product].each do |klass|
|
208
207
|
klass.headers.delete(header)
|