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
data/test/product_test.rb CHANGED
@@ -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
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class RedirectTest < Test::Unit::TestCase
4
5
  test "#create should create a redirect" do
5
- fake "redirects", :method => :post, :status => 201, :body => load_fixture('redirect')
6
- redirect = ShopifyAPI::Redirect.create(:path => "/ipod", :target => "/pages/itunes")
7
- assert_equal 979034150, redirect.id
6
+ fake("redirects", method: :post, status: 201, body: load_fixture('redirect'))
7
+ redirect = ShopifyAPI::Redirect.create(path: "/ipod", target: "/pages/itunes")
8
+ assert_equal(979034150, redirect.id)
8
9
  end
9
10
  end
data/test/refund_test.rb CHANGED
@@ -1,32 +1,37 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class RefundTest < Test::Unit::TestCase
4
-
5
5
  test '#create should create a refund' do
6
- fake "orders/450789469/refunds", :method => :post, :status => 201, :body => load_fixture('refund')
6
+ fake("orders/450789469/refunds", method: :post, status: 201, body: load_fixture('refund'))
7
7
  refund = ShopifyAPI::Refund.create(
8
- :order_id => 450789469,
9
- :restock => true,
10
- :note => "wrong size",
11
- :shipping => { :full_refund => true },
12
- :refund_line_items => [{ :line_item_id => 518995019, :quantity => 1 }]
8
+ order_id: 450789469,
9
+ restock: true,
10
+ note: "wrong size",
11
+ shipping: { full_refund: true },
12
+ refund_line_items: [{ line_item_id: 518995019, quantity: 1 }]
13
13
  )
14
- assert_equal 703073504, refund.refund_line_items.first.line_item_id
14
+ assert_equal(703073504, refund.refund_line_items.first.line_item_id)
15
15
  end
16
16
 
17
17
  test '#find should return a refund' do
18
- fake "orders/450789469/refunds/509562969.json?order_id=450789469", :extension => false, :method => :get, :body => load_fixture('refund')
19
- fake "orders/450789469/refunds/509562969", :method => :get, :body => load_fixture('refund')
20
- refund = ShopifyAPI::Refund.find(509562969, :params => {:order_id => 450789469})
21
- assert_equal 509562969, refund.id
18
+ fake(
19
+ "orders/450789469/refunds/509562969.json?order_id=450789469",
20
+ extension: false,
21
+ method: :get,
22
+ body: load_fixture('refund')
23
+ )
24
+ fake("orders/450789469/refunds/509562969", method: :get, body: load_fixture('refund'))
25
+ refund = ShopifyAPI::Refund.find(509562969, params: { order_id: 450789469 })
26
+ assert_equal(509562969, refund.id)
22
27
  end
23
28
 
24
29
  test '#calculate a refund' do
25
- fake "orders/450789469/refunds/calculate", :method => :post, :body => load_fixture('refund')
26
- data = { :shipping => { :amount => 0 } }
30
+ fake("orders/450789469/refunds/calculate", method: :post, body: load_fixture('refund'))
31
+ data = { shipping: { amount: 0 } }
27
32
 
28
- refund = ShopifyAPI::Refund.calculate(data, :params => {:order_id => 450789469})
29
- assert_equal 2, refund.refund_line_items.count
30
- assert_equal 703073504, refund.refund_line_items.first.line_item_id
33
+ refund = ShopifyAPI::Refund.calculate(data, params: { order_id: 450789469 })
34
+ assert_equal(2, refund.refund_line_items.count)
35
+ assert_equal(703073504, refund.refund_line_items.first.line_item_id)
31
36
  end
32
37
  end
data/test/report_test.rb CHANGED
@@ -1,35 +1,37 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class ReportTest < Test::Unit::TestCase
4
5
  test 'get should get a report' do
5
- fake 'reports/987', method: :get, status: 200, body: load_fixture('report')
6
+ fake('reports/987', method: :get, status: 200, body: load_fixture('report'))
6
7
 
