ruby_shopify_api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (351) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.github/CODEOWNERS +1 -0
  4. data/.github/ISSUE_TEMPLATE.md +36 -0
  5. data/.github/probots.yml +2 -0
  6. data/.github/workflows/build.yml +43 -0
  7. data/.gitignore +15 -0
  8. data/.rubocop.yml +28 -0
  9. data/.rubocop_todo.yml +75 -0
  10. data/CHANGELOG-OLD.md +501 -0
  11. data/CHANGELOG.md +5 -0
  12. data/CONTRIBUTING.md +8 -0
  13. data/CONTRIBUTORS +3 -0
  14. data/Gemfile +10 -0
  15. data/Gemfile.lock +151 -0
  16. data/Gemfile_ar41 +5 -0
  17. data/Gemfile_ar50 +5 -0
  18. data/Gemfile_ar51 +5 -0
  19. data/Gemfile_ar60 +5 -0
  20. data/Gemfile_ar_main +5 -0
  21. data/LICENSE +20 -0
  22. data/README.md +649 -0
  23. data/RELEASING +17 -0
  24. data/Rakefile +55 -0
  25. data/SECURITY.md +59 -0
  26. data/dev.yml +11 -0
  27. data/docker-compose.yml +13 -0
  28. data/docs/_config.yml +1 -0
  29. data/docs/_includes/footer.html +28 -0
  30. data/docs/_includes/head.html +28 -0
  31. data/docs/_layouts/index.html +57 -0
  32. data/docs/graphql.md +241 -0
  33. data/docs/index.md +639 -0
  34. data/lib/active_resource/connection_ext.rb +11 -0
  35. data/lib/active_resource/detailed_log_subscriber.rb +55 -0
  36. data/lib/active_resource/json_errors.rb +37 -0
  37. data/lib/shopify_api/api_access.rb +57 -0
  38. data/lib/shopify_api/api_version.rb +206 -0
  39. data/lib/shopify_api/connection.rb +36 -0
  40. data/lib/shopify_api/countable.rb +15 -0
  41. data/lib/shopify_api/disable_prefix_check.rb +31 -0
  42. data/lib/shopify_api/events.rb +8 -0
  43. data/lib/shopify_api/graphql/http_client.rb +22 -0
  44. data/lib/shopify_api/graphql/railtie.rb +17 -0
  45. data/lib/shopify_api/graphql/task.rake +100 -0
  46. data/lib/shopify_api/graphql.rb +103 -0
  47. data/lib/shopify_api/hmac_params.rb +33 -0
  48. data/lib/shopify_api/limits.rb +77 -0
  49. data/lib/shopify_api/message_enricher.rb +25 -0
  50. data/lib/shopify_api/meta.rb +14 -0
  51. data/lib/shopify_api/metafields.rb +21 -0
  52. data/lib/shopify_api/paginated_collection.rb +69 -0
  53. data/lib/shopify_api/pagination_link_headers.rb +34 -0
  54. data/lib/shopify_api/resources/abandoned_checkout.rb +7 -0
  55. data/lib/shopify_api/resources/access_scope.rb +10 -0
  56. data/lib/shopify_api/resources/access_token.rb +9 -0
  57. data/lib/shopify_api/resources/address.rb +5 -0
  58. data/lib/shopify_api/resources/announcement.rb +5 -0
  59. data/lib/shopify_api/resources/api_permission.rb +9 -0
  60. data/lib/shopify_api/resources/application_charge.rb +16 -0
  61. data/lib/shopify_api/resources/application_credit.rb +5 -0
  62. data/lib/shopify_api/resources/array_base.rb +13 -0
  63. data/lib/shopify_api/resources/article.rb +22 -0
  64. data/lib/shopify_api/resources/asset.rb +101 -0
  65. data/lib/shopify_api/resources/assigned_fulfillment_order.rb +16 -0
  66. data/lib/shopify_api/resources/base.rb +166 -0
  67. data/lib/shopify_api/resources/billing_address.rb +5 -0
  68. data/lib/shopify_api/resources/blog.rb +11 -0
  69. data/lib/shopify_api/resources/carrier_service.rb +5 -0
  70. data/lib/shopify_api/resources/cart.rb +5 -0
  71. data/lib/shopify_api/resources/checkout.rb +30 -0
  72. data/lib/shopify_api/resources/collect.rb +7 -0
  73. data/lib/shopify_api/resources/collection.rb +14 -0
  74. data/lib/shopify_api/resources/collection_listing.rb +19 -0
  75. data/lib/shopify_api/resources/collection_publication.rb +10 -0
  76. data/lib/shopify_api/resources/comment.rb +24 -0
  77. data/lib/shopify_api/resources/country.rb +5 -0
  78. data/lib/shopify_api/resources/currency.rb +6 -0
  79. data/lib/shopify_api/resources/custom_collection.rb +20 -0
  80. data/lib/shopify_api/resources/customer.rb +30 -0
  81. data/lib/shopify_api/resources/customer_group.rb +6 -0
  82. data/lib/shopify_api/resources/customer_invite.rb +5 -0
  83. data/lib/shopify_api/resources/customer_saved_search.rb +12 -0
  84. data/lib/shopify_api/resources/discount_code.rb +10 -0
  85. data/lib/shopify_api/resources/discount_code_batch.rb +34 -0
  86. data/lib/shopify_api/resources/draft_order.rb +15 -0
  87. data/lib/shopify_api/resources/draft_order_invoice.rb +5 -0
  88. data/lib/shopify_api/resources/event.rb +9 -0
  89. data/lib/shopify_api/resources/fulfillment.rb +56 -0
  90. data/lib/shopify_api/resources/fulfillment_event.rb +16 -0
  91. data/lib/shopify_api/resources/fulfillment_order.rb +151 -0
  92. data/lib/shopify_api/resources/fulfillment_order_locations_for_move.rb +5 -0
  93. data/lib/shopify_api/resources/fulfillment_request.rb +16 -0
  94. data/lib/shopify_api/resources/fulfillment_service.rb +5 -0
  95. data/lib/shopify_api/resources/fulfillment_v2.rb +21 -0
  96. data/lib/shopify_api/resources/gift_card.rb +8 -0
  97. data/lib/shopify_api/resources/image.rb +17 -0
  98. data/lib/shopify_api/resources/inventory_item.rb +6 -0
  99. data/lib/shopify_api/resources/inventory_level.rb +54 -0
  100. data/lib/shopify_api/resources/line_item.rb +15 -0
  101. data/lib/shopify_api/resources/location.rb +8 -0
  102. data/lib/shopify_api/resources/marketing_event.rb +11 -0
  103. data/lib/shopify_api/resources/metafield.rb +14 -0
  104. data/lib/shopify_api/resources/note_attribute.rb +5 -0
  105. data/lib/shopify_api/resources/option.rb +5 -0
  106. data/lib/shopify_api/resources/order.rb +44 -0
  107. data/lib/shopify_api/resources/order_risk.rb +9 -0
  108. data/lib/shopify_api/resources/page.rb +7 -0
  109. data/lib/shopify_api/resources/payment.rb +7 -0
  110. data/lib/shopify_api/resources/payment_details.rb +5 -0
  111. data/lib/shopify_api/resources/ping.rb +3 -0
  112. data/lib/shopify_api/resources/policy.rb +8 -0
  113. data/lib/shopify_api/resources/price_rule.rb +8 -0
  114. data/lib/shopify_api/resources/product.rb +59 -0
  115. data/lib/shopify_api/resources/product_listing.rb +17 -0
  116. data/lib/shopify_api/resources/product_publication.rb +10 -0
  117. data/lib/shopify_api/resources/province.rb +6 -0
  118. data/lib/shopify_api/resources/publication.rb +5 -0
  119. data/lib/shopify_api/resources/receipt.rb +5 -0
  120. data/lib/shopify_api/resources/recurring_application_charge.rb +34 -0
  121. data/lib/shopify_api/resources/redirect.rb +5 -0
  122. data/lib/shopify_api/resources/refund.rb +15 -0
  123. data/lib/shopify_api/resources/report.rb +5 -0
  124. data/lib/shopify_api/resources/resource_feedback.rb +19 -0
  125. data/lib/shopify_api/resources/rule.rb +5 -0
  126. data/lib/shopify_api/resources/script_tag.rb +5 -0
  127. data/lib/shopify_api/resources/shipping_address.rb +5 -0
  128. data/lib/shopify_api/resources/shipping_line.rb +5 -0
  129. data/lib/shopify_api/resources/shipping_rate.rb +7 -0
  130. data/lib/shopify_api/resources/shipping_zone.rb +5 -0
  131. data/lib/shopify_api/resources/shop.rb +26 -0
  132. data/lib/shopify_api/resources/smart_collection.rb +15 -0
  133. data/lib/shopify_api/resources/storefront_access_token.rb +5 -0
  134. data/lib/shopify_api/resources/tax_line.rb +5 -0
  135. data/lib/shopify_api/resources/tax_service.rb +5 -0
  136. data/lib/shopify_api/resources/tender_transaction.rb +6 -0
  137. data/lib/shopify_api/resources/theme.rb +5 -0
  138. data/lib/shopify_api/resources/transaction.rb +6 -0
  139. data/lib/shopify_api/resources/usage_charge.rb +6 -0
  140. data/lib/shopify_api/resources/user.rb +5 -0
  141. data/lib/shopify_api/resources/variant.rb +43 -0
  142. data/lib/shopify_api/resources/webhook.rb +5 -0
  143. data/lib/shopify_api/resources.rb +4 -0
  144. data/lib/shopify_api/session.rb +203 -0
  145. data/lib/shopify_api/version.rb +4 -0
  146. data/lib/shopify_api.rb +45 -0
  147. data/lib/verify_docs.rb +8 -0
  148. data/service.yml +2 -0
  149. data/shipit.rubygems.yml +1 -0
  150. data/shopify_api.gemspec +47 -0
  151. data/test/abandoned_checkouts_test.rb +29 -0
  152. data/test/access_scope_test.rb +23 -0
  153. data/test/access_token_test.rb +20 -0
  154. data/test/active_resource/json_errors_test.rb +19 -0
  155. data/test/api_access_test.rb +153 -0
  156. data/test/api_permission_test.rb +9 -0
  157. data/test/api_version_test.rb +157 -0
  158. data/test/application_charge_test.rb +82 -0
  159. data/test/application_credit_test.rb +36 -0
  160. data/test/article_test.rb +72 -0
  161. data/test/asset_test.rb +26 -0
  162. data/test/assigned_fulfillment_order_test.rb +78 -0
  163. data/test/base_test.rb +213 -0
  164. data/test/blog_test.rb +9 -0
  165. data/test/carrier_service_test.rb +18 -0
  166. data/test/cart_test.rb +14 -0
  167. data/test/checkouts_test.rb +77 -0
  168. data/test/collect_test.rb +10 -0
  169. data/test/collection_listing_test.rb +84 -0
  170. data/test/collection_publication_test.rb +40 -0
  171. data/test/collection_test.rb +50 -0
  172. data/test/countable_test.rb +14 -0
  173. data/test/currency_test.rb +21 -0
  174. data/test/custom_collection_test.rb +10 -0
  175. data/test/customer_saved_search_test.rb +37 -0
  176. data/test/customer_test.rb +58 -0
  177. data/test/detailed_log_subscriber_test.rb +143 -0
  178. data/test/discount_code_batch_test.rb +41 -0
  179. data/test/discount_code_test.rb +59 -0
  180. data/test/draft_order_test.rb +167 -0
  181. data/test/fixtures/abandoned_checkout.json +184 -0
  182. data/test/fixtures/abandoned_checkouts.json +186 -0
  183. data/test/fixtures/access_scopes.json +10 -0
  184. data/test/fixtures/access_token_delegate.json +4 -0
  185. data/test/fixtures/api_versions.json +38 -0
  186. data/test/fixtures/apis.json +42 -0
  187. data/test/fixtures/application_charge.json +16 -0
  188. data/test/fixtures/application_charges.json +57 -0
  189. data/test/fixtures/application_credit.json +12 -0
  190. data/test/fixtures/application_credits.json +24 -0
  191. data/test/fixtures/article.json +15 -0
  192. data/test/fixtures/articles.json +39 -0
  193. data/test/fixtures/asset.json +9 -0
  194. data/test/fixtures/assets.json +136 -0
  195. data/test/fixtures/assigned_fulfillment_orders.json +80 -0
  196. data/test/fixtures/authors.json +1 -0
  197. data/test/fixtures/blog.json +13 -0
  198. data/test/fixtures/blogs.json +13 -0
  199. data/test/fixtures/carrier_service.json +9 -0
  200. data/test/fixtures/carts.json +43 -0
  201. data/test/fixtures/checkout.json +160 -0
  202. data/test/fixtures/checkouts.json +162 -0
  203. data/test/fixtures/collect.json +12 -0
  204. data/test/fixtures/collection.json +17 -0
  205. data/test/fixtures/collection_listing.json +11 -0
  206. data/test/fixtures/collection_listing_product_ids.json +1 -0
  207. data/test/fixtures/collection_listing_product_ids2.json +1 -0
  208. data/test/fixtures/collection_listings.json +13 -0
  209. data/test/fixtures/collection_products.json +47 -0
  210. data/test/fixtures/collection_publication.json +11 -0
  211. data/test/fixtures/collection_publications.json +13 -0
  212. data/test/fixtures/currencies.json +25 -0
  213. data/test/fixtures/custom_collection.json +17 -0
  214. data/test/fixtures/customer_invite.json +9 -0
  215. data/test/fixtures/customer_saved_search.json +9 -0
  216. data/test/fixtures/customer_saved_search_customers.json +60 -0
  217. data/test/fixtures/customers.json +59 -0
  218. data/test/fixtures/customers_account_activation_url.json +3 -0
  219. data/test/fixtures/customers_search.json +60 -0
  220. data/test/fixtures/discount_code.json +10 -0
  221. data/test/fixtures/discount_code_batch.json +14 -0
  222. data/test/fixtures/discount_code_batch_discount_codes.json +21 -0
  223. data/test/fixtures/discount_codes.json +12 -0
  224. data/test/fixtures/draft_order.json +159 -0
  225. data/test/fixtures/draft_order_completed.json +159 -0
  226. data/test/fixtures/draft_order_invoice.json +9 -0
  227. data/test/fixtures/draft_orders.json +161 -0
  228. data/test/fixtures/engagement.json +15 -0
  229. data/test/fixtures/events.json +31 -0
  230. data/test/fixtures/fulfillment.json +49 -0
  231. data/test/fixtures/fulfillment_event.json +12 -0
  232. data/test/fixtures/fulfillment_order.json +39 -0
  233. data/test/fixtures/fulfillment_order_locations_for_move.json +18 -0
  234. data/test/fixtures/fulfillment_orders.json +80 -0
  235. data/test/fixtures/fulfillment_request.json +28 -0
  236. data/test/fixtures/fulfillment_service.json +10 -0
  237. data/test/fixtures/fulfillments.json +53 -0
  238. data/test/fixtures/gift_card.json +20 -0
  239. data/test/fixtures/gift_card_disabled.json +20 -0
  240. data/test/fixtures/graphql/2019-10.json +1083 -0
  241. data/test/fixtures/graphql/dummy_schema.rb +16 -0
  242. data/test/fixtures/graphql/unstable.json +1083 -0
  243. data/test/fixtures/image.json +10 -0
  244. data/test/fixtures/images.json +20 -0
  245. data/test/fixtures/inventory_level.json +7 -0
  246. data/test/fixtures/inventory_levels.json +24 -0
  247. data/test/fixtures/marketing_event.json +28 -0
  248. data/test/fixtures/marketing_events.json +54 -0
  249. data/test/fixtures/metafield.json +12 -0
  250. data/test/fixtures/metafields.json +34 -0
  251. data/test/fixtures/order.json +297 -0
  252. data/test/fixtures/order_risk.json +14 -0
  253. data/test/fixtures/order_risks.json +28 -0
  254. data/test/fixtures/order_with_properties.json +373 -0
  255. data/test/fixtures/orders.json +299 -0
  256. data/test/fixtures/payment.json +7 -0
  257. data/test/fixtures/payments.json +9 -0
  258. data/test/fixtures/ping/conversation.json +1 -0
  259. data/test/fixtures/ping/failed_delivery_confirmation.json +1 -0
  260. data/test/fixtures/ping/message.json +1 -0
  261. data/test/fixtures/ping/successful_delivery_confirmation.json +1 -0
  262. data/test/fixtures/policies.json +8 -0
  263. data/test/fixtures/price_rule.json +27 -0
  264. data/test/fixtures/price_rules.json +28 -0
  265. data/test/fixtures/product.json +116 -0
  266. data/test/fixtures/product_listing.json +86 -0
  267. data/test/fixtures/product_listing_product_ids.json +1 -0
  268. data/test/fixtures/product_listing_product_ids2.json +1 -0
  269. data/test/fixtures/product_listings.json +174 -0
  270. data/test/fixtures/product_publication.json +11 -0
  271. data/test/fixtures/product_publications.json +13 -0
  272. data/test/fixtures/publications.json +9 -0
  273. data/test/fixtures/recurring_application_charge.json +22 -0
  274. data/test/fixtures/recurring_application_charge_adjustment.json +5 -0
  275. data/test/fixtures/recurring_application_charges.json +106 -0
  276. data/test/fixtures/redirect.json +7 -0
  277. data/test/fixtures/refund.json +112 -0
  278. data/test/fixtures/report.json +9 -0
  279. data/test/fixtures/reports.json +11 -0
  280. data/test/fixtures/script_tag.json +10 -0
  281. data/test/fixtures/script_tags.json +18 -0
  282. data/test/fixtures/shipping_rates.json +12 -0
  283. data/test/fixtures/shipping_zones.json +315 -0
  284. data/test/fixtures/shop.json +26 -0
  285. data/test/fixtures/smart_collection.json +21 -0
  286. data/test/fixtures/smart_collection_products.json +155 -0
  287. data/test/fixtures/storefront_access_token.json +9 -0
  288. data/test/fixtures/storefront_access_tokens.json +18 -0
  289. data/test/fixtures/tags.json +1 -0
  290. data/test/fixtures/tax_service.json +9 -0
  291. data/test/fixtures/tender_transactions.json +52 -0
  292. data/test/fixtures/transaction.json +29 -0
  293. data/test/fixtures/usage_charge.json +11 -0
  294. data/test/fixtures/usage_charges.json +23 -0
  295. data/test/fixtures/user.json +21 -0
  296. data/test/fixtures/users.json +42 -0
  297. data/test/fixtures/variant.json +23 -0
  298. data/test/fixtures/variants.json +88 -0
  299. data/test/fixtures/webhook.json +10 -0
  300. data/test/fixtures/webhooks.json +18 -0
  301. data/test/fulfillment_event_test.rb +74 -0
  302. data/test/fulfillment_order_test.rb +530 -0
  303. data/test/fulfillment_order_test_helper.rb +8 -0
  304. data/test/fulfillment_request_test.rb +35 -0
  305. data/test/fulfillment_service_test.rb +18 -0
  306. data/test/fulfillment_test.rb +239 -0
  307. data/test/fulfillment_v2_test.rb +66 -0
  308. data/test/gift_card_test.rb +24 -0
  309. data/test/graphql/http_client_test.rb +26 -0
  310. data/test/graphql_test.rb +190 -0
  311. data/test/hmac_params_test.rb +25 -0
  312. data/test/image_test.rb +41 -0
  313. data/test/inventory_level_test.rb +68 -0
  314. data/test/lib/webmock_extensions/last_request.rb +16 -0
  315. data/test/limits_test.rb +39 -0
  316. data/test/location_test.rb +15 -0
  317. data/test/marketing_event_test.rb +68 -0
  318. data/test/message_enricher_test.rb +45 -0
  319. data/test/meta_test.rb +47 -0
  320. data/test/metafield_test.rb +56 -0
  321. data/test/order_risk_test.rb +47 -0
  322. data/test/order_test.rb +140 -0
  323. data/test/pagination_test.rb +290 -0
  324. data/test/payment_test.rb +19 -0
  325. data/test/policy_test.rb +20 -0
  326. data/test/price_rule_test.rb +70 -0
  327. data/test/product_listing_test.rb +97 -0
  328. data/test/product_publication_test.rb +40 -0
  329. data/test/product_test.rb +111 -0
  330. data/test/publication_test.rb +12 -0
  331. data/test/recurring_application_charge_test.rb +204 -0
  332. data/test/redirect_test.rb +10 -0
  333. data/test/refund_test.rb +37 -0
  334. data/test/report_test.rb +37 -0
  335. data/test/resource_feedback_test.rb +43 -0
  336. data/test/script_tag_test.rb +31 -0
  337. data/test/session_test.rb +640 -0
  338. data/test/shipping_rate_test.rb +17 -0
  339. data/test/shipping_zone_test.rb +11 -0
  340. data/test/shop_test.rb +82 -0
  341. data/test/smart_collection_test.rb +11 -0
  342. data/test/storefront_access_token_test.rb +30 -0
  343. data/test/tax_service_test.rb +12 -0
  344. data/test/tender_transaction_test.rb +18 -0
  345. data/test/test_helper.rb +126 -0
  346. data/test/transaction_test.rb +18 -0
  347. data/test/usage_charge_test.rb +25 -0
  348. data/test/user_test.rb +18 -0
  349. data/test/variant_test.rb +73 -0
  350. data/test/webhook_test.rb +24 -0
  351. metadata +555 -0
