shopify_api 9.0.4 → 9.5

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.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -1
  3. data/.github/ISSUE_TEMPLATE.md +36 -0
  4. data/.github/workflows/build.yml +44 -0
  5. data/.gitignore +2 -1
  6. data/.rubocop.yml +23 -3
  7. data/.rubocop_todo.yml +75 -0
  8. data/CHANGELOG.md +41 -0
  9. data/CONTRIBUTING.md +1 -1
  10. data/Gemfile +5 -0
  11. data/Gemfile.lock +153 -0
  12. data/Gemfile_ar51 +1 -1
  13. data/README.md +42 -32
  14. data/RELEASING +10 -6
  15. data/Rakefile +16 -5
  16. data/SECURITY.md +59 -0
  17. data/dev.yml +11 -0
  18. data/docs/_config.yml +1 -0
  19. data/docs/_includes/footer.html +28 -0
  20. data/docs/_includes/head.html +28 -0
  21. data/docs/_layouts/index.html +57 -0
  22. data/docs/graphql.md +47 -2
  23. data/docs/index.md +639 -0
  24. data/lib/active_resource/connection_ext.rb +1 -0
  25. data/lib/active_resource/detailed_log_subscriber.rb +10 -7
  26. data/lib/active_resource/json_errors.rb +8 -2
  27. data/lib/shopify_api/api_access.rb +57 -0
  28. data/lib/shopify_api/api_version.rb +6 -5
  29. data/lib/shopify_api/connection.rb +1 -0
  30. data/lib/shopify_api/countable.rb +3 -2
  31. data/lib/shopify_api/disable_prefix_check.rb +2 -2
  32. data/lib/shopify_api/events.rb +2 -1
  33. data/lib/shopify_api/graphql.rb +28 -8
  34. data/lib/shopify_api/hmac_params.rb +23 -0
  35. data/lib/shopify_api/limits.rb +3 -2
  36. data/lib/shopify_api/message_enricher.rb +11 -9
  37. data/lib/shopify_api/meta.rb +0 -1
  38. data/lib/shopify_api/metafields.rb +5 -4
  39. data/lib/shopify_api/pagination_link_headers.rb +5 -4
  40. data/lib/shopify_api/resources/access_scope.rb +1 -1
  41. data/lib/shopify_api/resources/access_token.rb +1 -0
  42. data/lib/shopify_api/resources/address.rb +1 -0
  43. data/lib/shopify_api/resources/announcement.rb +2 -1
  44. data/lib/shopify_api/resources/application_charge.rb +1 -0
  45. data/lib/shopify_api/resources/application_credit.rb +1 -0
  46. data/lib/shopify_api/resources/article.rb +3 -2
  47. data/lib/shopify_api/resources/asset.rb +6 -5
  48. data/lib/shopify_api/resources/assigned_fulfillment_order.rb +1 -1
  49. data/lib/shopify_api/resources/base.rb +12 -8
  50. data/lib/shopify_api/resources/billing_address.rb +1 -0
  51. data/lib/shopify_api/resources/blog.rb +2 -1
  52. data/lib/shopify_api/resources/carrier_service.rb +1 -0
  53. data/lib/shopify_api/resources/cart.rb +2 -1
  54. data/lib/shopify_api/resources/collect.rb +1 -0
  55. data/lib/shopify_api/resources/collection_listing.rb +1 -0
  56. data/lib/shopify_api/resources/comment.rb +20 -5
  57. data/lib/shopify_api/resources/country.rb +1 -0
  58. data/lib/shopify_api/resources/custom_collection.rb +4 -3
  59. data/lib/shopify_api/resources/customer.rb +2 -1
  60. data/lib/shopify_api/resources/customer_group.rb +1 -0
  61. data/lib/shopify_api/resources/customer_invite.rb +1 -0
  62. data/lib/shopify_api/resources/customer_saved_search.rb +2 -1
  63. data/lib/shopify_api/resources/discount_code.rb +1 -0
  64. data/lib/shopify_api/resources/discount_code_batch.rb +4 -2
  65. data/lib/shopify_api/resources/draft_order.rb +1 -0
  66. data/lib/shopify_api/resources/draft_order_invoice.rb +1 -0
  67. data/lib/shopify_api/resources/event.rb +1 -0
  68. data/lib/shopify_api/resources/fulfillment.rb +12 -3
  69. data/lib/shopify_api/resources/fulfillment_event.rb +1 -0
  70. data/lib/shopify_api/resources/fulfillment_order.rb +30 -16
  71. data/lib/shopify_api/resources/fulfillment_order_locations_for_move.rb +1 -0
  72. data/lib/shopify_api/resources/fulfillment_request.rb +1 -0
  73. data/lib/shopify_api/resources/fulfillment_service.rb +1 -0
  74. data/lib/shopify_api/resources/fulfillment_v2.rb +3 -2
  75. data/lib/shopify_api/resources/gift_card.rb +1 -0
  76. data/lib/shopify_api/resources/image.rb +2 -1
  77. data/lib/shopify_api/resources/inventory_level.rb +3 -4
  78. data/lib/shopify_api/resources/line_item.rb +4 -3
  79. data/lib/shopify_api/resources/location.rb +1 -1
  80. data/lib/shopify_api/resources/marketing_event.rb +1 -0
  81. data/lib/shopify_api/resources/metafield.rb +1 -0
  82. data/lib/shopify_api/resources/note_attribute.rb +1 -0
  83. data/lib/shopify_api/resources/option.rb +1 -0
  84. data/lib/shopify_api/resources/order.rb +2 -1
  85. data/lib/shopify_api/resources/order_risk.rb +1 -0
  86. data/lib/shopify_api/resources/page.rb +1 -0
  87. data/lib/shopify_api/resources/payment_details.rb +1 -0
  88. data/lib/shopify_api/resources/policy.rb +1 -0
  89. data/lib/shopify_api/resources/price_rule.rb +1 -1
  90. data/lib/shopify_api/resources/product.rb +27 -3
  91. data/lib/shopify_api/resources/product_listing.rb +1 -0
  92. data/lib/shopify_api/resources/province.rb +1 -0
  93. data/lib/shopify_api/resources/receipt.rb +1 -0
  94. data/lib/shopify_api/resources/recurring_application_charge.rb +4 -1
  95. data/lib/shopify_api/resources/redirect.rb +1 -0
  96. data/lib/shopify_api/resources/refund.rb +2 -1
  97. data/lib/shopify_api/resources/report.rb +1 -0
  98. data/lib/shopify_api/resources/resource_feedback.rb +1 -1
  99. data/lib/shopify_api/resources/rule.rb +1 -0
  100. data/lib/shopify_api/resources/script_tag.rb +1 -0
  101. data/lib/shopify_api/resources/shipping_address.rb +1 -0
  102. data/lib/shopify_api/resources/shipping_line.rb +1 -0
  103. data/lib/shopify_api/resources/shipping_zone.rb +1 -0
  104. data/lib/shopify_api/resources/shop.rb +2 -1
  105. data/lib/shopify_api/resources/smart_collection.rb +4 -8
  106. data/lib/shopify_api/resources/storefront_access_token.rb +1 -0
  107. data/lib/shopify_api/resources/tax_line.rb +1 -0
  108. data/lib/shopify_api/resources/tax_service.rb +1 -0
  109. data/lib/shopify_api/resources/theme.rb +1 -0
  110. data/lib/shopify_api/resources/transaction.rb +1 -0
  111. data/lib/shopify_api/resources/usage_charge.rb +1 -0
  112. data/lib/shopify_api/resources/user.rb +1 -0
  113. data/lib/shopify_api/resources/variant.rb +35 -0
  114. data/lib/shopify_api/resources/webhook.rb +1 -0
  115. data/lib/shopify_api/resources.rb +1 -0
  116. data/lib/shopify_api/session.rb +51 -20
  117. data/lib/shopify_api/version.rb +2 -1
  118. data/lib/shopify_api.rb +9 -1
  119. data/lib/verify_docs.rb +8 -0
  120. data/service.yml +2 -5
  121. data/shopify_api.gemspec +13 -7
  122. data/test/access_token_test.rb +6 -5
  123. data/test/active_resource/json_errors_test.rb +6 -6
  124. data/test/api_access_test.rb +153 -0
  125. data/test/api_version_test.rb +3 -3
  126. data/test/application_charge_test.rb +30 -27
  127. data/test/application_credit_test.rb +10 -9
  128. data/test/article_test.rb +34 -35
  129. data/test/asset_test.rb +14 -6
  130. data/test/assigned_fulfillment_order_test.rb +5 -4
  131. data/test/base_test.rb +64 -49
  132. data/test/blog_test.rb +4 -3
  133. data/test/carrier_service_test.rb +7 -6
  134. data/test/cart_test.rb +2 -1
  135. data/test/collect_test.rb +4 -3
  136. data/test/collection_listing_test.rb +21 -16
  137. data/test/collection_publication_test.rb +8 -8
  138. data/test/collection_test.rb +20 -19
  139. data/test/countable_test.rb +3 -2
  140. data/test/currency_test.rb +5 -5
  141. data/test/custom_collection_test.rb +4 -3
  142. data/test/customer_saved_search_test.rb +18 -8
  143. data/test/customer_test.rb +22 -14
  144. data/test/detailed_log_subscriber_test.rb +16 -12
  145. data/test/discount_code_batch_test.rb +11 -10
  146. data/test/discount_code_test.rb +21 -15
  147. data/test/draft_order_test.rb +68 -52
  148. data/test/fixtures/assigned_fulfillment_orders.json +2 -0
  149. data/test/fixtures/fulfillment_order.json +1 -0
  150. data/test/fixtures/fulfillment_orders.json +2 -0
  151. data/test/fulfillment_event_test.rb +31 -26
  152. data/test/fulfillment_order_test.rb +217 -149
  153. data/test/fulfillment_order_test_helper.rb +1 -0
  154. data/test/fulfillment_request_test.rb +10 -8
  155. data/test/fulfillment_service_test.rb +13 -12
  156. data/test/fulfillment_test.rb +81 -66
  157. data/test/fulfillment_v2_test.rb +16 -12
  158. data/test/gift_card_test.rb +6 -4
  159. data/test/graphql_test.rb +55 -23
  160. data/test/hmac_params_test.rb +25 -0
  161. data/test/image_test.rb +19 -17
  162. data/test/inventory_level_test.rb +24 -15
  163. data/test/lib/webmock_extensions/last_request.rb +1 -1
  164. data/test/limits_test.rb +2 -1
  165. data/test/location_test.rb +2 -1
  166. data/test/marketing_event_test.rb +20 -20
  167. data/test/message_enricher_test.rb +6 -6
  168. data/test/meta_test.rb +9 -11
  169. data/test/metafield_test.rb +30 -20
  170. data/test/order_risk_test.rb +17 -16
  171. data/test/order_test.rb +43 -28
  172. data/test/pagination_test.rb +89 -56
  173. data/test/policy_test.rb +6 -5
  174. data/test/price_rule_test.rb +20 -15
  175. data/test/product_listing_test.rb +20 -20
  176. data/test/product_publication_test.rb +8 -8
  177. data/test/product_test.rb +71 -20
  178. data/test/publication_test.rb +3 -3
  179. data/test/recurring_application_charge_test.rb +104 -42
  180. data/test/redirect_test.rb +4 -3
  181. data/test/refund_test.rb +22 -17
  182. data/test/report_test.rb +12 -10
  183. data/test/resource_feedback_test.rb +14 -13
  184. data/test/script_tag_test.rb +10 -9
  185. data/test/session_test.rb +319 -45
  186. data/test/shipping_zone_test.rb +4 -3
  187. data/test/shop_test.rb +47 -33
  188. data/test/smart_collection_test.rb +5 -29
  189. data/test/storefront_access_token_test.rb +13 -15
  190. data/test/tax_service_test.rb +7 -4
  191. data/test/tender_transaction_test.rb +3 -3
  192. data/test/test_helper.rb +14 -12
  193. data/test/transaction_test.rb +4 -3
  194. data/test/usage_charge_test.rb +12 -8
  195. data/test/user_test.rb +4 -3
  196. data/test/variant_test.rb +50 -23
  197. data/test/webhook_test.rb +10 -7
  198. metadata +44 -17
  199. data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
  200. data/.travis.yml +0 -23
  201. data/bin/shopify +0 -3
