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.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +36 -0
  3. data/.github/workflows/build.yml +41 -0
  4. data/.gitignore +2 -1
  5. data/.rubocop.yml +23 -3
  6. data/.rubocop_todo.yml +75 -0
  7. data/CHANGELOG.md +43 -0
  8. data/CONTRIBUTING.md +1 -1
  9. data/Gemfile +5 -0
  10. data/Gemfile.lock +151 -0
  11. data/Gemfile_ar51 +1 -1
  12. data/README.md +47 -31
  13. data/RELEASING +10 -6
  14. data/Rakefile +16 -5
  15. data/SECURITY.md +59 -0
  16. data/docs/_config.yml +1 -0
  17. data/docs/_includes/footer.html +28 -0
  18. data/docs/_includes/head.html +28 -0
  19. data/docs/_layouts/index.html +57 -0
  20. data/docs/graphql.md +47 -2
  21. data/docs/index.md +639 -0
  22. data/lib/active_resource/connection_ext.rb +1 -0
  23. data/lib/active_resource/detailed_log_subscriber.rb +6 -7
  24. data/lib/active_resource/json_errors.rb +8 -2
  25. data/lib/shopify_api.rb +8 -1
  26. data/lib/shopify_api/api_access.rb +57 -0
  27. data/lib/shopify_api/api_version.rb +6 -5
  28. data/lib/shopify_api/connection.rb +1 -0
  29. data/lib/shopify_api/countable.rb +3 -2
  30. data/lib/shopify_api/disable_prefix_check.rb +2 -2
  31. data/lib/shopify_api/events.rb +2 -1
  32. data/lib/shopify_api/graphql.rb +28 -8
  33. data/lib/shopify_api/limits.rb +3 -2
  34. data/lib/shopify_api/message_enricher.rb +11 -9
  35. data/lib/shopify_api/meta.rb +0 -1
  36. data/lib/shopify_api/metafields.rb +5 -4
  37. data/lib/shopify_api/pagination_link_headers.rb +5 -4
  38. data/lib/shopify_api/resources.rb +1 -0
  39. data/lib/shopify_api/resources/access_scope.rb +1 -1
  40. data/lib/shopify_api/resources/access_token.rb +1 -0
  41. data/lib/shopify_api/resources/address.rb +1 -0
  42. data/lib/shopify_api/resources/announcement.rb +2 -1
  43. data/lib/shopify_api/resources/application_charge.rb +1 -0
  44. data/lib/shopify_api/resources/application_credit.rb +1 -0
  45. data/lib/shopify_api/resources/article.rb +3 -2
  46. data/lib/shopify_api/resources/asset.rb +6 -5
  47. data/lib/shopify_api/resources/assigned_fulfillment_order.rb +1 -1
  48. data/lib/shopify_api/resources/base.rb +12 -8
  49. data/lib/shopify_api/resources/billing_address.rb +1 -0
  50. data/lib/shopify_api/resources/blog.rb +2 -1
  51. data/lib/shopify_api/resources/carrier_service.rb +1 -0
  52. data/lib/shopify_api/resources/cart.rb +2 -1
  53. data/lib/shopify_api/resources/collect.rb +1 -0
  54. data/lib/shopify_api/resources/collection_listing.rb +1 -0
  55. data/lib/shopify_api/resources/comment.rb +20 -5
  56. data/lib/shopify_api/resources/country.rb +1 -0
  57. data/lib/shopify_api/resources/custom_collection.rb +4 -3
  58. data/lib/shopify_api/resources/customer.rb +2 -1
  59. data/lib/shopify_api/resources/customer_group.rb +1 -0
  60. data/lib/shopify_api/resources/customer_invite.rb +1 -0
  61. data/lib/shopify_api/resources/customer_saved_search.rb +2 -1
  62. data/lib/shopify_api/resources/discount_code.rb +1 -0
  63. data/lib/shopify_api/resources/discount_code_batch.rb +34 -0
  64. data/lib/shopify_api/resources/draft_order.rb +1 -0
  65. data/lib/shopify_api/resources/draft_order_invoice.rb +1 -0
  66. data/lib/shopify_api/resources/event.rb +1 -0
  67. data/lib/shopify_api/resources/fulfillment.rb +12 -3
  68. data/lib/shopify_api/resources/fulfillment_event.rb +1 -0
  69. data/lib/shopify_api/resources/fulfillment_order.rb +30 -16
  70. data/lib/shopify_api/resources/fulfillment_order_locations_for_move.rb +1 -0
  71. data/lib/shopify_api/resources/fulfillment_request.rb +1 -0
  72. data/lib/shopify_api/resources/fulfillment_service.rb +1 -0
  73. data/lib/shopify_api/resources/fulfillment_v2.rb +3 -2
  74. data/lib/shopify_api/resources/gift_card.rb +1 -0
  75. data/lib/shopify_api/resources/image.rb +2 -1
  76. data/lib/shopify_api/resources/inventory_level.rb +3 -4
  77. data/lib/shopify_api/resources/line_item.rb +4 -3
  78. data/lib/shopify_api/resources/location.rb +1 -1
  79. data/lib/shopify_api/resources/marketing_event.rb +1 -0
  80. data/lib/shopify_api/resources/metafield.rb +1 -0
  81. data/lib/shopify_api/resources/note_attribute.rb +1 -0
  82. data/lib/shopify_api/resources/option.rb +1 -0
  83. data/lib/shopify_api/resources/order.rb +2 -1
  84. data/lib/shopify_api/resources/order_risk.rb +1 -0
  85. data/lib/shopify_api/resources/page.rb +1 -0
  86. data/lib/shopify_api/resources/payment_details.rb +1 -0
  87. data/lib/shopify_api/resources/policy.rb +1 -0
  88. data/lib/shopify_api/resources/price_rule.rb +1 -1
  89. data/lib/shopify_api/resources/product.rb +27 -3
  90. data/lib/shopify_api/resources/product_listing.rb +1 -0
  91. data/lib/shopify_api/resources/province.rb +1 -0
  92. data/lib/shopify_api/resources/receipt.rb +1 -0
  93. data/lib/shopify_api/resources/recurring_application_charge.rb +4 -1
  94. data/lib/shopify_api/resources/redirect.rb +1 -0
  95. data/lib/shopify_api/resources/refund.rb +2 -1
  96. data/lib/shopify_api/resources/report.rb +1 -0
  97. data/lib/shopify_api/resources/resource_feedback.rb +1 -1
  98. data/lib/shopify_api/resources/rule.rb +1 -0
  99. data/lib/shopify_api/resources/script_tag.rb +1 -0
  100. data/lib/shopify_api/resources/shipping_address.rb +1 -0
  101. data/lib/shopify_api/resources/shipping_line.rb +1 -0
  102. data/lib/shopify_api/resources/shipping_zone.rb +1 -0
  103. data/lib/shopify_api/resources/shop.rb +2 -1
  104. data/lib/shopify_api/resources/smart_collection.rb +4 -8
  105. data/lib/shopify_api/resources/storefront_access_token.rb +1 -0
  106. data/lib/shopify_api/resources/tax_line.rb +1 -0
  107. data/lib/shopify_api/resources/tax_service.rb +1 -0
  108. data/lib/shopify_api/resources/theme.rb +1 -0
  109. data/lib/shopify_api/resources/transaction.rb +1 -0
  110. data/lib/shopify_api/resources/usage_charge.rb +1 -0
  111. data/lib/shopify_api/resources/user.rb +1 -0
  112. data/lib/shopify_api/resources/variant.rb +35 -0
  113. data/lib/shopify_api/resources/webhook.rb +1 -0
  114. data/lib/shopify_api/session.rb +43 -14
  115. data/lib/shopify_api/version.rb +2 -1
  116. data/lib/verify_docs.rb +8 -0
  117. data/service.yml +1 -1
  118. data/shopify_api.gemspec +13 -6
  119. data/test/access_token_test.rb +6 -5
  120. data/test/active_resource/json_errors_test.rb +6 -6
  121. data/test/api_access_test.rb +153 -0
  122. data/test/api_version_test.rb +3 -3
  123. data/test/application_charge_test.rb +30 -27
  124. data/test/application_credit_test.rb +10 -9
  125. data/test/article_test.rb +34 -35
  126. data/test/asset_test.rb +14 -6
  127. data/test/assigned_fulfillment_order_test.rb +5 -4
  128. data/test/base_test.rb +64 -49
  129. data/test/blog_test.rb +4 -3
  130. data/test/carrier_service_test.rb +7 -6
  131. data/test/cart_test.rb +2 -1
  132. data/test/collect_test.rb +4 -3
  133. data/test/collection_listing_test.rb +21 -16
  134. data/test/collection_publication_test.rb +8 -8
  135. data/test/collection_test.rb +20 -19
  136. data/test/countable_test.rb +3 -2
  137. data/test/currency_test.rb +5 -5
  138. data/test/custom_collection_test.rb +4 -3
  139. data/test/customer_saved_search_test.rb +18 -8
  140. data/test/customer_test.rb +22 -14
  141. data/test/detailed_log_subscriber_test.rb +15 -11
  142. data/test/discount_code_batch_test.rb +41 -0
  143. data/test/discount_code_test.rb +21 -15
  144. data/test/draft_order_test.rb +68 -52
  145. data/test/fixtures/assigned_fulfillment_orders.json +2 -0
  146. data/test/fixtures/discount_code_batch.json +14 -0
  147. data/test/fixtures/discount_code_batch_discount_codes.json +21 -0
  148. data/test/fixtures/fulfillment_order.json +1 -0
  149. data/test/fixtures/fulfillment_orders.json +2 -0
  150. data/test/fulfillment_event_test.rb +31 -26
  151. data/test/fulfillment_order_test.rb +215 -147
  152. data/test/fulfillment_order_test_helper.rb +1 -0
  153. data/test/fulfillment_request_test.rb +10 -8
  154. data/test/fulfillment_service_test.rb +13 -12
  155. data/test/fulfillment_test.rb +81 -66
  156. data/test/fulfillment_v2_test.rb +16 -12
  157. data/test/gift_card_test.rb +6 -4
  158. data/test/graphql_test.rb +55 -23
  159. data/test/image_test.rb +19 -17
  160. data/test/inventory_level_test.rb +24 -15
  161. data/test/lib/webmock_extensions/last_request.rb +1 -1
  162. data/test/limits_test.rb +2 -1
  163. data/test/location_test.rb +2 -1
  164. data/test/marketing_event_test.rb +20 -20
  165. data/test/message_enricher_test.rb +6 -6
  166. data/test/meta_test.rb +7 -9
  167. data/test/metafield_test.rb +30 -20
  168. data/test/order_risk_test.rb +17 -16
  169. data/test/order_test.rb +43 -28
  170. data/test/pagination_test.rb +89 -56
  171. data/test/policy_test.rb +6 -5
  172. data/test/price_rule_test.rb +20 -15
  173. data/test/product_listing_test.rb +20 -20
  174. data/test/product_publication_test.rb +8 -8
  175. data/test/product_test.rb +71 -20
  176. data/test/publication_test.rb +3 -3
  177. data/test/recurring_application_charge_test.rb +104 -42
  178. data/test/redirect_test.rb +4 -3
  179. data/test/refund_test.rb +22 -17
  180. data/test/report_test.rb +12 -10
  181. data/test/resource_feedback_test.rb +14 -13
  182. data/test/script_tag_test.rb +10 -9
  183. data/test/session_test.rb +234 -43
  184. data/test/shipping_zone_test.rb +4 -3
  185. data/test/shop_test.rb +47 -33
  186. data/test/smart_collection_test.rb +5 -29
  187. data/test/storefront_access_token_test.rb +13 -15
  188. data/test/tax_service_test.rb +7 -4
  189. data/test/tender_transaction_test.rb +3 -3
  190. data/test/test_helper.rb +14 -12
  191. data/test/transaction_test.rb +4 -3
  192. data/test/usage_charge_test.rb +12 -8
  193. data/test/user_test.rb +4 -3
  194. data/test/variant_test.rb +50 -23
  195. data/test/webhook_test.rb +10 -7
  196. metadata +30 -15
  197. data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
  198. data/.travis.yml +0 -23
  199. data/bin/shopify +0 -3
