shopify_api 9.0.2 → 9.3.0

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 (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,37 +1,38 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class PriceRuleTest < Test::Unit::TestCase
4
5
  def setup
5
6
  super
6
- fake 'price_rules/102586120', body: load_fixture('price_rule')
7
+ fake('price_rules/102586120', body: load_fixture('price_rule'))
7
8
 
8
9
  @price_rule = ShopifyAPI::PriceRule.find(102586120)
9
10
  end
10
11
 
11
12
  def test_get_price_rule
12
- fake 'price_rules/102586120', method: :get, status: 200, body: load_fixture('price_rule')
13
+ fake('price_rules/102586120', method: :get, status: 200, body: load_fixture('price_rule'))
13
14
  price_rule = ShopifyAPI::PriceRule.find(102586120)
14
15
 
15
- assert_equal 102586120, price_rule.id
16
+ assert_equal(102586120, price_rule.id)
16
17
  end
17
18
 
18
19
  def test_get_all_price_rules
19
- fake 'price_rules', method: :get, status: 200, body: load_fixture('price_rules')
20
+ fake('price_rules', method: :get, status: 200, body: load_fixture('price_rules'))
20
21
  price_rules = ShopifyAPI::PriceRule.all
21
22
 
22
- assert_equal 1, price_rules.length
23
- assert_equal 102586120, price_rules.first.id
23
+ assert_equal(1, price_rules.length)
24
+ assert_equal(102586120, price_rules.first.id)
24
25
  end
25
26
 
26
27
  def test_get_all_discount_codes_for_a_price_rule
27
- fake 'price_rules/102586120/discount_codes', method: :get, status: 200, body: load_fixture('discount_codes')
28
+ fake('price_rules/102586120/discount_codes', method: :get, status: 200, body: load_fixture('discount_codes'))
28
29
  price_rule = ShopifyAPI::PriceRule.find(102586120)
29
30
 
30
- assert_equal "SUMMERSALE10", price_rule.discount_codes.first.code
31
+ assert_equal("SUMMERSALE10", price_rule.discount_codes.first.code)
31
32
  end
32
33
 
33
34
  def test_create_price_rule
34
- fake 'price_rules', method: :post, status: 201, body: load_fixture('price_rule')
35
+ fake('price_rules', method: :post, status: 201, body: load_fixture('price_rule'))
35
36
 
36
37
  price_rule = ShopifyAPI::PriceRule.create(
37
38
  target_type: "line_item",
@@ -42,24 +43,28 @@ class PriceRuleTest < Test::Unit::TestCase
42
43
  starts_at: "2017-01-19T00:00:00Z"
43
44
  )
44
45
 
45
- assert_equal '{"price_rule":{"target_type":"line_item","allocation_method":"across","value_type":"fixed_amount","value":-10.0,"customer_selection":"all","starts_at":"2017-01-19T00:00:00Z"}}', WebMock.last_request.body
46
- assert_equal -10, price_rule.value
46
+ assert_equal(
47
+ '{"price_rule":{"target_type":"line_item","allocation_method":"across","value_type":"fixed_amount",' \
48
+ '"value":-10.0,"customer_selection":"all","starts_at":"2017-01-19T00:00:00Z"}}',
49
+ WebMock.last_request.body
50
+ )
51
+ assert_equal(-10, price_rule.value)
47
52
  end
48
53
 
49
54
  def test_update_price_rule
50
55
  price_rule_response = ActiveSupport::JSON.decode(load_fixture('price_rule'))
51
56
  price_rule_response['price_rule']['value'] = -50.0
52
57
  @price_rule.value = -50.0
53
- fake 'price_rules/102586120', method: :put, status: 200, body: ActiveSupport::JSON.encode(price_rule_response)
58
+ fake('price_rules/102586120', method: :put, status: 200, body: ActiveSupport::JSON.encode(price_rule_response))
54
59
 
55
60
  @price_rule.save
56
61
 
57
- assert_equal price_rule_response['price_rule']['value'], @price_rule.value
62
+ assert_equal(price_rule_response['price_rule']['value'], @price_rule.value)
58
63
  end
59
64
 
60
65
  def test_delete_price_rule
61
- fake 'price_rules/102586120', method: :delete, body: 'destroyed'
66
+ fake('price_rules/102586120', method: :delete, body: 'destroyed')
62
67
 
63
- assert @price_rule.destroy
68
+ assert(@price_rule.destroy)
64
69
  end
65
70
  end
@@ -1,41 +1,41 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class ProductListingTest < Test::Unit::TestCase
4
-
5
5
  def test_get_product_listings
6
- fake "product_listings", method: :get, status: 201, body: load_fixture('product_listings')
6
+ fake("product_listings", method: :get, status: 201, body: load_fixture('product_listings'))
7
7
 
8
8
  product_listings = ShopifyAPI::ProductListing.find(:all)
9
- assert_equal 2, product_listings.count
10
- assert_equal 2, product_listings.first.product_id
11
- assert_equal 1, product_listings.last.product_id
12
- assert_equal 'Synergistic Silk Chair', product_listings.first.title
13
- assert_equal 'Rustic Copper Bottle', product_listings.last.title
9
+ assert_equal(2, product_listings.count)
10
+ assert_equal(2, product_listings.first.product_id)
11
+ assert_equal(1, product_listings.last.product_id)
12
+ assert_equal('Synergistic Silk Chair', product_listings.first.title)
13
+ assert_equal('Rustic Copper Bottle', product_listings.last.title)
14
14
  end
15
15
 
16
16
  def test_get_product_listing
17
- fake "product_listings/2", method: :get, status: 201, body: load_fixture('product_listing')
17
+ fake("product_listings/2", method: :get, status: 201, body: load_fixture('product_listing'))
18
18
 
19
19
  product_listing = ShopifyAPI::ProductListing.find(2)
20
- assert_equal 'Synergistic Silk Chair', product_listing.title
20
+ assert_equal('Synergistic Silk Chair', product_listing.title)
21
21
  end
22
22
 
23
23
  def test_reload_product_listing
24
- fake "product_listings/2", method: :get, status: 201, body: load_fixture('product_listing')
24
+ fake("product_listings/2", method: :get, status: 201, body: load_fixture('product_listing'))
25
25
 
26
26
  product_listing = ShopifyAPI::ProductListing.new(product_id: 2)
27
27
  product_listing.reload
28
28
 
29
- assert_equal 'Synergistic Silk Chair', product_listing.title
29
+ assert_equal('Synergistic Silk Chair', product_listing.title)
30
30
  end
31
31
 
32
32
  def test_get_product_listing_product_ids
33
- fake "product_listings/product_ids", method: :get, status: 201, body: load_fixture('product_listing_product_ids')
33
+ fake("product_listings/product_ids", method: :get, status: 201, body: load_fixture('product_listing_product_ids'))
34
34
 
35
35
  product_ids = ShopifyAPI::ProductListing.product_ids
36
- assert_equal 2, product_ids.count
37
- assert_equal 4, product_ids.first
38
- assert_equal 3, product_ids.last
36
+ assert_equal(2, product_ids.count)
37
+ assert_equal(4, product_ids.first)
38
+ assert_equal(3, product_ids.last)
39
39
  end
40
40
 
41
41
  def test_get_product_listing_product_ids_multi_page_with_cursor
@@ -58,8 +58,8 @@ class ProductListingTest < Test::Unit::TestCase
58
58
  )