@@ -1,42 +1,47 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class CollectionListingTest < Test::Unit::TestCase
4
-
5
5
  def test_get_collection_listings
6
- fake "collection_listings", method: :get, status: 201, body: load_fixture('collection_listings')
6
+ fake("collection_listings", method: :get, status: 201, body: load_fixture('collection_listings'))
7
7
 
8
8
  collection_listings = ShopifyAPI::CollectionListing.find(:all)
9
9
 
10
- assert_equal 1, collection_listings.count
11
- assert_equal 1, collection_listings.first.collection_id
12
- assert_equal 'Home page', collection_listings.first.title
10
+ assert_equal(1, collection_listings.count)
11
+ assert_equal(1, collection_listings.first.collection_id)
12
+ assert_equal('Home page', collection_listings.first.title)
13
13
  end
14
14
 
15
15
  def test_get_collection_listing
16
- fake "collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing')
16
+ fake("collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing'))
17
17
 
18
18
  collection_listing = ShopifyAPI::CollectionListing.find(1)
19
19
 
20
- assert_equal 1, collection_listing.collection_id
21
- assert_equal 'Home page', collection_listing.title
20
+ assert_equal(1, collection_listing.collection_id)
21
+ assert_equal('Home page', collection_listing.title)
22
22
  end
23
23
 
24
24
  def test_get_collection_listing_reload
25
- fake "collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing')
25
+ fake("collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing'))
26
26
 
27
27
  collection_listing = ShopifyAPI::CollectionListing.new(collection_id: 1)
28
28
  collection_listing.reload
29
29
 
30
- assert_equal 1, collection_listing.collection_id
31
- assert_equal 'Home page', collection_listing.title
30
+ assert_equal(1, collection_listing.collection_id)
31
+ assert_equal('Home page', collection_listing.title)
32
32
  end
33
33
 
34
34
  def test_get_collection_listing_product_ids
35
- fake "collection_listings/1/product_ids", method: :get, status: 201, body: load_fixture('collection_listing_product_ids')
35
+ fake(
36
+ "collection_listings/1/product_ids",
37
+ method: :get,
38
+ status: 201,
39
+ body: load_fixture('collection_listing_product_ids')
40
+ )
36
41
 
37
42
  collection_listing = ShopifyAPI::CollectionListing.new(collection_id: 1)
38
43
 
39
- assert_equal [1, 2], collection_listing.product_ids
44
+ assert_equal([1, 2], collection_listing.product_ids)
40
45
  end
41
46
 
42
47
  def test_get_collection_listing_product_ids_multi_page_with_cursor
@@ -61,8 +66,8 @@ class CollectionListingTest < Test::Unit::TestCase
61
66
  )
62
67
 
63
68
  product_ids = collection_listing.product_ids
64
- assert_equal [1, 2], product_ids
65
- assert product_ids.next_page?
69
+ assert_equal([1, 2], product_ids)
70
+ assert(product_ids.next_page?)
66
71
 
67
72
  fake(
68
73
  "collection_listings/1/product_ids",
@@ -74,6 +79,6 @@ class CollectionListingTest < Test::Unit::TestCase
74
79
  )
75
80
 
76
81
  next_page = product_ids.fetch_next_page
77
- assert_equal [3, 4], next_page
82
+ assert_equal([3, 4], next_page)
78
83
  end
79
84
  end
@@ -3,23 +3,23 @@ require 'test_helper'
3
3
 
4
4
  class CollectionPublicationTest < Test::Unit::TestCase
5
5
  def test_get_all_collection_publications
6
- fake 'publications/55650051/collection_publications', body: load_fixture('collection_publications')
6
+ fake('publications/55650051/collection_publications', body: load_fixture('collection_publications'))
7
7
  collection_publications = ShopifyAPI::CollectionPublication.find(:all, params: { publication_id: 55650051 })
8
8
 
9
- assert_equal 96062799894, collection_publications.first.id
10
- assert_equal 55650051, collection_publications.first.publication_id
9
+ assert_equal(96062799894, collection_publications.first.id)
10
+ assert_equal(55650051, collection_publications.first.publication_id)
11
11
  end
12
12
 
13
13
  def test_get_collection_publication
14
- fake 'publications/55650051/collection_publications/647162527768', body: load_fixture('collection_publication')
14
+ fake('publications/55650051/collection_publications/647162527768', body: load_fixture('collection_publication'))
15
15
  collection_publication = ShopifyAPI::CollectionPublication.find(647162527768, params: { publication_id: 55650051 })
16
16
 
17
- assert_equal 96062799894, collection_publication.id
18
- assert_equal 55650051, collection_publication.publication_id
17
+ assert_equal(96062799894, collection_publication.id)
18
+ assert_equal(55650051, collection_publication.publication_id)
19
19
  end
20
20
 
21
21
  def test_create_collection_publication
22
- fake 'publications/55650051/collection_publications', method: :post, body: load_fixture('collection_publication')
22
+ fake('publications/55650051/collection_publications', method: :post, body: load_fixture('collection_publication'))
23
23
  ShopifyAPI::CollectionPublication.create(
24
24
  publication_id: 55650051,
25
25
  published_at: "2018-01-29T14:06:08-05:00",
@@ -35,6 +35,6 @@ class CollectionPublicationTest < Test::Unit::TestCase
35
35
  },
36
36
  }.to_json
