shopify_api 9.0.3 → 9.4.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 (197) 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 +36 -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 +41 -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 +4 -2
  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 +12 -9
  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 +15 -11
  113. data/lib/shopify_api/resources/webhook.rb +1 -0
  114. data/lib/shopify_api/session.rb +50 -15
  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 +11 -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 +11 -10
  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/fulfillment_order.json +1 -0
  147. data/test/fixtures/fulfillment_orders.json +2 -0
  148. data/test/fulfillment_event_test.rb +31 -26
  149. data/test/fulfillment_order_test.rb +215 -147
  150. data/test/fulfillment_order_test_helper.rb +1 -0
  151. data/test/fulfillment_request_test.rb +10 -8
  152. data/test/fulfillment_service_test.rb +13 -12
  153. data/test/fulfillment_test.rb +81 -66
  154. data/test/fulfillment_v2_test.rb +16 -12
  155. data/test/gift_card_test.rb +6 -4
  156. data/test/graphql_test.rb +55 -23
  157. data/test/image_test.rb +19 -17
  158. data/test/inventory_level_test.rb +24 -15
  159. data/test/lib/webmock_extensions/last_request.rb +1 -1
  160. data/test/limits_test.rb +2 -1
  161. data/test/location_test.rb +2 -1
  162. data/test/marketing_event_test.rb +20 -20
  163. data/test/message_enricher_test.rb +6 -6
  164. data/test/meta_test.rb +7 -9
  165. data/test/metafield_test.rb +30 -20
  166. data/test/order_risk_test.rb +17 -16
  167. data/test/order_test.rb +43 -28
  168. data/test/pagination_test.rb +89 -56
  169. data/test/policy_test.rb +6 -5
  170. data/test/price_rule_test.rb +20 -15
  171. data/test/product_listing_test.rb +20 -20
  172. data/test/product_publication_test.rb +8 -8
  173. data/test/product_test.rb +44 -32
  174. data/test/publication_test.rb +3 -3
  175. data/test/recurring_application_charge_test.rb +104 -42
  176. data/test/redirect_test.rb +4 -3
  177. data/test/refund_test.rb +22 -17
  178. data/test/report_test.rb +12 -10
  179. data/test/resource_feedback_test.rb +14 -13
  180. data/test/script_tag_test.rb +10 -9
  181. data/test/session_test.rb +297 -43
  182. data/test/shipping_zone_test.rb +4 -3
  183. data/test/shop_test.rb +47 -33
  184. data/test/smart_collection_test.rb +5 -29
  185. data/test/storefront_access_token_test.rb +13 -15
  186. data/test/tax_service_test.rb +7 -4
  187. data/test/tender_transaction_test.rb +3 -3
  188. data/test/test_helper.rb +15 -13
  189. data/test/transaction_test.rb +4 -3
  190. data/test/usage_charge_test.rb +12 -8
  191. data/test/user_test.rb +4 -3
  192. data/test/variant_test.rb +29 -91
  193. data/test/webhook_test.rb +10 -7
  194. metadata +24 -14
  195. data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
  196. data/.travis.yml +0 -23
  197. data/bin/shopify +0 -3
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class ShippingZoneTest < Test::Unit::TestCase
4
5
  test "get all should get all shipping zones" do
5
- fake 'shipping_zones', :method => :get, :status => 200, :body => load_fixture('shipping_zones')
6
+ fake('shipping_zones', method: :get, status: 200, body: load_fixture('shipping_zones'))
6
7
  checkout = ShopifyAPI::ShippingZone.all
7
- assert_equal 1, checkout.first.id
8
- assert_equal "Canada", checkout.first.name
8
+ assert_equal(1, checkout.first.id)
9
+ assert_equal("Canada", checkout.first.name)
9
10
  end
10
11
  end
data/test/shop_test.rb CHANGED
@@ -1,68 +1,82 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class ShopTest < Test::Unit::TestCase
4
5
  def setup
5
6
  super
6
- fake "shop"
7
+ fake("shop")
7
8
  @shop = ShopifyAPI::Shop.current