7
8
  report = ShopifyAPI::Report.find(987)
8
- assert_equal 987, report.id
9
+ assert_equal(987, report.id)
9
10
  end
10
11
 
11
12
  test 'get all should get all reports' do
12
- fake 'reports', method: :get, status: 200, body: load_fixture('reports')
13
+ fake('reports', method: :get, status: 200, body: load_fixture('reports'))
13
14
 
14
15
  reports = ShopifyAPI::Report.all
15
- assert_equal 'custom_app_reports', reports.first.category
16
+ assert_equal('custom_app_reports', reports.first.category)
16
17
  end
17
18
 
18
19
  test 'create should create a report' do
19
- fake 'reports', method: :post, status: 201, body: load_fixture('report')
20
+ fake('reports', method: :post, status: 201, body: load_fixture('report'))
20
21
 
21
22
  report = ShopifyAPI::Report.create(
22
23
  name: 'Custom App Report',
23
- shopify_ql: 'SHOW quantity_count, total_sales BY product_type, vendor, product_title FROM products SINCE -1m UNTIL -0m ORDER BY total_sales DESC'
24
+ shopify_ql: 'SHOW quantity_count, total_sales BY product_type, vendor, product_title ' \
25
+ 'FROM products SINCE -1m UNTIL -0m ORDER BY total_sales DESC'
24
26
  )
25
- assert_equal 'custom_app_reports', report.category
27
+ assert_equal('custom_app_reports', report.category)
26
28
  end
27
29
 
28
30
  test 'delete should delete report' do
29
- fake 'reports/987', method: :get, status: 200, body: load_fixture('report')
30
- fake 'reports/987', method: :delete, status: 200, body: '[]'
31
+ fake('reports/987', method: :get, status: 200, body: load_fixture('report'))
32
+ fake('reports/987', method: :delete, status: 200, body: '[]')
31
33
 
32
34
  report = ShopifyAPI::Report.find(987)
33
- assert report.destroy
35
+ assert(report.destroy)
34
36
  end
35
37
  end
@@ -1,41 +1,42 @@
1
+ # frozen_string_literal: true
1
2
  class ResourceFeedbackTest < Test::Unit::TestCase
2
3
  def test_get_resource_feedback
3
- body = { resource_feedback: [ { resource_type: 'Shop' } ] }.to_json
4
- fake 'resource_feedback', method: :get, body: body
4
+ body = { resource_feedback: [{ resource_type: 'Shop' }] }.to_json
5
+ fake('resource_feedback', method: :get, body: body)
5
6
  resource_feedback = ShopifyAPI::ResourceFeedback.find(:all)
6
- assert_equal 'Shop', resource_feedback.first.resource_type
7
+ assert_equal('Shop', resource_feedback.first.resource_type)
7
8
  end
8
9
 
9
10
  def test_save_with_resource_feedback_endpoint
10
11
  body = { resource_feedback: {} }.to_json
11
- fake 'resource_feedback', method: :post, body: body
12
+ fake('resource_feedback', method: :post, body: body)
12
13
  ShopifyAPI::ResourceFeedback.new.save
13
- assert_request_body body
14
+ assert_request_body(body)
14
15
  end
15
16
 
16
17
  def test_get_resource_feedback_with_product_id
17
- body = { resource_feedback: [ { resource_type: 'Product' } ] }.to_json
18
- fake 'products/42/resource_feedback', method: :get, body: body
18
+ body = { resource_feedback: [{ resource_type: 'Product' }] }.to_json
19
+ fake('products/42/resource_feedback', method: :get, body: body)
19
20
  resource_feedback = ShopifyAPI::ResourceFeedback.find(:all, params: { product_id: 42 })
20
- assert_equal 'Product', resource_feedback.first.resource_type
21
+ assert_equal('Product', resource_feedback.first.resource_type)
21
22
  end