37
37
 
38
- assert_equal expected_body, WebMock.last_request.body
38
+ assert_equal(expected_body, WebMock.last_request.body)
39
39
  end
40
40
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class CollectionTest < Test::Unit::TestCase
@@ -6,23 +7,23 @@ class CollectionTest < Test::Unit::TestCase
6
7
  ShopifyAPI::Base.activate_session(available_version)
7
8
 
8
9
  fake(
9
- 'collections',
10
- url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1.json',
11
- method: :get,
12
- status: 200,
13
- body: load_fixture('collection'),
14
- extension: false
10
+ 'collections',
11
+ url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1.json',
12
+ method: :get,
13
+ status: 200,
14
+ body: load_fixture('collection'),
15
+ extension: false
15
16
  )
16
17
 
17
18
  collection = ShopifyAPI::Collection.find(1)
18
19
 
19
20
  fake(
20
- 'products',
21
- url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1/products.json',
22
- method: :get,
23
- status: 200,
24
- body: load_fixture('collection_products'),
25
- extension: false
21
+ 'products',
22
+ url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1/products.json',
23
+ method: :get,
24
+ status: 200,
25
+ body: load_fixture('collection_products'),
26
+ extension: false
26
27
  )
27
28
  assert_equal [632910392, 921728736], collection.products.map(&:id)