@@ -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 "application_charges", :method => :post, :status => 201, :body => load_fixture('application_charge')
6
+ fake("application_charges", method: :post, status: 201, body: load_fixture('application_charge'))
7
7
 
8
8
  charge = ShopifyAPI::ApplicationCharge.create(
9
- name: "iPod Cleaning",
10
- price: 5.00,
11
- return_url: "http://google.com"
9
+ name: "iPod Cleaning",
10
+ price: 5.00,
11
+ return_url: "http://google.com"
12
12
  )
13
13
 
14
- assert_equal 'https://this-is-my-test-shop.myshopify.com/admin/charges/803742/confirm_application_charge?signature=BAhpA55DDA%3D%3D--55b44e274e438c619be4631c804abcbcb6ee915a', charge.confirmation_url
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 "application_charges/803742", :method => :get, :status => 201, :body => load_fixture('application_charge')
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 "iPod Cleaning", charge.name
26
+ assert_equal("iPod Cleaning", charge.name)
23
27
  end
24
28
 
25
29
  def test_list_application_charges
26
- fake "application_charges", :method => :get, :status => 201, :body => load_fixture('application_charges')
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 4, charges.size
31
- assert_equal "iPhone Case", charges.last.name
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 "application_charges", :method => :get, :status => 201, :body => load_fixture('application_charges')
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 1, pending_charges.size
40
- assert_equal "Screen Replacement", pending_charges.first.name
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 "application_charges", :method => :get, :status => 201, :body => load_fixture('application_charges')
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 1, expired_charges.size
49
- assert_equal "iPod Cleaning", expired_charges.first.name
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 "application_charges", :method => :get, :status => 201, :body => load_fixture('application_charges')
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 1, accepted_charges.size
58
- assert_equal "iPhone Case", accepted_charges.first.name
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 "application_charges", :method => :get, :status => 201, :body => load_fixture('application_charges')
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 1, declined_charges.size
67
- assert_equal "Magic Mouse", declined_charges.first.name
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 "application_charges", :method => :get, :status => 201, :body => load_fixture('application_charges')
72
- fake "application_charges/803740/activate", :method => :post, :status => 200, :body => "{}"
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 charge.last.activate
80
+ assert(charge.last.activate)
77
81
  end