8
9
  end
9
10
 
10
11
  def test_current_should_return_current_shop
11
- assert @shop.is_a?(ShopifyAPI::Shop)
12
- assert_equal "Apple Computers", @shop.name
13
- assert_equal "apple.myshopify.com", @shop.myshopify_domain
14
- assert_equal 690933842, @shop.id
15
- assert_equal "2007-12-31T19:00:00-05:00", @shop.created_at
16
- assert_nil @shop.tax_shipping
12
+ assert(@shop.is_a?(ShopifyAPI::Shop))
13
+ assert_equal("Apple Computers", @shop.name)
14
+ assert_equal("apple.myshopify.com", @shop.myshopify_domain)
15
+ assert_equal(690933842, @shop.id)
16
+ assert_equal("2007-12-31T19:00:00-05:00", @shop.created_at)
17
+ assert_nil(@shop.tax_shipping)
17
18
  end
18
19
 
19
20
  def test_current_with_options_should_return_current_shop
20
- fake "shop.json?fields%5B%5D=name&fields%5B%5D=myshopify_domain", :extension => false, :method => :get, :status => 201, :body => load_fixture('shop')
21
-
22
- @shop = ShopifyAPI::Shop.current(params: { fields: [:name, :myshopify_domain]})
23
- assert @shop.is_a?(ShopifyAPI::Shop)
24
- assert_equal "Apple Computers", @shop.name
25
- assert_equal "apple.myshopify.com", @shop.myshopify_domain
21
+ fake(
22
+ "shop.json?fields%5B%5D=name&fields%5B%5D=myshopify_domain",
23
+ extension: false,
24
+ method: :get,
25
+ status: 201,
26
+ body: load_fixture('shop')
27
+ )
28
+
29
+ @shop = ShopifyAPI::Shop.current(params: { fields: [:name, :myshopify_domain] })
30
+ assert(@shop.is_a?(ShopifyAPI::Shop))
31
+ assert_equal("Apple Computers", @shop.name)
32
+ assert_equal("apple.myshopify.com", @shop.myshopify_domain)
26
33
  end
27
34
 
28
35
  def test_get_all_metafields_for_shop
29
- fake "metafields"
36
+ fake("metafields")
30
37
 
31
38
  metafields = @shop.metafields
32
39
 
33
- assert_equal 3, metafields.length
34
- assert metafields.all?{|m| m.is_a?(ShopifyAPI::Metafield)}
40
+ assert_equal(3, metafields.length)
41
+ assert(metafields.all? { |m| m.is_a?(ShopifyAPI::Metafield) })
35
42
  end
36
43
 
37
44
  def test_get_2_metafields_for_shop
38
- body = ActiveSupport::JSON.decode load_fixture 'metafields'
39
- body['metafields'].slice! 2, 1
45
+ body = ActiveSupport::JSON.decode(load_fixture('metafields'))
46
+ body['metafields'].slice!(2, 1)
40
47
 
41
- fake 'metafields.json?limit=2', body: body.to_json, extension: false
48
+ fake('metafields.json?limit=2', body: body.to_json, extension: false)
42
49
 
43
- metafields = @shop.metafields limit: 2
50
+ metafields = @shop.metafields(limit: 2)
44
51
 
45
- assert_equal 2, metafields.length
46
- assert metafields.all?{ |m| m.is_a? ShopifyAPI::Metafield }
52
+ assert_equal(2, metafields.length)
53
+ assert(metafields.all? { |m| m.is_a?(ShopifyAPI::Metafield) })
47
54
  end
48
55
 
49
56
  def test_add_metafield