28
29
  end
@@ -32,17 +33,17 @@ class CollectionTest < Test::Unit::TestCase
32
33
  ShopifyAPI::Base.activate_session(old_version)
33
34
 
34
35
  fake(
35
- 'collections',
36
- url: 'https://shop2.myshopify.com/admin/api/2019-10/collections/1.json',
37
- method: :get,
38
- status: 200,
39
- body: load_fixture('collection'),
40
- extension: false
36
+ 'collections',
37
+ url: 'https://shop2.myshopify.com/admin/api/2019-10/collections/1.json',
38
+ method: :get,
39
+ status: 200,
40
+ body: load_fixture('collection'),
41
+ extension: false
41
42
  )
42
43
 
43
44
  collection = ShopifyAPI::Collection.find(1)
44
45
 
45
- assert_raises NotImplementedError do
46
+ assert_raises(NotImplementedError) do
46
47
  collection.products
47
48
  end
48
49
  end
@@ -1,13 +1,14 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class CountableTest < Test::Unit::TestCase
4
5
  def setup
5
6
  super
6
- fake "products/count", :body => '{"count": 16}'
7
+ fake("products/count", body: '{"count": 16}')
7
8
  end
8
9
 
9
10
  def test_count_products
10
11
  count = ShopifyAPI::Product.count