78
-
79
82
  end
@@ -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 "application_credits", method: :post, status: 201, body: load_fixture('application_credit')
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 'refund for application charge', credit.description
15
- assert_equal '5.00', credit.amount
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 "application_credits/803742", method: :get, status: 201, body: load_fixture('application_credit')
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 'refund for application charge', credit.description
24
- assert_equal '5.00', credit.amount
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 "application_credits", method: :get, status: 201, body: load_fixture('application_credits')
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 2, credit.size
33
- assert_equal '10.00', credit.last.amount
33
+ assert_equal(2, credit.size)
34
+ assert_equal('10.00', credit.last.amount)
34
35
  end
35
36
  end
@@ -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 "blogs/1008414260/articles", :method => :post, :body => load_fixture('article')
7
- article = ShopifyAPI::Article.new(:blog_id => 1008414260)
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 "First Post", article.title
9
+ assert_equal("First Post", article.title)
10
10
  end
11
11
 
12
12
  def test_get_article
13
- fake "articles/6242736", :method => :get, :body => load_fixture('article')
13
+ fake("articles/6242736", method: :get, body: load_fixture('article'))
14
14
  article = ShopifyAPI::Article.find(6242736)
15
- assert_equal "First Post", article.title
16
- assert_equal 1008414260, article.blog_id
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 "articles", :method => :get, :body => load_fixture('articles')
20
+ fake("articles", method: :get, body: load_fixture('articles'))
21
21
  articles = ShopifyAPI::Article.all