59
59
 
60
60
  product_ids = ShopifyAPI::ProductListing.product_ids
61
- assert_equal [4, 3], product_ids
62
- assert product_ids.next_page?
61
+ assert_equal([4, 3], product_ids)
62
+ assert(product_ids.next_page?)
63
63
 
64
64
  fake(
65
65
  "product_listings/product_ids",
@@ -71,7 +71,7 @@ class ProductListingTest < Test::Unit::TestCase
71
71
  )
72
72
 
73
73
  next_page = product_ids.fetch_next_page
74
- assert_equal [2, 1], next_page
74
+ assert_equal([2, 1], next_page)
75
75
  end
76
76
 
77
77
  def test_get_product_listing_product_ids_multi_page_with_cursor_fails_on_older_api_version
@@ -89,8 +89,8 @@ class ProductListingTest < Test::Unit::TestCase
89
89
  )
90
90
 
91
91
  product_ids = ShopifyAPI::ProductListing.product_ids
92
- assert_equal [4, 3], product_ids
93
- assert_raises NotImplementedError do
92
+ assert_equal([4, 3], product_ids)
93
+ assert_raises(NotImplementedError) do
94
94
  product_ids.next_page?
95
95
  end
96
96
  end
@@ -3,23 +3,23 @@ require 'test_helper'
3
3
 