50
- fake "metafields", :method => :post, :status => 201, :body =>load_fixture('metafield')
51
-
52
- field = @shop.add_metafield(ShopifyAPI::Metafield.new(:namespace => "contact", :key => "email", :value => "123@example.com", :value_type => "string"))
53
- assert_equal ActiveSupport::JSON.decode('{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'), ActiveSupport::JSON.decode(WebMock.last_request.body)
54
- assert !field.new_record?
55
- assert_equal "contact", field.namespace
56
- assert_equal "email", field.key
57
- assert_equal "123@example.com", field.value
57
+ fake("metafields", method: :post, status: 201, body: load_fixture('metafield'))
58
+
59
+ field = @shop.add_metafield(
60
+ ShopifyAPI::Metafield.new(namespace: "contact", key: "email", value: "123@example.com", value_type: "string")
61
+ )
62
+ assert_equal(
63
+ ActiveSupport::JSON.decode(
64
+ '{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'
65
+ ),
66
+ ActiveSupport::JSON.decode(WebMock.last_request.body)
67
+ )
68
+ assert(!field.new_record?)
69
+ assert_equal("contact", field.namespace)
70
+ assert_equal("email", field.key)
71
+ assert_equal("123@example.com", field.value)
58
72
  end
59
73
 
60
74
  def test_events
61
- fake "events"
75
+ fake("events")
62
76
 
63
77
  events = @shop.events
64
78
 
65
- assert_equal 3, events.length
66
- assert events.all?{|m| m.is_a?(ShopifyAPI::Event)}
79
+ assert_equal(3, events.length)
80
+ assert(events.all? { |m| m.is_a?(ShopifyAPI::Event) })
67
81
  end
68
82
  end
@@ -1,35 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class SmartCollectionTest < Test::Unit::TestCase
4
5
  test "Smart Collection creation" do
5
- fake "smart_collections", :method => :post, :status => 201, :body => load_fixture('smart_collection')
6
- rules = { :column => "title", :relation => "starts_with", :condition => "mac" }
7
- smart_collection = ShopifyAPI::SmartCollection.create(:title => "Macbooks", :rules => rules)
8
- assert_equal 1063001432, smart_collection.id
9
- end
10
-
11
- test "Smart Collection get products gets all products in a smart collection" do
12
- fake "smart_collections/1063001432", method: :get, status: 200, body: load_fixture('smart_collection')
13
- smart_collection = ShopifyAPI::SmartCollection.find(1063001432)
14
-
15
- fake "products.json?collection_id=1063001432",
16
- method: :get,
17
- status: 200,
18
- body:
19
- load_fixture('smart_collection_products'),
20
- extension: false
21
- assert_equal [632910392, 921728736], smart_collection.products.map(&:id)
22
- end
23
-
24
- test "Smart Collection get products with only_sorted=only_manual gets only manually sorted products" do
25
- fake "smart_collections/1063001432", method: :get, status: 200, body: load_fixture('smart_collection')
26
- smart_collection = ShopifyAPI::SmartCollection.find(1063001432)
27
-
28
- fake "smart_collections/1063001432/products.json?only_sorted=only_manual",
29
- method: :get,
30
- status: 200,
31
- body: load_fixture('smart_collection_products'),
32
- extension: false
33
- assert_equal [632910392, 921728736], smart_collection.products(only_sorted: "only_manual").map(&:id)
6
+ fake("smart_collections", method: :post, status: 201, body: load_fixture('smart_collection'))
7
+ rules = { column: "title", relation: "starts_with", condition: "mac" }
8
+ smart_collection = ShopifyAPI::SmartCollection.create(title: "Macbooks", rules: rules)
9
+ assert_equal(1063001432, smart_collection.id)
34
10
  end
35
11
  end
@@ -1,32 +1,30 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class StorefrontAccessTokenTest < Test::Unit::TestCase
4
-
5
5
  def test_create_storefront_access_token
6
- fake "storefront_access_tokens", :method => :post, :body => load_fixture('storefront_access_token')
6
+ fake("storefront_access_tokens", method: :post, body: load_fixture('storefront_access_token'))
7
7
  storefront_access_token = ShopifyAPI::StorefrontAccessToken.create(title: 'Test')
8
- assert_equal 1, storefront_access_token.id
9
- assert_equal "Test", storefront_access_token.title
8
+ assert_equal(1, storefront_access_token.id)
9
+ assert_equal("Test", storefront_access_token.title)
10
10
  end
11
11
 
12
12
  def test_delete_storefront_access_token