22
- assert_equal 3, articles.length
23
- assert_equal 1008414260, articles.first.blog_id
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 "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
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 "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
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 "articles/authors", :method => :get, :body => load_fixture('authors')
41
+ fake("articles/authors", method: :get, body: load_fixture('authors'))
42
42
  authors = ShopifyAPI::Article.authors
43
- assert_equal "Shopify", authors.first
44
- assert_equal "development shop", authors.last
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 "blogs/1008414260/articles/authors", :method => :get, :body => load_fixture('authors')
49
- authors = ShopifyAPI::Article.authors(:blog_id => 1008414260)
50
- assert_equal 3, authors.length
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 "articles/tags", :method => :get, :body => load_fixture('tags')
54
+ fake("articles/tags", method: :get, body: load_fixture('tags'))
55
55
  tags = ShopifyAPI::Article.tags
56
- assert_equal "consequuntur", tags.first
57
- assert_equal "repellendus", tags.last
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 "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
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 "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
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
@@ -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 "themes/1/assets", :method => :get, :body => load_fixture('assets')
6
- v = ShopifyAPI::Asset.find(:all, :params => {:theme_id => 1})
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 "themes/1/assets.json?asset%5Bkey%5D=templates%2Findex.liquid&theme_id=1", :extension=> false, :method => :get, :body => load_fixture('asset')
11
- v = ShopifyAPI::Asset.find('templates/index.liquid', :params => {:theme_id => 1})
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 "assets.json?asset%5Bkey%5D=templates%2Findex.liquid", :extension=> false, :method => :get, :body => load_fixture('asset')
16
- v = ShopifyAPI::Asset.find('templates/index.liquid')
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 NotImplementedError do
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 NotImplementedError do
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
- params: { assigned_status: 'cancellation_requested' }
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
- params: { location_ids: [assigned_location_id] }
67
+ params: { location_ids: [assigned_location_id] }
67
68
  )