4
4
  class ProductPublicationTest < Test::Unit::TestCase
5
5
  def test_get_all_product_publications
6
- fake 'publications/55650051/product_publications', body: load_fixture('product_publications')
6
+ fake('publications/55650051/product_publications', body: load_fixture('product_publications'))
7
7
  product_publications = ShopifyAPI::ProductPublication.find(:all, params: { publication_id: 55650051 })
8
8
 
9
- assert_equal 647162527768, product_publications.first.id
10
- assert_equal 55650051, product_publications.first.publication_id
9
+ assert_equal(647162527768, product_publications.first.id)
10
+ assert_equal(55650051, product_publications.first.publication_id)
11
11
  end
12
12
 
13
13
  def test_get_product_publication
14
- fake 'publications/55650051/product_publications/647162527768', body: load_fixture('product_publication')
14
+ fake('publications/55650051/product_publications/647162527768', body: load_fixture('product_publication'))
15
15
  product_publication = ShopifyAPI::ProductPublication.find(647162527768, params: { publication_id: 55650051 })
16
16
 
17
- assert_equal 647162527768, product_publication.id
18
- assert_equal 55650051, product_publication.publication_id
17
+ assert_equal(647162527768, product_publication.id)
18
+ assert_equal(55650051, product_publication.publication_id)
19
19
  end
20
20
 
21
21
  def test_create_product_publication