13
- fake 'storefront_access_tokens/1', method: :get, status: 200, body: load_fixture('storefront_access_token')
14
- fake 'storefront_access_tokens/1', method: :delete, status: 200, body: 'destroyed'
15
-
13
+ fake('storefront_access_tokens/1', method: :get, status: 200, body: load_fixture('storefront_access_token'))
14
+ fake('storefront_access_tokens/1', method: :delete, status: 200, body: 'destroyed')
16
15
  storefront_access_tokens = ShopifyAPI::StorefrontAccessToken.find(1)
17
- assert storefront_access_tokens.destroy
16
+ assert(storefront_access_tokens.destroy)
18
17
  end
19
18
 
20
19
  def test_get_storefront_access_tokens
21
- fake "storefront_access_tokens", method: :get, status: 201, body: load_fixture('storefront_access_tokens')
20
+ fake("storefront_access_tokens", method: :get, status: 201, body: load_fixture('storefront_access_tokens'))
22
21
 
23
22
  tokens = ShopifyAPI::StorefrontAccessToken.all
24
23
 
25
- assert_equal 2, tokens.size
26
- assert_equal 1, tokens.first.id
27
- assert_equal 2, tokens.last.id
28
- assert_equal 'Test 1', tokens.first.title
29
- assert_equal 'Test 2', tokens.last.title
24
+ assert_equal(2, tokens.size)
25
+ assert_equal(1, tokens.first.id)
26
+ assert_equal(2, tokens.last.id)
27
+ assert_equal('Test 1', tokens.first.title)
28
+ assert_equal('Test 2', tokens.last.title)
30
29
  end
31
-
32
30
  end
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
  class TaxServiceTest < Test::Unit::TestCase
3
4
  test "tax service creation" do
4
- fake "tax_services", :method => :post, :status => 202, :body => load_fixture('tax_service')
5
- tax_service = ShopifyAPI::TaxService.create(:name => "My Tax Service", :url => "https://mytaxservice.com")
6
- assert_equal '{"tax_service":{"name":"My Tax Service","url":"https://mytaxservice.com"}}', WebMock.last_request.body
7
-
5
+ fake("tax_services", method: :post, status: 202, body: load_fixture('tax_service'))
6
+ ShopifyAPI::TaxService.create(name: "My Tax Service", url: "https://mytaxservice.com")
7
+ assert_equal(
8
+ '{"tax_service":{"name":"My Tax Service","url":"https://mytaxservice.com"}}',
9
+ WebMock.last_request.body
10
+ )
8
11
  end
9
12
  end
@@ -5,14 +5,14 @@ require 'test_helper'
5
5
  class TenderTransactionTest < Test::Unit::TestCase
6
6
  def setup
7
7
  super
8
- fake "tender_transactions", method: :get, body: load_fixture('tender_transactions')
8
+ fake("tender_transactions", method: :get, body: load_fixture('tender_transactions'))
9
9
  end
10
10
 
11
11
  context "Tender Transaction" do
12
12
  should 'return a list of transactions' do
13
13
  tender_transactions = ShopifyAPI::TenderTransaction.all
14
- assert_equal 3, tender_transactions.length
15
- assert_equal [1, 2, 3], tender_transactions.map(&:id)
14
+ assert_equal(3, tender_transactions.length)
15
+ assert_equal([1, 2, 3], tender_transactions.map(&:id))
16
16
  end
17
17
  end
18
18
  end
data/test/test_helper.rb CHANGED
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  require 'rubygems'
2
3
  require 'minitest/autorun'
3
4
  require 'webmock/minitest'
4
5
  require_relative 'lib/webmock_extensions/last_request'
5
- require 'mocha/setup'
6
+ require 'mocha/minitest'
6
7
  require 'pry'
7
8
 
8
9
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -23,7 +24,7 @@ module Test
23
24
  self.test("should_#{string}", &block)
24
25
  end
25
26
 
26
- def self.context(string)
27
+ def self.context(_string)
27
28
  yield
28
29
  end
29
30
 