68
69
 
69
70
  assert_equal 2, assigned_fulfillment_orders.count
@@ -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,77 +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 @session1
18
+ ShopifyAPI::Base.activate_session(@session1)
18
19
 
19
- assert_nil ActiveResource::Base.site
20
- assert_equal 'https://shop1.myshopify.com', ShopifyAPI::Base.site.to_s
21
- assert_equal 'https://shop1.myshopify.com', ShopifyAPI::Shop.site.to_s
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 ActiveResource::Base.headers['X-Shopify-Access-Token']
24
- assert_equal 'token1', ShopifyAPI::Base.headers['X-Shopify-Access-Token']
25
- assert_equal 'token1', ShopifyAPI::Shop.headers['X-Shopify-Access-Token']
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 "foo", ShopifyAPI::Base.user
32
- assert_equal "bar", ShopifyAPI::Base.password
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 ShopifyAPI::Base.user
37
- assert_nil ShopifyAPI::Base.password
38
- assert_nil ShopifyAPI::Base.site
37
+ assert_nil(ShopifyAPI::Base.user)
38
+ assert_nil(ShopifyAPI::Base.password)
39
+ assert_nil(ShopifyAPI::Base.site)
40
+ end
41
+
42
+ # test to check session reset api version remains the same after session reset
43
+ test '#clear_session should not change the api_version' do
44
+ ShopifyAPI::Base.site = "https://zoo:lion@www.zoo.com"
45
+
46
+ assert_equal("zoo", ShopifyAPI::Base.user)
47
+ assert_equal("lion", ShopifyAPI::Base.password)
48
+
49
+ ShopifyAPI::Base.clear_session
50
+
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)
39
55
  end
40
56
 
41
57
  test '#clear_session should clear site and headers from Base' do
42
- ShopifyAPI::Base.activate_session @session1
58
+ ShopifyAPI::Base.activate_session(@session1)
43
59
  ShopifyAPI::Base.clear_session
44
60
 
45
- assert_nil ActiveResource::Base.site
46
- assert_nil ShopifyAPI::Base.site
47
- assert_nil ShopifyAPI::Shop.site
61
+ assert_nil(ActiveResource::Base.site)
62
+ assert_nil(ShopifyAPI::Base.site)
63
+ assert_nil(ShopifyAPI::Shop.site)
48
64
 
49
- assert_nil ActiveResource::Base.headers['X-Shopify-Access-Token']
50
- assert_nil ShopifyAPI::Base.headers['X-Shopify-Access-Token']
51
- assert_nil ShopifyAPI::Shop.headers['X-Shopify-Access-Token']
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'])
52
68
  end