11
- assert_equal 16, count
12
+ assert_equal(16, count)
12
13
  end
13
14
  end
@@ -4,17 +4,17 @@ require 'test_helper'
4
4
  class CurrencyTest < Test::Unit::TestCase
5
5
  def setup
6
6
  super
7
- fake "currencies", method: :get, body: load_fixture('currencies')
7
+ fake("currencies", method: :get, body: load_fixture('currencies'))
8
8
  end
9
9
 
10
10
  context "Currency" do
11
11
  should 'return a list of enabled currencies' do
12
12
  currencies = ShopifyAPI::Currency.all
13
- assert_equal 4, currencies.count
14
- assert_equal %w(AUD EUR GBP HKD), currencies.map(&:currency)
15
- assert_equal [true, true, true, false], currencies.map(&:enabled)
13
+ assert_equal(4, currencies.count)
14
+ assert_equal(%w(AUD EUR GBP HKD), currencies.map(&:currency))
15
+ assert_equal([true, true, true, false], currencies.map(&:enabled))
16
16
  currencies.each do |currency|
17
- assert_equal "2018-10-03T14:44:08-04:00", currency.rate_updated_at
17
+ assert_equal("2018-10-03T14:44:08-04:00", currency.rate_updated_at)
18
18
  end
19
19
  end
20
20
  end
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class CustomCollectionTest < Test::Unit::TestCase
4
5
  test "#create should create a custom collection" do
5
- fake "custom_collections", :method => :post, :status => 201, :body => load_fixture('custom_collection')
6
- link = ShopifyAPI::CustomCollection.create(:title => "Macbooks", :image => { :src => "http://example.com/rails_logo.gif" })
7
- assert_equal 1063001463, link.id
6
+ fake("custom_collections", method: :post, status: 201, body: load_fixture('custom_collection'))
7
+ link = ShopifyAPI::CustomCollection.create(title: "Macbooks", image: { src: "http://example.com/rails_logo.gif" })
8
+ assert_equal(1063001463, link.id)
8
9
  end
9
10
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class CustomerSavedSearchTest < Test::Unit::TestCase
@@ -7,21 +8,30 @@ class CustomerSavedSearchTest < Test::Unit::TestCase
7
8
  end
8
9
 
9
10
  def test_get_customers_from_customer_saved_search
10
- fake 'customers/search.json?customer_saved_search_id=8899730', :body => load_fixture('customer_saved_search_customers'), :extension => false
11
- assert_equal 1, @customer_saved_search.customers.length
12
- assert_equal 112223902, @customer_saved_search.customers.first.id
11
+ fake(
12
+ 'customers/search.json?customer_saved_search_id=8899730',
13
+ body: load_fixture('customer_saved_search_customers'),
14
+ extension: false
15
+ )
16
+ assert_equal(1, @customer_saved_search.customers.length)
17
+ assert_equal(112223902, @customer_saved_search.customers.first.id)
13
18
  end
14
19
 
15
20
  def test_get_customers_from_customer_saved_search_with_params
16
- fake 'customers/search.json?customer_saved_search_id=8899730&limit=1', :body => load_fixture('customer_saved_search_customers'), :extension => false
17
- customers = @customer_saved_search.customers(:limit => 1)
18
- assert_equal 1, customers.length
19
- assert_equal 112223902, customers.first.id
21
+ fake(
22
+ 'customers/search.json?customer_saved_search_id=8899730&limit=1',
23
+ body: load_fixture('customer_saved_search_customers'),
24
+ extension: false
25
+ )
26
+ customers = @customer_saved_search.customers(limit: 1)
27
+ assert_equal(1, customers.length)
28
+ assert_equal(112223902, customers.first.id)
20
29
  end
21
30
 
22
31
  private
32
+
23
33
  def load_customer_saved_search
24
- fake 'customer_saved_searches/8899730', :body => load_fixture('customer_saved_search')
34
+ fake('customer_saved_searches/8899730', body: load_fixture('customer_saved_search'))
25
35
  @customer_saved_search = ShopifyAPI::CustomerSavedSearch.find(8899730)
26
36
  end
27
37
  end
@@ -1,50 +1,58 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class CustomerTest < Test::Unit::TestCase
4
5
  def setup