22
23
 
23
24
  def test_save_with_product_id_resource_feedback_endpoint
24
25
  body = { resource_feedback: {} }.to_json
25
- fake 'products/42/resource_feedback', method: :post, body: body
26
+ fake('products/42/resource_feedback', method: :post, body: body)
26
27
  ShopifyAPI::ResourceFeedback.new(product_id: 42).save
27
- assert_request_body body
28
+ assert_request_body(body)
28
29
  end
29
30
 
30
31
  def test_save_raises_exception_when_already_persisted
31
32
  body = { resource_feedback: {} }.to_json
32
- fake 'resource_feedback', method: :post, body: body
33
+ fake('resource_feedback', method: :post, body: body)
33
34
  resource_feedback = ShopifyAPI::ResourceFeedback.new
34
35
  resource_feedback.save
35
- assert_request_body body
36
+ assert_request_body(body)
36
37
 
37
38
  ShopifyAPI::ResourceFeedback.any_instance.expects(:persisted?).returns(true)
38
- assert_raises ShopifyAPI::ResourceFeedback::ExistingFeedbackSaved do
39
+ assert_raises(ShopifyAPI::ResourceFeedback::ExistingFeedbackSaved) do
39
40
  resource_feedback.save
40
41
  end
41
42
  end
@@ -1,30 +1,31 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class ScriptTagTest < Test::Unit::TestCase
4
5
  test "get all should get all script tags" do
5
- fake 'script_tags', :method => :get, :status => 200, :body => load_fixture('script_tags')
6
+ fake('script_tags', method: :get, status: 200, body: load_fixture('script_tags'))
6
7
  script_tags = ShopifyAPI::ScriptTag.all
7
- assert_equal "http://js-aplenty.com/bar.js", script_tags.first.src
8
+ assert_equal("http://js-aplenty.com/bar.js", script_tags.first.src)
8
9
  end
9
10
 
10
11
  test "get should get a script tag" do
11
- fake 'script_tags/421379493', :method => :get, :status => 200, :body => load_fixture('script_tag')
12
+ fake('script_tags/421379493', method: :get, status: 200, body: load_fixture('script_tag'))
12
13
  script_tag = ShopifyAPI::ScriptTag.find(421379493)
13
- assert_equal "http://js-aplenty.com/bar.js", script_tag.src
14
+ assert_equal("http://js-aplenty.com/bar.js", script_tag.src)
14
15
  end
15
16
 
16
17
  test "create should create a new script tag" do
17
- fake 'script_tags', :method => :post, :status => 201, :body => load_fixture('script_tag')
18
+ fake('script_tags', method: :post, status: 201, body: load_fixture('script_tag'))
18
19
  script_tag = ShopifyAPI::ScriptTag.create(event: "onload", src: "http://js-aplenty.com/bar.js")
19
- assert_equal "http://js-aplenty.com/bar.js", script_tag.src
20
+ assert_equal("http://js-aplenty.com/bar.js", script_tag.src)
20
21
  end
21
22
 
22
23
  test "editing script tag should update script tag" do
23
- fake 'script_tags/421379493', :method => :get, :status => 200, :body => load_fixture('script_tag')
24
+ fake('script_tags/421379493', method: :get, status: 200, body: load_fixture('script_tag'))
24
25
  script_tag = ShopifyAPI::ScriptTag.find(421379493)
25
26
  script_tag.src = "http://js-aplenty.com/bar.js"
26
- fake 'script_tags/421379493', :method => :put, :status => 200, :body => load_fixture('script_tag')
27
+ fake('script_tags/421379493', method: :put, status: 200, body: load_fixture('script_tag'))
27
28
  script_tag.save
28
- assert_equal "http://js-aplenty.com/bar.js", script_tag.src
29
+ assert_equal("http://js-aplenty.com/bar.js", script_tag.src)
29
30
  end
30
31
  end