22
- fake 'publications/55650051/product_publications', method: :post, body: load_fixture('product_publication')
22
+ fake('publications/55650051/product_publications', method: :post, body: load_fixture('product_publication'))
23
23
  ShopifyAPI::ProductPublication.create(
24
24
  publication_id: 55650051,
25
25
  published_at: "2018-01-29T14:06:08-05:00",
@@ -35,6 +35,6 @@ class ProductPublicationTest < 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,47 +1,54 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class ProductTest < Test::Unit::TestCase
4
5
  def setup
5
6
  super
6
7
 
7
- fake "products/632910392", :body => load_fixture('product')
8
- @product = ShopifyAPI::Product.find(632910392)
8
+ refresh_product
9
9
  end
10
10
 
11
11
  def test_add_metafields_to_product
12
- fake "products/632910392/metafields", :method => :post, :status => 201, :body => load_fixture('metafield')
13
-
14
- field = @product.add_metafield(ShopifyAPI::Metafield.new(:namespace => "contact", :key => "email", :value => "123@example.com", :value_type => "string"))
15
- assert_equal ActiveSupport::JSON.decode('{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'), ActiveSupport::JSON.decode(WebMock.last_request.body)
16
- assert !field.new_record?
17
- assert_equal "contact", field.namespace
18
- assert_equal "email", field.key
19
- assert_equal "123@example.com", field.value
12
+ fake("products/632910392/metafields", method: :post, status: 201, body: load_fixture('metafield'))
13
+
14
+ field = @product.add_metafield(
15
+ ShopifyAPI::Metafield.new(namespace: "contact", key: "email", value: "123@example.com", value_type: "string")
16
+ )
17
+ assert_equal(
18
+ ActiveSupport::JSON.decode(
19
+ '{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'
20
+ ),
21
+ ActiveSupport::JSON.decode(WebMock.last_request.body)
22
+ )
23
+ assert(!field.new_record?)
24
+ assert_equal("contact", field.namespace)
25
+ assert_equal("email", field.key)
26
+ assert_equal("123@example.com", field.value)
20
27
  end
21
28
 
22
29
  def test_get_all_metafields_for_product
23
- fake "products/632910392/metafields", :body => load_fixture('metafields')
30
+ fake("products/632910392/metafields", body: load_fixture('metafields'))
24
31
 
25
32
  metafields = @product.metafields
26
33
 
27
- assert_equal 3, metafields.length
28
- assert metafields.all?{ |m| m.is_a? ShopifyAPI::Metafield }
34
+ assert_equal(3, metafields.length)
35
+ assert(metafields.all? { |m| m.is_a?(ShopifyAPI::Metafield) })
29
36
  end
30
37
 
31
38
  def test_get_2_metafields_for_product
32
- body = ActiveSupport::JSON.decode load_fixture 'metafields'
33
- body['metafields'].slice! 2, 1
39
+ body = ActiveSupport::JSON.decode(load_fixture('metafields'))
40
+ body['metafields'].slice!(2, 1)
34
41
 
35
- fake 'products/632910392/metafields.json?limit=2', body: body.to_json, extension: false
42
+ fake('products/632910392/metafields.json?limit=2', body: body.to_json, extension: false)
36
43
 
37
- metafields = @product.metafields limit: 2
44
+ metafields = @product.metafields(limit: 2)
38
45
 
39
- assert_equal 2, metafields.length
40
- assert metafields.all?{ |m| m.is_a? ShopifyAPI::Metafield }
46
+ assert_equal(2, metafields.length)
47
+ assert(metafields.all? { |m| m.is_a?(ShopifyAPI::Metafield) })
41
48
  end
42
49
 
43
50
  def test_update_loaded_variant
44
- fake "products/632910392/variants/808950810", :method => :put, :status => 200, :body => load_fixture('variant')
51
+ fake("products/632910392/variants/808950810", method: :put, status: 200, body: load_fixture('variant'))
45
52
 
46
53
  variant = @product.variants.first
47
54
  variant.price = "0.50"
@@ -57,4 +64,48 @@ class ProductTest < Test::Unit::TestCase
57
64
 
58
65
  assert_equal('100.00 - 199.00', @product.price_range)
59
66
  end
67
+
68
+ def test_read_only_variant_inventory_fields_not_removed_in_2020_01
69
+ ShopifyAPI::Base.api_version = '2020-01'
70
+ refresh_product(api_version: ShopifyAPI::Base.api_version)
71
+
72
+ variant = @product.variants.first
73
+ assert_equal(10, variant.inventory_quantity)
74
+ end
75
+
76
+ def test_deprecated_inventory_fields_are_removed_in_2020_01
77
+ ShopifyAPI::Base.api_version = '2020-01'
78
+ refresh_product(api_version: ShopifyAPI::Base.api_version)
79
+
80
+ refute(@product.as_json.include?('total_inventory'))
81
+ end
82
+
83
+ def test_setting_product_total_inventory_passes_in_api_before_2019_10
84
+ ShopifyAPI::Base.api_version = '2019-07'
85
+ refresh_product(api_version: ShopifyAPI::Base.api_version)
86
+ @product.total_inventory = 8
87
+ end
88
+
89
+ def test_setting_product_total_inventory_fails_in_2019_10_api
90
+ ShopifyAPI::Base.api_version = '2019-10'
91
+ refresh_product(api_version: ShopifyAPI::Base.api_version)
92
+ assert_raises(ShopifyAPI::ValidationException) do
93
+ @product.total_inventory = 8
94
+ end
95
+ end
96
+
97
+ def test_setting_product_total_inventory_fails_in_the_unstable_api
98
+ ShopifyAPI::Base.api_version = :unstable
99
+ refresh_product(api_version: ShopifyAPI::Base.api_version)
100
+ assert_raises(ShopifyAPI::ValidationException) do
101
+ @product.total_inventory = 8
102
+ end
103
+ end
104
+
105
+ private
106
+
107
+ def refresh_product(api_version: nil)
108
+ fake("products/632910392", body: load_fixture('product'), api_version: api_version)
109
+ @product = ShopifyAPI::Product.find(632910392)
110
+ end
60
111
  end
@@ -3,10 +3,10 @@ require 'test_helper'
3
3
 
4
4
  class PublicationTest < Test::Unit::TestCase
5
5
  def test_find_all_publications
6
- fake 'publications'
6
+ fake('publications')
7
7
  publications = ShopifyAPI::Publication.find(:all)
8
8
 
9
- assert_equal 55650051, publications.first.id
10
- assert_equal "Buy Button", publications.first.name
9
+ assert_equal(55650051, publications.first.id)
10
+ assert_equal("Buy Button", publications.first.name)
11
11
  end
12
12
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class RecurringApplicationChargeTest < Test::Unit::TestCase
4
-
5
5
  def test_recurring_application_charges_create
6
- fake "recurring_application_charges", method: :post, status: 201, body: load_fixture('recurring_application_charge')
6
+ fake(
7
+ "recurring_application_charges", method: :post, status: 201, body: load_fixture('recurring_application_charge')
8
+ )
7
9
 
8
10
  charge = ShopifyAPI::RecurringApplicationCharge.create(
9
11
  name: "Default Plan",
@@ -11,132 +13,192 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
11
13
  return_url: "http://test.com/confirm"
12
14
  )
13
15
 
14
- assert_equal 'http://apple.myshopify.com/admin/charges/654381177/confirm_recurring_application_charge?signature=BAhpBHkQASc%3D--419fc7424f8c290ac2b21b9004ed223e35b52164', charge.confirmation_url
16
+ assert_equal(
17
+ 'http://apple.myshopify.com/admin/charges/654381177/confirm_recurring_application_charge?' \
18
+ 'signature=BAhpBHkQASc%3D--419fc7424f8c290ac2b21b9004ed223e35b52164',
19
+ charge.confirmation_url
20
+ )
15
21
  end
16
22
 
17
23
  def test_get_recurring_application_charges
18
- fake "recurring_application_charges/654381177", method: :get, status: 201, body: load_fixture('recurring_application_charge')
24
+ fake(
25
+ "recurring_application_charges/654381177",
26
+ method: :get,
27
+ status: 201,
28
+ body: load_fixture('recurring_application_charge')
29
+ )
19
30
 
20
31
  charge = ShopifyAPI::RecurringApplicationCharge.find(654381177)
21
32
 
22
- assert_equal "Super Duper Plan", charge.name
33
+ assert_equal("Super Duper Plan", charge.name)
23
34
  end
24
35
 
25
36
  def test_list_recurring_application_charges
26
- fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
37
+ fake(
38
+ "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
39
+ )
27
40
 
28
41
  charge = ShopifyAPI::RecurringApplicationCharge.find(:all)
29
42
 
30
- assert_equal "Super Mega Plan", charge.last.name
43
+ assert_equal("Super Mega Plan", charge.last.name)
31
44
  end
32
45
 
33
46
  def test_list_since_recurring_application_charges
34
- fake "recurring_application_charges.json?since_id=64512345",extension: false, method: :get, status: 201, body: load_fixture('recurring_application_charges')
47
+ fake(
48
+ "recurring_application_charges.json?since_id=64512345",
49
+ extension: false,
50
+ method: :get,
51
+ status: 201,
52
+ body: load_fixture('recurring_application_charges')
53
+ )
35
54
 
36
55
  charge = ShopifyAPI::RecurringApplicationCharge.find(:all, params: { since_id: '64512345' })
37
56
 
38
- assert_equal "Super Mega Plan", charge.last.name
57
+ assert_equal("Super Mega Plan", charge.last.name)
39
58
  end
40
59
 
41
60
  def test_list_fields_recurring_application_charges
42
- fake "recurring_application_charges.json?fields=name",extension: false, method: :get, status: 201, body: load_fixture('recurring_application_charges')
61
+ fake(
62
+ "recurring_application_charges.json?fields=name",
63
+ extension: false,
64
+ method: :get,
65
+ status: 201,
66
+ body: load_fixture('recurring_application_charges')
67
+ )
43
68
 
44
69
  charge = ShopifyAPI::RecurringApplicationCharge.find(:all, params: { fields: 'name' })
45
70
 
46
- assert_equal "Super Mega Plan", charge.last.name
71
+ assert_equal("Super Mega Plan", charge.last.name)
47
72
  end
48
73
 
49
74
  def test_pending_recurring_application_charge
50
- fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
75
+ fake(
76
+ "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
77
+ )
51
78
 
52
79
  charge = ShopifyAPI::RecurringApplicationCharge.pending
53
80
 
54
- assert_equal "Super Mega Plan2", charge.last.name
81
+ assert_equal("Super Mega Plan2", charge.last.name)
55
82
  end
56
83
 
57
84
  def test_cancelled_recurring_application_charge
58
- fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
85
+ fake(
86
+ "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
87
+ )
59
88
 
60
89
  charge = ShopifyAPI::RecurringApplicationCharge.cancelled
61
90
 
62
- assert_equal "Super Mega Plan3", charge.last.name
91
+ assert_equal("Super Mega Plan3", charge.last.name)
63
92
  end
64
93
 
65
94
  def test_accepted_recurring_application_charge
66
- fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
95
+ fake(
96
+ "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
97
+ )
67
98
 
68
99
  charge = ShopifyAPI::RecurringApplicationCharge.accepted
69
100
 
70
- assert_equal "Super Mega Plan4", charge.first.name
71
- assert_equal "Super Mega Plan", charge.last.name
101
+ assert_equal("Super Mega Plan4", charge.first.name)
102
+ assert_equal("Super Mega Plan", charge.last.name)
72
103
  end
73
104
 
74
105
  def test_declined_recurring_application_charge
75
- fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
106
+ fake(
107
+ "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
108
+ )
76
109
 
77
110
  charge = ShopifyAPI::RecurringApplicationCharge.declined
78
111
 
79
- assert_equal "Super Mega Plan5", charge.last.name
112
+ assert_equal("Super Mega Plan5", charge.last.name)
80
113
  end
81
114
 
82
115
  def test_activate_recurring_application_charge
83
- fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
84
- fake "recurring_application_charges/455696199/activate", method: :post, status: 200, body: "{}"
116
+ fake(
117
+ "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
118
+ )
119
+ fake("recurring_application_charges/455696199/activate", method: :post, status: 200, body: "{}")
85
120
 
86
121
  charge = ShopifyAPI::RecurringApplicationCharge.accepted
87
122
 
88
- assert charge.last.activate
123
+ assert(charge.last.activate)
89
124
  end
90
125
 
91
126
  def test_adjust_recurring_application_charge
92
- fake "recurring_application_charges/654381177", method: :get, status: 201, body: load_fixture('recurring_application_charge')
93
- fake "recurring_application_charges/654381177/customize.json?recurring_application_charge%5Bcapped_amount%5D=200", method: :put, body: load_fixture('recurring_application_charge_adjustment'), extension: false
127
+ fake(
128
+ "recurring_application_charges/654381177",
129
+ method: :get,
130
+ status: 201,
131
+ body: load_fixture('recurring_application_charge')
132
+ )
133
+ fake(
134
+ "recurring_application_charges/654381177/customize.json?recurring_application_charge%5Bcapped_amount%5D=200",
135
+ method: :put,
136
+ body: load_fixture('recurring_application_charge_adjustment'),
137
+ extension: false
138
+ )
94
139
 
95
140
  charge = ShopifyAPI::RecurringApplicationCharge.find(654381177)
96
141
 
97
- assert charge.customize(capped_amount: 200)
142
+ assert(charge.customize(capped_amount: 200))
98
143
  end
99
144
 
100
145
  def test_cancel_recurring_application_charge
101
- fake "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
102
- fake "recurring_application_charges/455696194", method: :delete, status: 200, body: "{}"
146
+ fake(
147
+ "recurring_application_charges", method: :get, status: 201, body: load_fixture('recurring_application_charges')
148
+ )
149
+ fake("recurring_application_charges/455696194", method: :delete, status: 200, body: "{}")
103
150
 
104
151
  charge = ShopifyAPI::RecurringApplicationCharge.current
105
- assert charge.cancel
152
+ assert(charge.cancel)
106
153
  end
107
154
 
108
155
  def test_usage_charges_recurring_application_charge_found
109
- fake "recurring_application_charges/654381177", method: :get, status: 201, body: load_fixture('recurring_application_charge')
110
- fake "recurring_application_charges/654381177/usage_charges", method: :get, status: 201, body: load_fixture('usage_charges')
156
+ fake(
157
+ "recurring_application_charges/654381177",
158
+ method: :get,
159
+ status: 201,
160
+ body: load_fixture('recurring_application_charge')
161
+ )
162
+ fake(
163
+ "recurring_application_charges/654381177/usage_charges",
164
+ method: :get,
165
+ status: 201,
166
+ body: load_fixture('usage_charges')
167
+ )
111
168
 
112
169
  charge = ShopifyAPI::RecurringApplicationCharge.find(654381177)
113
170
  usage_charges = charge.usage_charges
114
171
 
115
- assert_equal 2, usage_charges.length
172
+ assert_equal(2, usage_charges.length)
116
173
  end
117
174
 
118
175
  def test_usage_charges_recurring_application_charge_not_found
119
- fake "recurring_application_charges/654381177", method: :get, status: 201, body: load_fixture('recurring_application_charge')
120
- fake "recurring_application_charges/654381177/usage_charges", method: :get, status: 201, body: "[]"
176
+ fake(
177
+ "recurring_application_charges/654381177",
178
+ method: :get,
179
+ status: 201,
180
+ body: load_fixture('recurring_application_charge')
181
+ )
182
+ fake("recurring_application_charges/654381177/usage_charges", method: :get, status: 201, body: "[]")
121
183
 
122
184
  charge = ShopifyAPI::RecurringApplicationCharge.find(654381177)
123
185
  usage_charges = charge.usage_charges
124
186
 
125
- assert_equal 0, usage_charges.length
187
+ assert_equal(0, usage_charges.length)
126
188
  end
127
189
 
128
190
  def test_no_recurring_application_charge_found
129
- fake "recurring_application_charges", body: {recurring_application_charges: []}.to_json
191
+ fake("recurring_application_charges", body: { recurring_application_charges: [] }.to_json)
130
192
 
131
- assert_equal 0, ShopifyAPI::RecurringApplicationCharge.all.count
132
- assert_nil ShopifyAPI::RecurringApplicationCharge.current
133
- assert_equal [], ShopifyAPI::RecurringApplicationCharge.pending
193
+ assert_equal(0, ShopifyAPI::RecurringApplicationCharge.all.count)
194
+ assert_nil(ShopifyAPI::RecurringApplicationCharge.current)
195
+ assert_equal([], ShopifyAPI::RecurringApplicationCharge.pending)
134
196
  end
135
197
 
136
198
  def test_recurring_application_charge_not_found_error
137
- fake "recurring_application_charges", body: '{"errors":"Not Found"}', status: 404
138
- assert_nil ShopifyAPI::RecurringApplicationCharge.all
139
- assert_nil ShopifyAPI::RecurringApplicationCharge.current
199
+ fake("recurring_application_charges", body: '{"errors":"Not Found"}', status: 404)
200
+ assert_nil(ShopifyAPI::RecurringApplicationCharge.all)
201
+ assert_nil(ShopifyAPI::RecurringApplicationCharge.current)
140
202
  assert_equal([], ShopifyAPI::RecurringApplicationCharge.pending)
141
203
  end
142
204
  end