@@ -34,6 +35,7 @@ module Test
34
35
  const = mod.const_get(const)
35
36
  const.format = :json if const.respond_to?(:format=)
36
37
  rescue NameError
38
+ # Do nothing
37
39
  end
38
40
  end
39
41
 
@@ -68,7 +70,7 @@ module Test
68
70
 
69
71
  # Custom Assertions
70
72
  def assert_not(expression)
71
- refute expression, "Expected <#{expression}> to be false!"
73
+ refute(expression, "Expected <#{expression}> to be false!")
72
74
  end
73
75
 
74
76
  def assert_nothing_raised
@@ -76,30 +78,30 @@ module Test
76
78
  end
77
79
 
78
80
  def assert_not_includes(array, value)
79
- refute array.include?(value)
81
+ refute(array.include?(value))
80
82
  end
81
83
 
82
84
  def assert_includes(array, value)
83
- assert array.include?(value)
85
+ assert(array.include?(value))
84
86
  end
85
87
 
86
- def load_fixture(name, format=:json)
88
+ def load_fixture(name, format = :json)
87
89
  File.read(File.dirname(__FILE__) + "/fixtures/#{name}.#{format}")
88
90
  end
89
91
 
90
92
  def assert_request_body(expected)
91
- assert_equal expected, WebMock.last_request.body
93
+ assert_equal(expected, WebMock.last_request.body)
92
94
  end
93
95
 
94
- def fake(endpoint, options={})
95
- request_body = options.has_key?(:request_body) ? options.delete(:request_body) : nil
96
- body = options.has_key?(:body) ? options.delete(:body) : load_fixture(endpoint)
96
+ def fake(endpoint, options = {})
97
+ request_body = options.key?(:request_body) ? options.delete(:request_body) : nil
98
+ body = options.key?(:body) ? options.delete(:body) : load_fixture(endpoint)
97
99
  format = options.delete(:format) || :json
98
100
  method = options.delete(:method) || :get
99
- api_version = options.delete(:api_version) || ShopifyAPI::Base.api_version
100
- extension = ".#{options.delete(:extension)||'json'}" unless options[:extension]==false
101
+ api_version = options.delete(:api_version) || ShopifyAPI::ApiVersion.find_version('2019-01')
102
+ extension = ".#{options.delete(:extension) || 'json'}" unless options[:extension] == false
101
103
  status = options.delete(:status) || 200
102
- url = if options.has_key?(:url)
104
+ url = if options.key?(:url)
103
105
  options[:url]
104
106
  else
105
107
  "https://this-is-my-test-shop.myshopify.com#{api_version.construct_api_path("#{endpoint}#{extension}")}"
@@ -1,16 +1,17 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class TransactionTest < Test::Unit::TestCase
4
5
  def setup
5
6
  super
6
- fake "orders/450789469/transactions/389404469", :method => :get, :body => load_fixture('transaction')
7
+ fake("orders/450789469/transactions/389404469", method: :get, body: load_fixture('transaction'))
7
8
  end
8
9
 
9
10
  context "Transaction" do
10
11
  context "#find" do
11
12
  should "find a specific transaction" do
12
- transaction = ShopifyAPI::Transaction.find(389404469, :params => {:order_id => 450789469})
13
- assert_equal "409.94", transaction.amount
13
+ transaction = ShopifyAPI::Transaction.find(389404469, params: { order_id: 450789469 })
14
+ assert_equal("409.94", transaction.amount)
14
15
  end
15
16
  end
16
17
  end
@@ -1,21 +1,25 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class UsageChargeTest < Test::Unit::TestCase
4
-
5
5
  def test_create_usage_charges
6
- fake "recurring_application_charges/654381177/usage_charges", method: :post, body: load_fixture('usage_charge')
6
+ fake("recurring_application_charges/654381177/usage_charges", method: :post, body: load_fixture('usage_charge'))
7
7
 
8
8
  usage_charge = ShopifyAPI::UsageCharge.new(description: '1000 emails', price: 1.0)