53
69
 
54
70
  test '#activate_session with one session, then clearing and activating with another session should send request to correct shop' do
55
- ShopifyAPI::Base.activate_session @session1
71
+ ShopifyAPI::Base.activate_session(@session1)
56
72
  ShopifyAPI::Base.clear_session
57
- ShopifyAPI::Base.activate_session @session2
73
+ ShopifyAPI::Base.activate_session(@session2)
58
74
 
59
- assert_nil ActiveResource::Base.site
60
- assert_equal 'https://shop2.myshopify.com', ShopifyAPI::Base.site.to_s
61
- assert_equal 'https://shop2.myshopify.com', ShopifyAPI::Shop.site.to_s
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)
62
78
 
63
- assert_nil ActiveResource::Base.headers['X-Shopify-Access-Token']
64
- assert_equal 'token2', ShopifyAPI::Base.headers['X-Shopify-Access-Token']
65
- assert_equal 'token2', ShopifyAPI::Shop.headers['X-Shopify-Access-Token']
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'])
66
82
  end
67
83
 
68
84
  test '#activate_session with nil raises an InvalidSessionError' do
69
- assert_raises ShopifyAPI::Base::InvalidSessionError do
70
- ShopifyAPI::Base.activate_session nil
85
+ assert_raises(ShopifyAPI::Base::InvalidSessionError) do
86
+ ShopifyAPI::Base.activate_session(nil)
71
87
  end
72
88
  end
73
89
 
74
90
  test "#delete should send custom headers with request" do
75
- ShopifyAPI::Base.activate_session @session1
91
+ ShopifyAPI::Base.activate_session(@session1)
76
92
  ShopifyAPI::Base.headers['X-Custom'] = 'abc'
77
93
  ShopifyAPI::Base.connection
78
94
  .expects(:delete)
79
95
  .with('/admin/api/2019-01/bases/1.json', has_entry('X-Custom', 'abc'))
80
- ShopifyAPI::Base.delete "1"
96
+ ShopifyAPI::Base.delete("1")
81
97
  end
82
98
 
83
99
  test "#headers includes the User-Agent" do
84
100
  assert_not_includes ActiveResource::Base.headers.keys, 'User-Agent'
85
- assert_includes ShopifyAPI::Base.headers.keys, 'User-Agent'
101
+ assert_includes(ShopifyAPI::Base.headers.keys, 'User-Agent')
86
102
  thread = Thread.new do
87
- assert_includes ShopifyAPI::Base.headers.keys, 'User-Agent'
103
+ assert_includes(ShopifyAPI::Base.headers.keys, 'User-Agent')
88
104
  end
89
105
  thread.join
90
106
  end
@@ -100,28 +116,28 @@ class BaseTest < Test::Unit::TestCase
100
116
  end
101
117
 
102
118
  test "prefix= will raise an error if value starts with with /admin" do
103
- assert_raises ArgumentError do
119
+ assert_raises(ArgumentError) do
104
120
  TestResource.prefix = '/admin/old/prefix/structure/'
105
121
  end
106
122
  end
107
123
 
108
124
  test "#headers propagates changes to subclasses" do
109
125
  ShopifyAPI::Base.headers['X-Custom'] = "the value"
110
- assert_equal "the value", ShopifyAPI::Base.headers['X-Custom']
111
- assert_equal "the value", ShopifyAPI::Product.headers['X-Custom']
126
+ assert_equal("the value", ShopifyAPI::Base.headers['X-Custom'])
127
+ assert_equal("the value", ShopifyAPI::Product.headers['X-Custom'])
112
128
  end
113
129
 
114
130
  test "#headers clears changes to subclasses" do
115
131
  ShopifyAPI::Base.headers['X-Custom'] = "the value"
116
- assert_equal "the value", ShopifyAPI::Product.headers['X-Custom']
132
+ assert_equal("the value", ShopifyAPI::Product.headers['X-Custom'])
117
133
  ShopifyAPI::Base.headers['X-Custom'] = nil