5
6
  super
6
7
 
7
- fake 'customers/207119551', body: load_fixture('customers')
8
+ fake('customers/207119551', body: load_fixture('customers'))
8
9
 
9
10
  @customer = ShopifyAPI::Customer.find(207119551)
10
11
  end
11
12
 
12
13
  test "search should get a customers collection" do
13
- fake "customers/search.json?query=Bob+country%3AUnited+States", :extension => false, :body => load_fixture('customers_search')
14
+ fake(
15
+ "customers/search.json?query=Bob+country%3AUnited+States",
16
+ extension: false,
17
+ body: load_fixture('customers_search')
18
+ )
14
19
 
15
20
  results = ShopifyAPI::Customer.search(query: 'Bob country:United States')
16
- assert_equal 'Bob', results.first.first_name
21
+ assert_equal('Bob', results.first.first_name)
17
22
  end
18
23
 
19
24
  test "account_activation_url should create an account activation url" do
20
- fake "customers/207119551/account_activation_url", :method => :post, :body => load_fixture('customers_account_activation_url')
25
+ fake(
26
+ "customers/207119551/account_activation_url",
27
+ method: :post,
28
+ body: load_fixture('customers_account_activation_url')
29
+ )
21
30
 
22
31
  activation_url = "http://apple.myshopify.com/account/activate/207119551/86688abf23572680740b1c062fa37111-1458248616"
23
- assert_equal activation_url, @customer.account_activation_url
32
+ assert_equal(activation_url, @customer.account_activation_url)
24
33
  end
25
34
 
26
35
  test "#send_invite with no params" do
27
36
  customer_invite_fixture = load_fixture('customer_invite')
28
37
  customer_invite = ActiveSupport::JSON.decode(customer_invite_fixture)
29
- fake 'customers/207119551/send_invite', method: :post, body: customer_invite_fixture
38
+ fake('customers/207119551/send_invite', method: :post, body: customer_invite_fixture)
30
39
 
31
40
  customer_invite_response = @customer.send_invite
32
41
 
33
- assert_equal '{"customer_invite":{}}', WebMock.last_request.body
34
- assert_kind_of ShopifyAPI::CustomerInvite, customer_invite_response
35
- assert_equal customer_invite['customer_invite']['to'], customer_invite_response.to
42
+ assert_equal('{"customer_invite":{}}', WebMock.last_request.body)
43
+ assert_kind_of(ShopifyAPI::CustomerInvite, customer_invite_response)
44
+ assert_equal(customer_invite['customer_invite']['to'], customer_invite_response.to)
36
45
  end
37
46
 
38
47
  test "#send_invite with params" do
39
48
  customer_invite_fixture = load_fixture('customer_invite')
40
49
  customer_invite = ActiveSupport::JSON.decode(customer_invite_fixture)
41
- fake 'customers/207119551/send_invite', method: :post, body: customer_invite_fixture
42
-
50
+ fake('customers/207119551/send_invite', method: :post, body: customer_invite_fixture)
43
51
 
44
52
  customer_invite_response = @customer.send_invite(ShopifyAPI::CustomerInvite.new(customer_invite['customer_invite']))
45
53
 
46
- assert_equal customer_invite, ActiveSupport::JSON.decode(WebMock.last_request.body)
47
- assert_kind_of ShopifyAPI::CustomerInvite, customer_invite_response
48
- assert_equal customer_invite['customer_invite']['to'], customer_invite_response.to
54
+ assert_equal(customer_invite, ActiveSupport::JSON.decode(WebMock.last_request.body))
55
+ assert_kind_of(ShopifyAPI::CustomerInvite, customer_invite_response)
56
+ assert_equal(customer_invite['customer_invite']['to'], customer_invite_response.to)
49
57
  end
50
58
  end
@@ -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
  require 'json'
@@ -9,18 +10,21 @@ class LogSubscriberTest < Test::Unit::TestCase
9
10
 
10
11
  def setup
11
12
  super
12
- @page = { :page => { :id => 1, :title => 'Shopify API' } }.to_json
13
- @ua_header = "\"User-Agent\"=>\"ShopifyAPI/#{ShopifyAPI::VERSION} ActiveResource/#{ActiveResource::VERSION::STRING} Ruby/#{RUBY_VERSION}\""
13
+ @page = { page: { id: 1, title: 'Shopify API' } }.to_json
14
+ @ua_header = "\"User-Agent\"=>\"ShopifyAPI/#{ShopifyAPI::VERSION} " \
15
+ "ActiveResource/#{ActiveResource::VERSION::STRING} Ruby/#{RUBY_VERSION}\""
14
16
  @request_headers = "Headers: {\"Accept\"=>\"application/json\", " \
15
- "#{@ua_header}, \"X-Shopify-Access-Token\"=>\"access_token\"}"
17
+ "#{@ua_header}, \"X-Shopify-Access-Token\"=>\"[FILTERED]\"}"
16
18
 
17
19
  ShopifyAPI::Base.clear_session