9
- usage_charge.prefix_options = {recurring_application_charge_id: 654381177}
10
- assert usage_charge.save
9
+ usage_charge.prefix_options = { recurring_application_charge_id: 654381177 }
10
+ assert(usage_charge.save)
11
11
  end
12
12
 
13
13
  def test_get_usage_charges
14
- fake "recurring_application_charges/654381177/usage_charges/359376002", method: :get, status: 201, body: load_fixture('usage_charge')
14
+ fake(
15
+ "recurring_application_charges/654381177/usage_charges/359376002",
16
+ method: :get,
17
+ status: 201,
18
+ body: load_fixture('usage_charge')
19
+ )
15
20
 
16
- usage_charge = ShopifyAPI::UsageCharge.find(359376002, params: {recurring_application_charge_id: 654381177})
21
+ usage_charge = ShopifyAPI::UsageCharge.find(359376002, params: { recurring_application_charge_id: 654381177 })
17
22
 
18
- assert_equal "1000 emails", usage_charge.description
23
+ assert_equal("1000 emails", usage_charge.description)
19
24
  end
20
-
21
25
  end
data/test/user_test.rb CHANGED
@@ -1,16 +1,17 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class UserTest < Test::Unit::TestCase
4
5
  test 'get should get a user' do
5
6
  fake 'users/799407056', method: :get, status: 200, body: load_fixture('user')
6
-
7
+
7
8
  user = ShopifyAPI::User.find(799407056)
8
9
  assert_equal 799407056, user.id
9
10
  end
10
-
11
+
11
12
  test 'get should get all users' do
12
13
  fake 'users', method: :get, status: 200, body: load_fixture('users')
13
-
14
+
14
15
  users = ShopifyAPI::User.all
15
16
  assert_equal 799407056, users.first.id
16
17
  end
data/test/variant_test.rb CHANGED
@@ -1,135 +1,73 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class VariantTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+ refresh_variant
8
+ end
4
9
 
5
10
  def test_get_variants
6
- fake "products/632910392/variants", :method => :get, :body => load_fixture('variants')
11
+ fake("products/632910392/variants", method: :get, body: load_fixture('variants'))
7
12
 
8
- variants = ShopifyAPI::Variant.find(:all, :params => { :product_id => 632910392 })
9
- assert_equal variants.map(&:id).sort, [39072856, 49148385, 457924702, 808950810]
13
+ variants = ShopifyAPI::Variant.find(:all, params: { product_id: 632910392 })
14
+ assert_equal(variants.map(&:id).sort, [39072856, 49148385, 457924702, 808950810])
10
15
  end
11
16
 
12
17
  def test_get_variant_namespaced
13
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
14
-
15
- v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
16
- assert_equal 632910392, v.product_id
18
+ assert_equal(632910392, @variant.product_id)
17
19
  end
18
20
 
19
21
  def test_get_variant
20
- fake "variants/808950810", :method => :get, :body => load_fixture('variant')
21
-
22
- v = ShopifyAPI::Variant.find(808950810)
23
- assert_equal 632910392, v.product_id
22
+ assert_equal(632910392, @variant.product_id)
24
23
  end
25
24
 
26
25
  def test_product_id_should_be_accessible_if_via_product_endpoint
27
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
28
-
29
- v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
30
- assert_equal 632910392, v.product_id
26
+ assert_equal(632910392, @variant.product_id)
31
27
  end
32
28
 
33
29
  def test_product_id_should_be_accessible_if_via_variant_endpoint
34
- fake "variants/808950810", :method => :get, :body => load_fixture('variant')
35
-
36
- v = ShopifyAPI::Variant.find(808950810)
37
- assert_equal 632910392, v.product_id
30
+ assert_equal(632910392, @variant.product_id)
38
31
  end
39
32
 
40
33
  def test_delete_variant
41
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
42
- fake "products/632910392/variants/808950810", :method => :delete, :body => 'destroyed'
43
- v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
44
- assert v.destroy
45
- end
46
-
47
- def test_deprecated_inventory_fields_are_included_in_2019_07
48
- ShopifyAPI::Base.api_version = '2019-07'
49
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
50
- variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
51
- assert variant.as_json.include?('inventory_quantity')
34
+ fake("products/632910392/variants/808950810", method: :delete, body: 'destroyed')
35
+ assert(@variant.destroy)
52
36
  end