118
- assert_nil ShopifyAPI::Product.headers['X-Custom']
134
+ assert_nil(ShopifyAPI::Product.headers['X-Custom'])
119
135
  end
120
136
 
121
137
  test "#headers set in the main thread affect spawned threads" do
122
138
  ShopifyAPI::Base.headers['X-Custom'] = "the value"
123
139
  Thread.new do
124
- assert_equal "the value", ShopifyAPI::Base.headers['X-Custom']
140
+ assert_equal("the value", ShopifyAPI::Base.headers['X-Custom'])
125
141
  end.join
126
142
  end
127
143
 
@@ -129,7 +145,7 @@ class BaseTest < Test::Unit::TestCase
129
145
  Thread.new do
130
146
  ShopifyAPI::Base.headers['X-Custom'] = "the value"
131
147
  end.join
132
- assert_nil ShopifyAPI::Base.headers['X-Custom']
148
+ assert_nil(ShopifyAPI::Base.headers['X-Custom'])
133
149
  end
134
150
 
135
151
  test "using a different version changes the url" do
@@ -152,41 +168,40 @@ class BaseTest < Test::Unit::TestCase
152
168
  )
153
169
 
154
170
  ShopifyAPI::Base.activate_session(release_2019_01)
155
- assert_equal 1, ShopifyAPI::Shop.current.id
171
+ assert_equal(1, ShopifyAPI::Shop.current.id)
156
172
 
157
173
  ShopifyAPI::Base.activate_session(unstable_version)
158
- assert_equal 2, ShopifyAPI::Shop.current.id
174
+ assert_equal(2, ShopifyAPI::Shop.current.id)
159
175
  end
160
176
 
161
177
  test "#api_version= should set ApiVersion" do
162
178
  ShopifyAPI::Base.api_version = '2019-04'
163
- assert_equal '2019-04', ShopifyAPI::Base.api_version.to_s
179
+ assert_equal('2019-04', ShopifyAPI::Base.api_version.to_s)
164
180
  end
165
181
 
166
182
  test "#api_version= nil should set ApiVersion to ShopifyAPI::ApiVersion::NullVersion" do
167
183
  ShopifyAPI::Base.api_version = nil
168
- assert_equal ShopifyAPI::ApiVersion::NullVersion, ShopifyAPI::Base.api_version
184
+ assert_equal(ShopifyAPI::ApiVersion::NullVersion, ShopifyAPI::Base.api_version)
169
185
  end
170
186
 
171
187
  test "#api_version= ShopifyAPI::ApiVersion::NullVersion should set ApiVersion to ShopifyAPI::ApiVersion::NullVersion" do
172
188
  ShopifyAPI::Base.api_version = ShopifyAPI::ApiVersion::NullVersion
173
- assert_equal ShopifyAPI::ApiVersion::NullVersion, ShopifyAPI::Base.api_version
189
+ assert_equal(ShopifyAPI::ApiVersion::NullVersion, ShopifyAPI::Base.api_version)
174
190
  end
175
191
 
176
192
  test "#version_validation! does not raise is api_version is newer or equal to minimum supported version" do
177
193
  ShopifyAPI::Base.api_version = '2020-01'
178
- assert_nil ShopifyAPI::Base::version_validation!('2020-01')
194
+ assert_nil(ShopifyAPI::Base::version_validation!('2020-01'))
179
195
  end
180
196
 
181
197
  test "#version_validation! raises NotImplemetedError if api_version is older than minimum supported version" do
182
198
  ShopifyAPI::Base.api_version = '2019-10'
183
- exception = assert_raises NotImplementedError do
199
+ exception = assert_raises(NotImplementedError) do
184
200
  ShopifyAPI::Base::version_validation!('2020-01')
185
201
  end
186
- assert_equal 'The minimum supported version is 2020-01.', exception.message
202
+ assert_equal('The minimum supported version is 2020-01.', exception.message)
187
203
  end
188
204
 
189
-
190
205
  def clear_header(header)
191
206
  [ActiveResource::Base, ShopifyAPI::Base, ShopifyAPI::Product].each do |klass|
192
207
  klass.headers.delete(header)