18
- fake("apis",
20
+ fake(
21
+ "apis",
19
22
  url: "https://app.shopify.com/services/apis.json",
20
23
  method: :get,
21
24
  status: 200,
22
25
  api_version: :stub,
23
- body: load_fixture('apis'))
26
+ body: load_fixture('apis')
27
+ )
24
28
  ShopifyAPI::ApiVersion.fetch_known_versions
25
29
  session = ShopifyAPI::Session.new(
26
30
  domain: "https://this-is-my-test-shop.myshopify.com",
@@ -30,8 +34,8 @@ class LogSubscriberTest < Test::Unit::TestCase
30
34
 
31
35
  ShopifyAPI::Base.activate_session(session)
32
36
 
33
- ActiveResource::LogSubscriber.attach_to :active_resource
34
- ActiveResource::DetailedLogSubscriber.attach_to :active_resource_detailed
37
+ ActiveResource::LogSubscriber.attach_to(:active_resource)
38
+ ActiveResource::DetailedLogSubscriber.attach_to(:active_resource_detailed)
35
39
  end
36
40
 
37
41
  def teardown
@@ -45,7 +49,7 @@ class LogSubscriberTest < Test::Unit::TestCase
45
49
  end
46
50
 
47
51
  test "logging on #find" do
48
- fake "pages/1", :method => :get, :body => @page
52
+ fake("pages/1", method: :get, body: @page)
49
53
 
50
54
  ShopifyAPI::Page.find(1)
51
55
 
@@ -64,9 +68,9 @@ class LogSubscriberTest < Test::Unit::TestCase
64
68
  end
65
69
 
66
70
  test "logging on #find with an error" do
67
- fake "pages/2", :method => :get, :body => nil, :status => 404
71
+ fake("pages/2", method: :get, body: nil, status: 404)
68
72
 
69
- assert_raises ActiveResource::ResourceNotFound do
73
+ assert_raises(ActiveResource::ResourceNotFound) do
70
74
  ShopifyAPI::Page.find(2)
71
75
  end
72
76
 
@@ -103,7 +107,7 @@ class LogSubscriberTest < Test::Unit::TestCase
103
107
 
104
108
  ShopifyAPI::Page.find(1)
105
109
 
106
- assert_equal 1, @logger.logged(:warn).size
110
+ assert_equal(1, @logger.logged(:warn).size)
107
111
 
108
112
  assert_match(
109
113
  %r{\[DEPRECATED\] ShopifyAPI made a call to GET /admin/api/2019-01/pages/1.json},
@@ -125,7 +129,7 @@ class LogSubscriberTest < Test::Unit::TestCase
125
129
 
126
130
  ShopifyAPI::Page.find(1)
127
131
 
128
- assert_equal 1, @logger.logged(:warn).size
132
+ assert_equal(1, @logger.logged(:warn).size)
129
133
 
130
134
  assert_match(
131
135
  %r{\[API Version Warning\] ShopifyAPI made a call to GET /admin/api/2019-01/pages/1.json},
@@ -4,30 +4,31 @@ require 'test_helper'
4
4
  class DiscountCodeBatchTest < Test::Unit::TestCase
5
5
  def setup
6
6
  super
7
- fake 'price_rules/102586120/batch/989355119', body: load_fixture('discount_code_batch')
7
+ fake('price_rules/102586120/batch/989355119', body: load_fixture('discount_code_batch'))
8
8
  end
9
9
 
10
10
  def test_get_batch
11
- batch = ShopifyAPI::DiscountCodeBatch.find 989355119, params: { price_rule_id: 102586120 }
11
+ batch = ShopifyAPI::DiscountCodeBatch.find(989355119, params: { price_rule_id: 102586120 })
12
12
 
13
- assert_equal 989355119, batch.id
13
+ assert_equal(989355119, batch.id)
14
14
  end
15
15
 
16
16
  def test_get_batch_discount_codes
17
- fake 'price_rules/102586120/batch/989355119/discount_codes',
17
+ fake(
18
+ 'price_rules/102586120/batch/989355119/discount_codes',
18
19
  method: :get,
19
20
  status: 200,
20
21
  body: load_fixture('discount_code_batch_discount_codes')
21
-
22
- batch = ShopifyAPI::DiscountCodeBatch.find 989355119, params: { price_rule_id: 102586120 }
22
+ )
23
+ batch = ShopifyAPI::DiscountCodeBatch.find(989355119, params: { price_rule_id: 102586120 })
23
24
  discount_code_job = batch.discount_code_job
24
25
 
25
- assert_equal 3, discount_code_job.count
26
- assert discount_code_job[2].errors.present?
26
+ assert_equal(3, discount_code_job.count)
27
+ assert(discount_code_job[2].errors.present?)
27
28
  end
28
29
 
29
30
  def test_create_batch
30
- fake 'price_rules/102586120/batch', method: :post, status: 201, body: load_fixture('discount_code_batch')
31
+ fake('price_rules/102586120/batch', method: :post, status: 201, body: load_fixture('discount_code_batch'))
31
32
  batch = ShopifyAPI::DiscountCodeBatch.new
32
33
  batch.prefix_options[:price_rule_id] = 102586120
33
34
  discount_codes = [{ "code": "SUMMER1" }, { "code": "SUMMER2" }, { "code": "SUMMER3" }]
@@ -35,6 +36,6 @@ class DiscountCodeBatchTest < Test::Unit::TestCase
35
36
  batch.save
36
37
 
37
38
  expected_body = { discount_codes: discount_codes }.to_json
38
- assert_equal expected_body, WebMock.last_request.body
39
+ assert_equal(expected_body, WebMock.last_request.body)
39
40
  end
40
41
  end
@@ -1,36 +1,37 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class DiscountCodeTest < Test::Unit::TestCase
4
5
  def setup
5
6
  super
6
- fake 'price_rules/102586120/discount_codes/1002091923', body: load_fixture('discount_code')
7
+ fake('price_rules/102586120/discount_codes/1002091923', body: load_fixture('discount_code'))
7
8
 
8
- @discount_code = ShopifyAPI::DiscountCode.find(1002091923, params: {price_rule_id: 102586120})
9
+ @discount_code = ShopifyAPI::DiscountCode.find(1002091923, params: { price_rule_id: 102586120 })
9
10
  end
10
11
 
11
12
  def test_get_discount_code
12
- fake 'price_rules/102586120/discount_codes', method: :get, status: 200, body: load_fixture('discount_code')
13
- discount_code = ShopifyAPI::DiscountCode.find 1002091923, params: { price_rule_id: 102586120 }
13
+ fake('price_rules/102586120/discount_codes', method: :get, status: 200, body: load_fixture('discount_code'))
14
+ discount_code = ShopifyAPI::DiscountCode.find(1002091923, params: { price_rule_id: 102586120 })
14
15
 
15
- assert_equal 1002091923, discount_code.id
16
+ assert_equal(1002091923, discount_code.id)
16
17
  end
17
18
 
18
19
  def test_get_all_discount_codes
19
- fake 'price_rules/102586120/discount_codes', method: :get, status: 200, body: load_fixture('discount_codes')
20
- discount_codes = ShopifyAPI::DiscountCode.all params: { price_rule_id: 102586120 }
20
+ fake('price_rules/102586120/discount_codes', method: :get, status: 200, body: load_fixture('discount_codes'))
21
+ discount_codes = ShopifyAPI::DiscountCode.all(params: { price_rule_id: 102586120 })
21
22
 
22
- assert_equal 1, discount_codes.length
23
- assert_equal 1002091923, discount_codes.first.id
23
+ assert_equal(1, discount_codes.length)
24
+ assert_equal(1002091923, discount_codes.first.id)
24
25
  end
25
26
 
26
27
  def test_create_discount_code
27
- fake 'price_rules/102586120/discount_codes', method: :post, status: 201, body: load_fixture('discount_code')
28
+ fake('price_rules/102586120/discount_codes', method: :post, status: 201, body: load_fixture('discount_code'))
28
29
  discount_code = ShopifyAPI::DiscountCode.new
29
30
  discount_code.prefix_options[:price_rule_id] = 102586120
30
31
  discount_code.code = "SUMMERSALE10"
31
32
  discount_code.save
32
33
 
33
- assert_equal '{"discount_code":{"code":"SUMMERSALE10"}}', WebMock.last_request.body
34
+ assert_equal('{"discount_code":{"code":"SUMMERSALE10"}}', WebMock.last_request.body)
34
35
  end
35
36
 
36
37
  def test_update_discount_code
@@ -38,16 +39,21 @@ class DiscountCodeTest < Test::Unit::TestCase
38
39
  discount_code_response['discount_code']['code'] = "WINTERSALE50"
39
40
  @discount_code.code = "WINTERSALE50"
40
41
 
41
- fake 'price_rules/102586120/discount_codes/1002091923', method: :put, status: 200, body: ActiveSupport::JSON.encode(discount_code_response)
42
+ fake(
43
+ 'price_rules/102586120/discount_codes/1002091923',
44
+ method: :put,
45
+ status: 200,
46
+ body: ActiveSupport::JSON.encode(discount_code_response)
47
+ )
42
48
 
43
49
  @discount_code.save
44
50
 
45
- assert_equal discount_code_response['discount_code']['code'], @discount_code.code
51
+ assert_equal(discount_code_response['discount_code']['code'], @discount_code.code)
46
52
  end
47
53
 
48
54
  def test_delete_discount_code
49
- fake 'price_rules/102586120/discount_codes/1002091923', method: :delete, body: 'destroyed'
55
+ fake('price_rules/102586120/discount_codes/1002091923', method: :delete, body: 'destroyed')
50
56
 
51
- assert @discount_code.destroy
57
+ assert(@discount_code.destroy)
52
58
  end
53
59
  end