53
37
 
54
- def test_deprecated_inventory_fields_are_removed_in_2020_01
38
+ def test_read_only_inventory_quantity
55
39
  ShopifyAPI::Base.api_version = '2020-01'
56
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
57
- variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
58
- refute variant.as_json.include?('inventory_quantity')
59
- end
60
-
61
- def test_setting_variant_inventory_quantity_adjustment_passes_in_api_before_2019_10
62
- ShopifyAPI::Base.api_version = '2019-07'
63
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
64
- variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
65
- variant.inventory_quantity_adjustment = 8
66
- end
67
-
68
- def test_setting_variant_inventory_quantity_adjustment_fails_in_2019_10_api
69
- ShopifyAPI::Base.api_version = '2019-10'
70
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
71
- variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
72
- assert_raises(ShopifyAPI::ValidationException) do
73
- variant.inventory_quantity_adjustment = 8
74
- end
40
+ refresh_variant(api_version: ShopifyAPI::Base.api_version)
41
+ assert_equal(10, @variant.inventory_quantity)
75
42
  end
76
43
 
77
44
  def test_setting_variant_inventory_quantity_adjustment_fails_in_the_unstable_api
78
45
  ShopifyAPI::Base.api_version = :unstable
79
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
80
- variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
81
- assert_raises(ShopifyAPI::ValidationException) do
82
- variant.inventory_quantity_adjustment = 8
83
- end
84
- end
85
-
86
- def test_setting_variant_inventory_quantity_passes_in_api_before_2019_10
87
- ShopifyAPI::Base.api_version = '2019-07'
88
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
89
- variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
90
- variant.inventory_quantity = 8
91
- end
92
-
93
- def test_setting_variant_inventory_quantity_fails_in_2019_10_api
94
- ShopifyAPI::Base.api_version = '2019-10'
95
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
96
- variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
97
46
  assert_raises(ShopifyAPI::ValidationException) do
98
- variant.inventory_quantity = 8
47
+ @variant.inventory_quantity_adjustment = 8
99
48
  end
100
49
  end
101
50
 
102
51
  def test_setting_variant_inventory_quantity_fails_in_the_unstable_api
103
52
  ShopifyAPI::Base.api_version = :unstable
104
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
105
- variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
106
- assert_raises(ShopifyAPI::ValidationException) do
107
- variant.inventory_quantity = 8
108
- end
109
- end
110
-
111
- def test_setting_variant_old_inventory_quantity_passes_in_api_before_2019_10
112
- ShopifyAPI::Base.api_version = '2019-07'
113
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
114
- variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
115
- variant.old_inventory_quantity = 8
116
- end
117
-
118
- def test_setting_variant_old_inventory_quantity_fails_in_2019_10_api
119
- ShopifyAPI::Base.api_version = '2019-10'
120
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
121
- variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
122
53
  assert_raises(ShopifyAPI::ValidationException) do
123
- variant.old_inventory_quantity = 8
54
+ @variant.inventory_quantity = 8
124
55
  end
125
56
  end
126
57
 
127
58
  def test_setting_variant_old_inventory_quantity_fails_in_the_unstable_api
128
59
  ShopifyAPI::Base.api_version = :unstable
129
- fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
130
- variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
131
60
  assert_raises(ShopifyAPI::ValidationException) do
132
- variant.old_inventory_quantity = 8
61
+ @variant.old_inventory_quantity = 8
133
62
  end
134
63
  end
64
+
65
+ private
66
+
67
+ def refresh_variant(api_version: nil)
68
+ fake(
69
+ "products/632910392/variants/808950810", method: :get, body: load_fixture('variant'), api_version: api_version
70
+ )
71
+ @variant = ShopifyAPI::Variant.find(808950810, params: { product_id: 632910392 })
72
+ end
135
73
  end