@@ -0,0 +1,640 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+ require 'timecop'
4
+
5
+ class SessionTest < Test::Unit::TestCase
6
+ SECONDS_IN_A_DAY = 24 * 60 * 60
7
+
8
+ def setup
9
+ super
10
+ ShopifyAPI::Session.secret = 'secret'
11
+ end
12
+
13
+ test "not be valid without a url" do
14
+ session = ShopifyAPI::Session.new(domain: nil, token: "any-token", api_version: any_api_version)
15
+ assert_not(session.valid?)
16
+ end
17
+
18
+ test "not be valid without token" do
19
+ session = ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: nil, api_version: any_api_version)
20
+ assert_not(session.valid?)
21
+ end
22
+
23
+ test "not be valid without an API version" do
24
+ session = ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: "any-token", api_version: nil)
25
+ assert_not(session.valid?)
26
+
27
+ session = ShopifyAPI::Session.new(
28
+ domain: "testshop.myshopify.com", token: "any-token", api_version: ShopifyAPI::ApiVersion::NullVersion
29
+ )
30
+ assert_not(session.valid?)
31
+ end
32
+
33
+ test "default to base API version" do
34
+ session = ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: "any-token")
35
+ assert(session.valid?)
36
+ assert_equal(session.api_version, ShopifyAPI::Base.api_version)
37
+ end
38
+
39
+ test "can override the base API version" do
40
+ different_api_version = '2020-01'
41
+ session = ShopifyAPI::Session.new(
42
+ domain: "testshop.myshopify.com", token: "any-token", api_version: different_api_version
43
+ )
44
+ assert(session.valid?)
45
+ assert_equal(session.api_version, ShopifyAPI::ApiVersion.find_version(different_api_version))
46
+ end
47
+
48
+ test "be valid with any token, any url and version" do
49
+ session = ShopifyAPI::Session.new(
50
+ domain: "testshop.myshopify.com",
51
+ token: "any-token",
52
+ api_version: any_api_version
53
+ )
54
+ assert(session.valid?)
55
+ end
56
+
57
+ test "be valid with nil access_scopes" do
58
+ session = ShopifyAPI::Session.new(
59
+ domain: "testshop.myshopify.com",
60
+ token: "any-token",
61
+ api_version: any_api_version,
62
+ access_scopes: nil
63
+ )
64
+
65
+ assert(session.valid?)
66
+ end
67
+
68
+ test "be valid with string of access_scopes" do
69
+ session = ShopifyAPI::Session.new(
70
+ domain: "testshop.myshopify.com",
71
+ token: "any-token",
72
+ api_version: any_api_version,
73
+ access_scopes: "read_products, write_orders"
74
+ )
75
+
76
+ assert(session.valid?)
77
+ end
78
+
79
+ test "be valid with a collection of access_scopes" do
80
+ session = ShopifyAPI::Session.new(
81
+ domain: "testshop.myshopify.com",
82
+ token: "any-token",
83
+ api_version: any_api_version,
84
+ access_scopes: %w(read_products write_orders)
85
+ )
86
+
87
+ assert(session.valid?)
88
+ end
89
+
90
+ test "not raise error without params" do
91
+ assert_nothing_raised do
92
+ ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: "any-token", api_version: any_api_version)
93
+ end
94
+ end
95
+
96
+ test "ignore everything but the subdomain in the shop" do
97
+ assert_equal_uri(
98
+ "https://testshop.myshopify.com",
99
+ ShopifyAPI::Session.new(
100
+ domain: "http://user:pass@testshop.notshopify.net/path",
101
+ token: "any-token",
102
+ api_version: any_api_version
103
+ ).site
104
+ )
105
+ end
106
+
107
+ test "append the myshopify domain if not given" do
108
+ assert_equal_uri(
109
+ "https://testshop.myshopify.com",
110
+ ShopifyAPI::Session.new(domain: "testshop", token: "any-token", api_version: any_api_version).site
111
+ )
112
+ end
113
+
114
+ test "not raise error without params" do
115
+ assert_nothing_raised do
116
+ ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: "any-token", api_version: any_api_version)
117
+ end
118
+ end
119
+
120
+ test "provides default nil access_scopes attribute" do
121
+ session = ShopifyAPI::Session.new(
122
+ domain: "testshop.myshopify.com",
123
+ token: "any-token",
124
+ api_version: any_api_version
125
+ )
126
+ assert_nil session.access_scopes
127
+ end
128
+
129
+ test "provides specified nil access_scopes attribute" do
130
+ session = ShopifyAPI::Session.new(
131
+ domain: "testshop.myshopify.com",
132
+ token: "any-token",
133
+ access_scopes: "read_products",
134
+ api_version: any_api_version
135
+ )
136
+ assert_equal "read_products", session.access_scopes.to_s
137
+ end
138
+
139
+ test "session instantiation raises error if bad access scopes are provided" do
140
+ assert_raises NoMethodError do
141
+ ShopifyAPI::Session.new(
142
+ domain: "testshop.myshopify.com",
143
+ token: "any-token",
144
+ access_scopes: { bad_input: "bad_input" },
145
+ api_version: any_api_version
146
+ )
147
+ end
148
+ end
149
+
150
+ test "raise error if params passed but signature omitted" do
151
+ assert_raises(ShopifyAPI::ValidationException) do
152
+ session = ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: nil, api_version: any_api_version)
153
+ session.request_token({ 'code' => 'any-code' })
154
+ end
155
+ end
156
+
157
+ test "setup api_key and secret for all sessions" do
158
+ ShopifyAPI::Session.setup(api_key: "My test key", secret: "My test secret")
159
+ assert_equal("My test key", ShopifyAPI::Session.api_key)
160
+ assert_equal("My test secret", ShopifyAPI::Session.secret)
161
+ end
162
+
163
+ test "#temp reset ShopifyAPI::Base values to original value" do
164
+ session1 = ShopifyAPI::Session.new(domain: 'fakeshop.myshopify.com', token: 'token1', api_version: '2019-01')
165
+ ShopifyAPI::Base.user = 'foo'
166
+ ShopifyAPI::Base.password = 'bar'
167
+ ShopifyAPI::Base.activate_session(session1)
168
+
169
+ ShopifyAPI::Session.temp(domain: "testshop.myshopify.com", token: "any-token", api_version: :unstable) do
170
+ @assigned_site = ShopifyAPI::Base.site
171
+ @assigned_version = ShopifyAPI::Base.api_version
172
+ @assigned_user = ShopifyAPI::Base.user
173
+ @assigned_password = ShopifyAPI::Base.password
174
+ end
175
+
176
+ assert_equal('https://testshop.myshopify.com', @assigned_site.to_s)
177
+ assert_equal('https://fakeshop.myshopify.com', ShopifyAPI::Base.site.to_s)
178
+
179
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: :unstable), @assigned_version)
180
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: '2019-01'), ShopifyAPI::Base.api_version)
181
+
182
+ assert_nil(@assigned_user)
183
+ assert_equal('foo', ShopifyAPI::Base.user)
184
+
185
+ assert_nil(@assigned_password)
186
+ assert_equal('bar', ShopifyAPI::Base.password)
187
+ end
188
+
189
+ test "#temp does not use basic auth values from Base.site" do
190
+ ShopifyAPI::Base.site = 'https://user:pass@fakeshop.myshopify.com'
191
+
192
+ ShopifyAPI::Session.temp(domain: "testshop.myshopify.com", token: "any-token", api_version: :unstable) do
193
+ @assigned_site = ShopifyAPI::Base.site
194
+ @assigned_user = ShopifyAPI::Base.user
195
+ @assigned_password = ShopifyAPI::Base.password
196
+ end
197
+
198
+ assert_equal('https://testshop.myshopify.com', @assigned_site.to_s)
199
+ assert_equal('https://fakeshop.myshopify.com', ShopifyAPI::Base.site.to_s)
200
+
201
+ assert_nil(@assigned_user)
202
+ assert_equal('user', ShopifyAPI::Base.user)
203
+
204
+ assert_nil(@assigned_password)
205
+ assert_equal('pass', ShopifyAPI::Base.password)
206
+ end
207
+
208
+ test "#with_session activates the session for the duration of the block" do
209
+ session1 = ShopifyAPI::Session.new(domain: 'fakeshop.myshopify.com', token: 'token1', api_version: '2019-01')
210
+ ShopifyAPI::Base.activate_session(session1)
211
+
212
+ other_session = ShopifyAPI::Session.new(
213
+ domain: "testshop.myshopify.com",
214
+ token: "any-token",
215
+ api_version: :unstable
216
+ )
217
+
218
+ ShopifyAPI::Session.with_session(other_session) do
219
+ @assigned_site = ShopifyAPI::Base.site
220
+ @assigned_version = ShopifyAPI::Base.api_version
221
+ end
222
+
223
+ assert_equal('https://testshop.myshopify.com', @assigned_site.to_s)
224
+ assert_equal('https://fakeshop.myshopify.com', ShopifyAPI::Base.site.to_s)
225
+
226
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: :unstable), @assigned_version)
227
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: '2019-01'), ShopifyAPI::Base.api_version)
228
+ end
229
+
230
+ test "#with_session resets the activated session even if there an exception during the block" do
231
+ session1 = ShopifyAPI::Session.new(domain: 'fakeshop.myshopify.com', token: 'token1', api_version: '2019-01')
232
+ ShopifyAPI::Base.activate_session(session1)
233
+
234
+ other_session = ShopifyAPI::Session.new(
235
+ domain: "testshop.myshopify.com",
236
+ token: "any-token",
237
+ api_version: :unstable
238
+ )
239
+
240
+ assert_raises(StandardError) do
241
+ ShopifyAPI::Session.with_session(other_session) { raise StandardError, "" }
242
+ end
243
+
244
+ assert_equal('https://fakeshop.myshopify.com', ShopifyAPI::Base.site.to_s)
245
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: '2019-01'), ShopifyAPI::Base.api_version)
246
+ end
247
+
248
+ test "#with_version will adjust the actvated api version for the duration of the block" do
249
+ session1 = ShopifyAPI::Session.new(domain: 'fakeshop.myshopify.com', token: 'token1', api_version: '2019-01')
250
+ ShopifyAPI::Base.activate_session(session1)
251
+
252
+ ShopifyAPI::Session.with_version(:unstable) do
253
+ @assigned_site = ShopifyAPI::Base.site
254
+ @assigned_version = ShopifyAPI::Base.api_version
255
+ end
256
+
257
+ assert_equal('https://fakeshop.myshopify.com', @assigned_site.to_s)
258
+ assert_equal('https://fakeshop.myshopify.com', ShopifyAPI::Base.site.to_s)
259
+
260
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: :unstable), @assigned_version)
261
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: '2019-01'), ShopifyAPI::Base.api_version)
262
+ end
263
+
264
+ test "create_permission_url requires redirect_uri" do
265
+ ShopifyAPI::Session.setup(api_key: "My_test_key", secret: "My test secret")
266
+ session = ShopifyAPI::Session.new(
267
+ domain: 'http://localhost.myshopify.com',
268
+ token: 'any-token',
269
+ api_version: any_api_version
270
+ )
271
+ scope = ["write_products"]
272
+ assert_raises(ArgumentError) do
273
+ session.create_permission_url(scope)
274
+ end
275
+ end
276
+
277
+ test "create_permission_url returns correct url with single scope and redirect uri" do
278
+ ShopifyAPI::Session.setup(api_key: "My_test_key", secret: "My test secret")
279
+ session = ShopifyAPI::Session.new(
280
+ domain: 'http://localhost.myshopify.com',
281
+ token: 'any-token',
282
+ api_version: any_api_version
283
+ )
284
+ scope = ["write_products"]
285
+ permission_url = session.create_permission_url(scope, "http://my_redirect_uri.com")
286
+ assert_equal_uri(
287
+ "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&" \
288
+ "scope=write_products&redirect_uri=http://my_redirect_uri.com",
289
+ permission_url
290
+ )
291
+ end
292
+
293
+ test "create_permission_url returns correct url with dual scope" do
294
+ ShopifyAPI::Session.setup(api_key: "My_test_key", secret: "My test secret")
295
+ session = ShopifyAPI::Session.new(
296
+ domain: 'http://localhost.myshopify.com',
297
+ token: 'any-token',
298
+ api_version: any_api_version
299
+ )
300
+ scope = ["write_products", "write_customers"]
301
+ permission_url = session.create_permission_url(scope, "http://my_redirect_uri.com")
302
+ assert_equal_uri(
303
+ "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&" \
304
+ "scope=write_products,write_customers&redirect_uri=http://my_redirect_uri.com",
305
+ permission_url
306
+ )
307
+ end
308
+
309
+ test "create_permission_url returns correct url with no scope" do
310
+ ShopifyAPI::Session.setup(api_key: "My_test_key", secret: "My test secret")
311
+ session = ShopifyAPI::Session.new(
312
+ domain: 'http://localhost.myshopify.com',
313
+ token: 'any-token',
314
+ api_version: any_api_version
315
+ )
316
+ scope = []
317
+ permission_url = session.create_permission_url(scope, "http://my_redirect_uri.com")
318
+ assert_equal_uri(
319
+ "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&" \
320
+ "scope=&redirect_uri=http://my_redirect_uri.com",
321
+ permission_url
322
+ )
323
+ end
324
+
325
+ test "create_permission_url returns correct url with state" do
326
+ ShopifyAPI::Session.setup(api_key: "My_test_key", secret: "My test secret")
327
+ session = ShopifyAPI::Session.new(
328
+ domain: 'http://localhost.myshopify.com',
329
+ token: 'any-token',
330
+ api_version: any_api_version
331
+ )
332
+ scope = []
333
+ permission_url = session.create_permission_url(scope, "http://my_redirect_uri.com", state: "My nonce")
334
+ assert_equal_uri(
335
+ "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&" \
336
+ "scope=&redirect_uri=http://my_redirect_uri.com&state=My+nonce",
337
+ permission_url
338
+ )
339
+ end
340
+
341
+ test "create_permission_url returns correct url with grant_options[]" do
342
+ ShopifyAPI::Session.setup(api_key: "My_test_key", secret: "My test secret")
343
+ session = ShopifyAPI::Session.new(
344
+ domain: 'http://localhost.myshopify.com',
345
+ token: 'any-token',
346
+ api_version: any_api_version
347
+ )
348
+ scope = []
349
+ permission_url = session.create_permission_url(scope, "http://my_redirect_uri.com", grant_options: "per-user")
350
+ assert_equal_uri(
351
+ "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&" \
352
+ "scope=&redirect_uri=http://my_redirect_uri.com&grant_options[]=per-user",
353
+ permission_url
354
+ )
355
+ end
356
+
357
+ test "raise exception if code invalid in request token" do
358
+ ShopifyAPI::Session.setup(api_key: "My test key", secret: "My test secret")
359
+ session = ShopifyAPI::Session.new(
360
+ domain: 'http://localhost.myshopify.com',
361
+ token: nil,
362
+ api_version: any_api_version
363
+ )
364
+ fake(
365
+ nil,
366
+ url: 'https://localhost.myshopify.com/admin/oauth/access_token',
367
+ method: :post,
368
+ status: 404,
369
+ body: '{"error" : "invalid_request"}'
370
+ )
371
+ assert_raises(ShopifyAPI::ValidationException) do
372
+ session.request_token(code: "bad-code")
373
+ end
374
+ assert_equal(false, session.valid?)
375
+ end
376
+
377
+ test "return site for session" do
378
+ session = ShopifyAPI::Session.new(
379
+ domain: "testshop.myshopify.com",
380
+ token: "any-token",
381
+ api_version: any_api_version
382
+ )
383
+ assert_equal_uri("https://testshop.myshopify.com", session.site)
384
+ end
385
+
386
+ test "return_token_if_signature_is_valid" do
387
+ api_version = any_api_version
388
+ fake(
389
+ nil,
390
+ url: "https://testshop.myshopify.com/admin/oauth/access_token",
391
+ method: :post,
392
+ body: '{"access_token":"any-token"}'
393
+ )
394
+ session = ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: nil, api_version: api_version)
395
+
396
+ params = { code: 'any-code', timestamp: Time.now }
397
+ token = session.request_token(params.merge(hmac: generate_signature(params)))
398
+
399
+ assert_equal("any-token", token)
400
+ assert_equal("any-token", session.token)
401
+ end
402
+
403
+ test "extra parameters are stored in session" do
404
+ api_version = ShopifyAPI::ApiVersion.new(handle: :unstable)
405
+ fake(
406
+ nil,
407
+ url: "https://testshop.myshopify.com/admin/oauth/access_token",
408
+ method: :post,
409
+ body: '{"access_token":"any-token","foo":"example"}'
410
+ )
411
+ session = ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: nil, api_version: api_version)
412
+
413
+ params = { code: 'any-code', timestamp: Time.now }
414
+ assert(session.request_token(params.merge(hmac: generate_signature(params))))
415
+
416
+ assert_equal({ "foo" => "example" }, session.extra)
417
+ end
418
+
419
+ test "expires_in is automatically converted in expires_at" do
420
+ api_version = any_api_version
421
+ fake(
422
+ nil,
423
+ url: "https://testshop.myshopify.com/admin/oauth/access_token",
424
+ method: :post,
425
+ body: '{"access_token":"any-token","expires_in":86393}'
426
+ )
427
+ session = ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: nil, api_version: api_version)
428
+
429
+ Timecop.freeze do
430
+ params = { code: 'any-code', timestamp: Time.now }
431
+ assert(session.request_token(params.merge(hmac: generate_signature(params))))
432
+
433
+ expires_at = Time.now.utc + 86393
434
+ assert_equal({ "expires_at" => expires_at.to_i }, session.extra)
435
+ assert(session.expires_at.is_a?(Time))
436
+ assert_equal(expires_at.to_i, session.expires_at.to_i)
437
+ assert_equal(86393, session.expires_in)
438
+ assert_equal(false, session.expired?)
439
+
440
+ Timecop.travel(session.expires_at) do
441
+ assert_equal(true, session.expired?)
442
+ end
443
+ end
444
+ end
445
+
446
+ test "raise error if signature does not match expected" do
447
+ params = { code: "any-code", timestamp: Time.now }
448
+ signature = generate_signature(params)
449
+ params[:foo] = 'world'
450
+ assert_raises(ShopifyAPI::ValidationException) do
451
+ session = ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: nil, api_version: any_api_version)
452
+ session.request_token(params.merge(hmac: signature))
453
+ end
454
+ end
455
+
456
+ test "raise error if timestamp is too old" do
457
+ params = { code: "any-code", timestamp: Time.now - 2 * SECONDS_IN_A_DAY }
458
+ signature = generate_signature(params)
459
+ params[:foo] = 'world'
460
+ assert_raises(ShopifyAPI::ValidationException) do
461
+ session = ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: nil, api_version: any_api_version)
462
+ session.request_token(params.merge(hmac: signature))
463
+ end
464
+ end
465
+
466
+ test "return true when the signature is valid and the keys of params are strings" do
467
+ params = { 'code' => 'any-code', 'timestamp' => Time.now }
468
+ params[:hmac] = generate_signature(params)
469
+ assert_equal(true, ShopifyAPI::Session.validate_signature(params))
470
+ end
471
+
472
+ test "return true when validating signature of params with ampersand and equal sign characters" do
473
+ ShopifyAPI::Session.secret = 'secret'
474
+ params = { 'a' => '1&b=2', 'c=3&d' => '4' }
475
+ to_sign = 'a=1%26b=2&c%3D3%26d=4'
476
+ params[:hmac] = generate_signature(to_sign)
477
+ assert_equal(true, ShopifyAPI::Session.validate_signature(params))
478
+ end
479
+
480
+ test "return true when validating signature of params with percent sign characters" do
481
+ ShopifyAPI::Session.secret = 'secret'
482
+ params = { 'a%3D1%26b' => '2%26c%3D3' }
483
+ to_sign = 'a%253D1%2526b=2%2526c%253D3'
484
+ params[:hmac] = generate_signature(to_sign)
485
+ assert_equal(true, ShopifyAPI::Session.validate_signature(params))
486
+ end
487
+
488
+ test "url is aliased to domain to minimize the upgrade changes" do
489
+ session = ShopifyAPI::Session.new(
490
+ domain: "http://testshop.myshopify.com",
491
+ token: "any-token",
492
+ api_version: any_api_version
493
+ )
494
+
495
+ assert_equal('testshop.myshopify.com', session.url)
496
+ end
497
+
498
+ test "#hash returns the same value for equal Sessions" do
499
+ session = ShopifyAPI::Session.new(
500
+ domain: "http://testshop.myshopify.com",
501
+ token: "any-token",
502
+ api_version: '2019-01',
503
+ extra: { foo: "bar" }
504
+ )
505
+ other_session = ShopifyAPI::Session.new(
506
+ domain: "http://testshop.myshopify.com",
507
+ token: "any-token",
508
+ api_version: '2019-01',
509
+ extra: { foo: "bar" }
510
+ )
511
+ assert_equal(session.hash, other_session.hash)
512
+ end
513
+
514
+ test "equality verifies domain" do
515
+ session = ShopifyAPI::Session.new(
516
+ domain: "http://testshop.myshopify.com",
517
+ token: "any-token",
518
+ api_version: '2019-01',
519
+ extra: { foo: "bar" }
520
+ )
521
+ other_session = ShopifyAPI::Session.new(
522
+ domain: "http://testshop.myshopify.com",
523
+ token: "any-token",
524
+ api_version: '2019-01',
525
+ extra: { foo: "bar" }
526
+ )
527
+ different_session = ShopifyAPI::Session.new(
528
+ domain: "http://another_testshop.myshopify.com",
529
+ token: "any-token",
530
+ api_version: '2019-01',
531
+ extra: { foo: "bar" }
532
+ )
533
+ assert_equal(session, other_session)
534
+ refute_equal(session, different_session)
535
+ end
536
+
537
+ test "equality verifies token" do
538
+ session = ShopifyAPI::Session.new(
539
+ domain: "http://testshop.myshopify.com",
540
+ token: "any-token",
541
+ api_version: '2019-01',
542
+ extra: { foo: "bar" }
543
+ )
544
+ different_session = ShopifyAPI::Session.new(
545
+ domain: "http://testshop.myshopify.com",
546
+ token: "very-different-token",
547
+ api_version: '2019-01',
548
+ extra: { foo: "bar" }
549
+ )
550
+ refute_equal(session, different_session)
551
+ end
552
+
553
+ test "equality verifies api_version" do
554
+ session = ShopifyAPI::Session.new(
555
+ domain: "http://testshop.myshopify.com",
556
+ token: "any-token",
557
+ api_version: '2019-01',
558
+ extra: { foo: "bar" }
559
+ )
560
+ different_session = ShopifyAPI::Session.new(
561
+ domain: "http://testshop.myshopify.com",
562
+ token: "any-token",
563
+ api_version: :unstable,
564
+ extra: { foo: "bar" }
565
+ )
566
+ refute_equal(session, different_session)
567
+ end
568
+
569
+ test "equality verifies extra" do
570
+ session = ShopifyAPI::Session.new(
571
+ domain: "http://testshop.myshopify.com",
572
+ token: "any-token",
573
+ api_version: '2019-01',
574
+ extra: { foo: "bar" }
575
+ )
576
+ different_session = ShopifyAPI::Session.new(
577
+ domain: "http://testshop.myshopify.com",
578
+ token: "any-token",
579
+ api_version: '2019-01',
580
+ extra: { bar: "other-bar" }
581
+ )
582
+ refute_equal(session, different_session)
583
+ end
584
+
585
+ test "equality verifies other is a Session" do
586
+ session = ShopifyAPI::Session.new(
587
+ domain: "http://testshop.myshopify.com",
588
+ token: "any-token",
589
+ api_version: '2019-01',
590
+ extra: { foo: "bar" }
591
+ )
592
+ different_session = nil
593
+ refute_equal(session, different_session)
594
+ end
595
+
596
+ test "#eql? and #hash are implemented" do
597
+ session = ShopifyAPI::Session.new(
598
+ domain: "http://testshop.myshopify.com",
599
+ token: "any-token",
600
+ api_version: '2019-01',
601
+ extra: { foo: "bar" }
602
+ )
603
+ other_session = ShopifyAPI::Session.new(
604
+ domain: "http://testshop.myshopify.com",
605
+ token: "any-token",
606
+ api_version: '2019-01',
607
+ extra: { foo: "bar" }
608
+ )
609
+ different_session = ShopifyAPI::Session.new(
610
+ domain: "http://another_testshop.myshopify.com",
611
+ token: "any-token",
612
+ api_version: '2019-01',
613
+ extra: { foo: "bar" }
614
+ )
615
+
616
+ assert_equal([session, different_session], [session, other_session, different_session].uniq)
617
+ end
618
+
619
+ private
620
+
621
+ def assert_equal_uri(expected, actual)
622
+ assert_equal(Addressable::URI.parse(expected), Addressable::URI.parse(actual))
623
+ end
624
+
625
+ def make_sorted_params(params)
626
+ params.with_indifferent_access.except(
627
+ :signature, :hmac, :action, :controller
628
+ ).collect { |k, v| "#{k}=#{v}" }.sort.join('&')
629
+ end
630
+
631
+ def generate_signature(params)
632
+ params = make_sorted_params(params) if params.is_a?(Hash)
633
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('SHA256'), ShopifyAPI::Session.secret, params)
634
+ end
635
+
636
+ def any_api_version
637
+ version_name = ['2019-01', :unstable].sample(1).first
638
+ ShopifyAPI::ApiVersion.find_version(version_name)
639
+ end
640
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class ShippingRateTest < Test::Unit::TestCase
6
+ test ":get lists all shipping rates for a given checkout" do
7
+ fake 'checkouts', method: :get, status: 200, body: load_fixture('checkouts')
8
+ checkouts = ShopifyAPI::Checkout.all
9
+
10
+ fake "checkouts/#{checkouts.first.id}/shipping_rates",
11
+ method: :get, status: 200, body: load_fixture('checkouts')
12
+ shipping_rates = ShopifyAPI::ShippingRate.find(:all, params: { checkout_id: checkouts.first.id })
13
+
14
+ assert_equal 2, shipping_rates.first.shipping_rates.length
15
+ assert_equal 'canada_post-INT.TP.BOGUS-4.00', shipping_rates.first.shipping_rates.first.id
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class ShippingZoneTest < Test::Unit::TestCase
5
+ test "get all should get all shipping zones" do
6
+ fake('shipping_zones', method: :get, status: 200, body: load_fixture('shipping_zones'))
7
+ checkout = ShopifyAPI::ShippingZone.all
8
+ assert_equal(1, checkout.first.id)
9
+ assert_equal("Canada", checkout.first.name)
10
+ end
11
+ end