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,18 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class CarrierServiceTest < Test::Unit::TestCase
5
+ test 'new should create carrier service' do
6
+ fake("carrier_services", method: :post, body: load_fixture('carrier_service'))
7
+ carrier_service = ShopifyAPI::CarrierService.new(name: "Some Postal Service")
8
+ carrier_service.save
9
+ assert_equal("Some Postal Service", carrier_service.name)
10
+ end
11
+
12
+ test 'find should return the carrier service' do
13
+ fake("carrier_services/123456", method: :get, body: load_fixture('carrier_service'))
14
+ carrier_service = ShopifyAPI::CarrierService.find(123456)
15
+ assert_equal(123456, carrier_service.id)
16
+ assert_equal("Some Postal Service", carrier_service.name)
17
+ end
18
+ end
data/test/cart_test.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class CartTest < Test::Unit::TestCase
5
+ test 'all should return all carts' do
6
+ fake 'carts'
7
+ carts = ShopifyAPI::Cart.all
8
+ assert_equal carts.size, 2
9
+ assert_equal 2, carts.first.id
10
+ assert_equal "3eed8183d4281db6ea82ee2b8f23e9cc", carts.first.token
11
+ assert_equal 1, carts.first.line_items.size
12
+ assert_equal 'test', carts.first.line_items.first.title
13
+ end
14
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class CheckoutsTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+
8
+ @expected_checkouts = JSON.parse(load_fixture('checkouts'))['checkouts']
9
+ @expected_checkout_id = JSON.parse(load_fixture('checkout'))['checkout']['token']
10
+ end
11
+
12
+ test ".headers includes a version" do
13
+ assert_equal "2016-09-06", ShopifyAPI::Checkout.headers["X-Shopify-Checkout-Version"]
14
+ assert_nil ShopifyAPI::Base.headers["X-Shopify-Checkout-Version"]
15
+ end
16
+
17
+ test ":create creates a checkout" do
18
+ fake 'checkouts', method: :post, status: 201, body: load_fixture('checkout')
19
+
20
+ checkout = ShopifyAPI::Checkout.create
21
+
22
+ assert_equal @expected_checkout_id, checkout.id
23
+ end
24
+
25
+ test "get all checkouts indexed by token" do
26
+ fake 'checkouts', method: :get, status: 200, body: load_fixture('checkouts')
27
+
28
+ checkouts = ShopifyAPI::Checkout.all
29
+
30
+ assert_equal @expected_checkout_id, checkouts.first.id
31
+ assert_equal @expected_checkouts.size, checkouts.size
32
+ end
33
+
34
+ test ":complete completes a checkout" do
35
+ fake "checkouts/#{@expected_checkout_id}", method: :get, status: 200, body: load_fixture('checkout')
36
+
37
+ checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
38
+
39
+ fake "checkouts/#{@expected_checkout_id}/complete", method: :post, status: 200, body: load_fixture('checkouts')
40
+
41
+ checkout.complete
42
+ end
43
+
44
+ test ":ready? returns true when status is 201" do
45
+ fake "checkouts/#{@expected_checkout_id}", method: :get, status: 201, body: load_fixture('checkout')
46
+ checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
47
+
48
+ assert_predicate checkout, :ready?
49
+ end
50
+
51
+ test ":ready? returns false when status is 202" do
52
+ fake "checkouts/#{@expected_checkout_id}", method: :get, status: 202, body: load_fixture('checkout')
53
+ checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
54
+
55
+ refute_predicate checkout, :ready?
56
+ end
57
+
58
+ test ":payments returns payments for a checkout" do
59
+ fake "checkouts/#{@expected_checkout_id}", method: :get, status: 200, body: load_fixture('checkout')
60
+ checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
61
+
62
+ fake "checkouts/#{@expected_checkout_id}/payments", method: :get, status: 202, body: load_fixture('payments')
63
+
64
+ assert_equal 10.00, checkout.payments.first.amount
65
+ end
66
+
67
+ test ":shipping_rates returns shipping rates for a checkout" do
68
+ fake "checkouts/#{@expected_checkout_id}", method: :get, status: 200, body: load_fixture('checkout')
69
+ checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
70
+
71
+ fake("checkouts/#{@expected_checkout_id}/shipping_rates",
72
+ method: :get,
73
+ status: 202,
74
+ body: load_fixture('shipping_rates'))
75
+ assert_equal "canada_post-INT.TP.BOGUS-4.00", checkout.shipping_rates.first.id
76
+ end
77
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class CollectTest < Test::Unit::TestCase
5
+ test "#create should create a collect" do
6
+ fake("collects", method: :post, status: 201, body: load_fixture('collect'))
7
+ link = ShopifyAPI::Collect.create(product_id: 921728736, collection_id: 841564295)
8
+ assert_equal(841564295, link.id)
9
+ end
10
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class CollectionListingTest < Test::Unit::TestCase
5
+ def test_get_collection_listings
6
+ fake("collection_listings", method: :get, status: 201, body: load_fixture('collection_listings'))
7
+
8
+ collection_listings = ShopifyAPI::CollectionListing.find(:all)
9
+
10
+ assert_equal(1, collection_listings.count)
11
+ assert_equal(1, collection_listings.first.collection_id)
12
+ assert_equal('Home page', collection_listings.first.title)
13
+ end
14
+
15
+ def test_get_collection_listing
16
+ fake("collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing'))
17
+
18
+ collection_listing = ShopifyAPI::CollectionListing.find(1)
19
+
20
+ assert_equal(1, collection_listing.collection_id)
21
+ assert_equal('Home page', collection_listing.title)
22
+ end
23
+
24
+ def test_get_collection_listing_reload
25
+ fake("collection_listings/1", method: :get, status: 201, body: load_fixture('collection_listing'))
26
+
27
+ collection_listing = ShopifyAPI::CollectionListing.new(collection_id: 1)
28
+ collection_listing.reload
29
+
30
+ assert_equal(1, collection_listing.collection_id)
31
+ assert_equal('Home page', collection_listing.title)
32
+ end
33
+
34
+ def test_get_collection_listing_product_ids
35
+ fake(
36
+ "collection_listings/1/product_ids",
37
+ method: :get,
38
+ status: 201,
39
+ body: load_fixture('collection_listing_product_ids')
40
+ )
41
+
42
+ collection_listing = ShopifyAPI::CollectionListing.new(collection_id: 1)
43
+
44
+ assert_equal([1, 2], collection_listing.product_ids)
45
+ end
46
+
47
+ def test_get_collection_listing_product_ids_multi_page_with_cursor
48
+ version = ShopifyAPI::ApiVersion.find_version('2019-07')
49
+ ShopifyAPI::Base.api_version = version.to_s
50
+
51
+ collection_listing = ShopifyAPI::CollectionListing.new(collection_id: 1)
52
+
53
+ url = "https://this-is-my-test-shop.myshopify.com/admin/api/2019-07/collection_listings/1/product_ids.json"
54
+
55
+ next_page_info = "notarealpageinfobutthatsokay"
56
+ next_page_url = "#{url}?page_info=#{next_page_info}"
57
+ link_header = "<#{next_page_url}>; rel=\"next\""
58
+
59
+ fake(
60
+ "collection_listings/1/product_ids",
61
+ method: :get,
62
+ status: 201,
63
+ url: url,
64
+ body: load_fixture('collection_listing_product_ids'),
65
+ link: link_header,
66
+ )
67
+
68
+ product_ids = collection_listing.product_ids
69
+ assert_equal([1, 2], product_ids)
70
+ assert(product_ids.next_page?)
71
+
72
+ fake(
73
+ "collection_listings/1/product_ids",
74
+ method: :get,
75
+ status: 201,
76
+ url: next_page_url,
77
+ body: load_fixture('collection_listing_product_ids2'),
78
+ link: link_header,
79
+ )
80
+
81
+ next_page = product_ids.fetch_next_page
82
+ assert_equal([3, 4], next_page)
83
+ end
84
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class CollectionPublicationTest < Test::Unit::TestCase
5
+ def test_get_all_collection_publications
6
+ fake('publications/55650051/collection_publications', body: load_fixture('collection_publications'))
7
+ collection_publications = ShopifyAPI::CollectionPublication.find(:all, params: { publication_id: 55650051 })
8
+
9
+ assert_equal(96062799894, collection_publications.first.id)
10
+ assert_equal(55650051, collection_publications.first.publication_id)
11
+ end
12
+
13
+ def test_get_collection_publication
14
+ fake('publications/55650051/collection_publications/647162527768', body: load_fixture('collection_publication'))
15
+ collection_publication = ShopifyAPI::CollectionPublication.find(647162527768, params: { publication_id: 55650051 })
16
+
17
+ assert_equal(96062799894, collection_publication.id)
18
+ assert_equal(55650051, collection_publication.publication_id)
19
+ end
20
+
21
+ def test_create_collection_publication
22
+ fake('publications/55650051/collection_publications', method: :post, body: load_fixture('collection_publication'))
23
+ ShopifyAPI::CollectionPublication.create(
24
+ publication_id: 55650051,
25
+ published_at: "2018-01-29T14:06:08-05:00",
26
+ published: true,
27
+ collection_id: 8267093571
28
+ )
29
+
30
+ expected_body = {
31
+ collection_publication: {
32
+ published_at: "2018-01-29T14:06:08-05:00",
33
+ published: true,
34
+ collection_id: 8267093571,
35
+ },
36
+ }.to_json
37
+
38
+ assert_equal(expected_body, WebMock.last_request.body)
39
+ end
40
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class CollectionTest < Test::Unit::TestCase
5
+ test "Collection get products gets all products in a collection on 2020-01 version" do
6
+ available_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: '2020-01')
7
+ ShopifyAPI::Base.activate_session(available_version)
8
+
9
+ fake(
10
+ 'collections',
11
+ url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1.json',
12
+ method: :get,
13
+ status: 200,
14
+ body: load_fixture('collection'),
15
+ extension: false
16
+ )
17
+
18
+ collection = ShopifyAPI::Collection.find(1)
19
+
20
+ fake(
21
+ 'products',
22
+ url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1/products.json',
23
+ method: :get,
24
+ status: 200,
25
+ body: load_fixture('collection_products'),
26
+ extension: false
27
+ )
28
+ assert_equal [632910392, 921728736], collection.products.map(&:id)
29
+ end
30
+
31
+ test "Collection get products fails on older api version" do
32
+ old_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: '2019-10')
33
+ ShopifyAPI::Base.activate_session(old_version)
34
+
35
+ fake(
36
+ 'collections',
37
+ url: 'https://shop2.myshopify.com/admin/api/2019-10/collections/1.json',
38
+ method: :get,
39
+ status: 200,
40
+ body: load_fixture('collection'),
41
+ extension: false
42
+ )
43
+
44
+ collection = ShopifyAPI::Collection.find(1)
45
+
46
+ assert_raises(NotImplementedError) do
47
+ collection.products
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class CountableTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+ fake("products/count", body: '{"count": 16}')
8
+ end
9
+
10
+ def test_count_products
11
+ count = ShopifyAPI::Product.count
12
+ assert_equal(16, count)
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+
2
+ # frozen_string_literal: true
3
+ require 'test_helper'
4
+ class CurrencyTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+ fake("currencies", method: :get, body: load_fixture('currencies'))
8
+ end
9
+
10
+ context "Currency" do
11
+ should 'return a list of enabled currencies' do
12
+ currencies = ShopifyAPI::Currency.all
13
+ assert_equal(4, currencies.count)
14
+ assert_equal(%w(AUD EUR GBP HKD), currencies.map(&:currency))
15
+ assert_equal([true, true, true, false], currencies.map(&:enabled))
16
+ currencies.each do |currency|
17
+ assert_equal("2018-10-03T14:44:08-04:00", currency.rate_updated_at)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class CustomCollectionTest < Test::Unit::TestCase
5
+ test "#create should create a custom collection" do
6
+ fake("custom_collections", method: :post, status: 201, body: load_fixture('custom_collection'))
7
+ link = ShopifyAPI::CustomCollection.create(title: "Macbooks", image: { src: "http://example.com/rails_logo.gif" })
8
+ assert_equal(1063001463, link.id)
9
+ end
10
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class CustomerSavedSearchTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+ load_customer_saved_search
8
+ end
9
+
10
+ def test_get_customers_from_customer_saved_search
11
+ fake(
12
+ 'customers/search.json?customer_saved_search_id=8899730',
13
+ body: load_fixture('customer_saved_search_customers'),
14
+ extension: false
15
+ )
16
+ assert_equal(1, @customer_saved_search.customers.length)
17
+ assert_equal(112223902, @customer_saved_search.customers.first.id)
18
+ end
19
+
20
+ def test_get_customers_from_customer_saved_search_with_params
21
+ fake(
22
+ 'customers/search.json?customer_saved_search_id=8899730&limit=1',
23
+ body: load_fixture('customer_saved_search_customers'),
24
+ extension: false
25
+ )
26
+ customers = @customer_saved_search.customers(limit: 1)
27
+ assert_equal(1, customers.length)
28
+ assert_equal(112223902, customers.first.id)
29
+ end
30
+
31
+ private
32
+
33
+ def load_customer_saved_search
34
+ fake('customer_saved_searches/8899730', body: load_fixture('customer_saved_search'))
35
+ @customer_saved_search = ShopifyAPI::CustomerSavedSearch.find(8899730)
36
+ end
37
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class CustomerTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+
8
+ fake('customers/207119551', body: load_fixture('customers'))
9
+
10
+ @customer = ShopifyAPI::Customer.find(207119551)
11
+ end
12
+
13
+ test "search should get a customers collection" do
14
+ fake(
15
+ "customers/search.json?query=Bob+country%3AUnited+States",
16
+ extension: false,
17
+ body: load_fixture('customers_search')
18
+ )
19
+
20
+ results = ShopifyAPI::Customer.search(query: 'Bob country:United States')
21
+ assert_equal('Bob', results.first.first_name)
22
+ end
23
+
24
+ test "account_activation_url should create an account activation url" do
25
+ fake(
26
+ "customers/207119551/account_activation_url",
27
+ method: :post,
28
+ body: load_fixture('customers_account_activation_url')
29
+ )
30
+
31
+ activation_url = "http://apple.myshopify.com/account/activate/207119551/86688abf23572680740b1c062fa37111-1458248616"
32
+ assert_equal(activation_url, @customer.account_activation_url)
33
+ end
34
+
35
+ test "#send_invite with no params" do
36
+ customer_invite_fixture = load_fixture('customer_invite')
37
+ customer_invite = ActiveSupport::JSON.decode(customer_invite_fixture)
38
+ fake('customers/207119551/send_invite', method: :post, body: customer_invite_fixture)
39
+
40
+ customer_invite_response = @customer.send_invite
41
+
42
+ assert_equal('{"customer_invite":{}}', WebMock.last_request.body)
43
+ assert_kind_of(ShopifyAPI::CustomerInvite, customer_invite_response)
44
+ assert_equal(customer_invite['customer_invite']['to'], customer_invite_response.to)
45
+ end
46
+
47
+ test "#send_invite with params" do
48
+ customer_invite_fixture = load_fixture('customer_invite')
49
+ customer_invite = ActiveSupport::JSON.decode(customer_invite_fixture)
50
+ fake('customers/207119551/send_invite', method: :post, body: customer_invite_fixture)
51
+
52
+ customer_invite_response = @customer.send_invite(ShopifyAPI::CustomerInvite.new(customer_invite['customer_invite']))
53
+
54
+ assert_equal(customer_invite, ActiveSupport::JSON.decode(WebMock.last_request.body))
55
+ assert_kind_of(ShopifyAPI::CustomerInvite, customer_invite_response)
56
+ assert_equal(customer_invite['customer_invite']['to'], customer_invite_response.to)
57
+ end
58
+ end
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+ require "active_support/log_subscriber/test_helper"
4
+ require 'json'
5
+
6
+ class LogSubscriberTest < Test::Unit::TestCase
7
+ include ActiveSupport::LogSubscriber::TestHelper
8
+
9
+ attr_reader :request_headers
10
+
11
+ def setup
12
+ super
13
+ @page = { page: { id: 1, title: 'Shopify API' } }.to_json
14
+ @ua_header = "\"User-Agent\"=>\"RubyShopifyAPI/#{ShopifyAPI::VERSION} " \
15
+ "ActiveResource/#{ActiveResource::VERSION::STRING} Ruby/#{RUBY_VERSION}\""
16
+ @request_headers = "Headers: {\"Accept\"=>\"application/json\", " \
17
+ "#{@ua_header}, \"X-Shopify-Access-Token\"=>\"[FILTERED]\"}"
18
+
19
+ ShopifyAPI::Base.clear_session
20
+ fake(
21
+ "apis",
22
+ url: "https://app.shopify.com/services/apis.json",
23
+ method: :get,
24
+ status: 200,
25
+ api_version: :stub,
26
+ body: load_fixture('apis')
27
+ )
28
+ ShopifyAPI::ApiVersion.fetch_known_versions
29
+ session = ShopifyAPI::Session.new(
30
+ domain: "https://this-is-my-test-shop.myshopify.com",
31
+ token: "access_token",
32
+ api_version: '2019-01'
33
+ )
34
+
35
+ ShopifyAPI::Base.activate_session(session)
36
+
37
+ ActiveResource::LogSubscriber.attach_to(:active_resource)
38
+ ActiveResource::DetailedLogSubscriber.attach_to(:active_resource_detailed)
39
+ end
40
+
41
+ def teardown
42
+ super
43
+ ShopifyAPI::ApiVersion.clear_known_versions
44
+ ShopifyAPI::ApiVersion.version_lookup_mode = :raise_on_unknown
45
+ end
46
+
47
+ def set_logger(logger)
48
+ ActiveResource::Base.logger = logger
49
+ end
50
+
51
+ test "logging on #find" do
52
+ fake("pages/1", method: :get, body: @page)
53
+
54
+ ShopifyAPI::Page.find(1)
55
+
56
+ assert_equal(4, @logger.logged(:info).size)
57
+ assert_equal(
58
+ "GET https://this-is-my-test-shop.myshopify.com:443/admin/api/2019-01/pages/1.json",
59
+ @logger.logged(:info)[0]
60
+ )
61
+ assert_match(/\-\-\> 200/, @logger.logged(:info)[1])
62
+ assert_equal(request_headers, @logger.logged(:info)[2])
63
+ assert_match(
64
+ %r{(Response:\n\{\"page\"\:\{\"id\"\:1,\"title\"\:\"Shopify API\"\}\})|
65
+ (Response:\n\{\"page\"\:\{\"title\"\:\"Shopify API\",\"id\"\:1\}\})},
66
+ @logger.logged(:info)[3]
67
+ )
68
+ end
69
+
70
+ test "logging on #find with an error" do
71
+ fake("pages/2", method: :get, body: nil, status: 404)
72
+
73
+ assert_raises(ActiveResource::ResourceNotFound) do
74
+ ShopifyAPI::Page.find(2)
75
+ end
76
+
77
+ if ar_version_before?('5.1.0')
78
+ assert_equal(4, @logger.logged(:info).size)
79
+ assert_equal(
80
+ "GET https://this-is-my-test-shop.myshopify.com:443/admin/api/2019-01/pages/2.json",
81
+ @logger.logged(:info)[0]
82
+ )
83
+ assert_match(/\-\-\> 404/, @logger.logged(:info)[1])
84
+ assert_equal(request_headers, @logger.logged(:info)[2])
85
+ assert_equal("Response:", @logger.logged(:info)[3])
86
+ else
87
+ assert_equal(2, @logger.logged(:error).size)
88
+ assert_equal(
89
+ "GET https://this-is-my-test-shop.myshopify.com:443/admin/api/2019-01/pages/2.json",
90
+ @logger.logged(:error)[0]
91
+ )
92
+ assert_match(/\-\-\> 404/, @logger.logged(:error)[1])
93
+
94
+ assert_equal(2, @logger.logged(:info).size)
95
+ assert_equal(request_headers, @logger.logged(:info)[0])
96
+ assert_equal("Response:", @logger.logged(:info)[1])
97
+ end
98
+ end
99
+
100
+ test "warns when the server responds with a x-shopify-api-deprecated-reason header" do
101
+ fake(
102
+ "pages/1",
103
+ method: :get,
104
+ body: @page,
105
+ x_shopify_api_deprecated_reason: 'https://help.shopify.com/en/api/getting-started/api-deprecations'
106
+ )
107
+
108
+ ShopifyAPI::Page.find(1)
109
+
110
+ assert_equal(1, @logger.logged(:warn).size)
111
+
112
+ assert_match(
113
+ %r{\[DEPRECATED\] ShopifyAPI made a call to GET /admin/api/2019-01/pages/1.json},
114
+ @logger.logged(:warn).first
115
+ )
116
+ assert_match(
117
+ %r{See https:\/\/help.shopify.com\/en\/api\/getting-started\/api-deprecations for more details.},
118
+ @logger.logged(:warn).first
119
+ )
120
+ end
121
+
122
+ test "warns when the server responds with a x-shopify-api-version-warning header" do
123
+ fake(
124
+ "pages/1",
125
+ method: :get,
126
+ body: @page,
127
+ x_shopify_api_version_warning: 'https://shopify.dev/concepts/about-apis/versioning'
128
+ )
129
+
130
+ ShopifyAPI::Page.find(1)
131
+
132
+ assert_equal(1, @logger.logged(:warn).size)
133
+
134
+ assert_match(
135
+ %r{\[API Version Warning\] ShopifyAPI made a call to GET /admin/api/2019-01/pages/1.json},
136
+ @logger.logged(:warn).first
137
+ )
138
+ assert_match(
139
+ %r{See https:\/\/shopify.dev\/concepts\/about-apis\/versioning for more details.},
140
+ @logger.logged(:warn).first
141
+ )
142
+ end
143
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class DiscountCodeBatchTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+ fake('price_rules/102586120/batch/989355119', body: load_fixture('discount_code_batch'))
8
+ end
9
+
10
+ def test_get_batch
11
+ batch = ShopifyAPI::DiscountCodeBatch.find(989355119, params: { price_rule_id: 102586120 })
12
+
13
+ assert_equal(989355119, batch.id)
14
+ end
15
+
16
+ def test_get_batch_discount_codes
17
+ fake(
18
+ 'price_rules/102586120/batch/989355119/discount_codes',
19
+ method: :get,
20
+ status: 200,
21
+ body: load_fixture('discount_code_batch_discount_codes')
22
+ )
23
+ batch = ShopifyAPI::DiscountCodeBatch.find(989355119, params: { price_rule_id: 102586120 })
24
+ discount_code_job = batch.discount_code_job
25
+
26
+ assert_equal(3, discount_code_job.count)
27
+ assert(discount_code_job[2].errors.present?)
28
+ end
29
+
30
+ def test_create_batch
31
+ fake('price_rules/102586120/batch', method: :post, status: 201, body: load_fixture('discount_code_batch'))
32
+ batch = ShopifyAPI::DiscountCodeBatch.new
33
+ batch.prefix_options[:price_rule_id] = 102586120
34
+ discount_codes = [{ "code": "SUMMER1" }, { "code": "SUMMER2" }, { "code": "SUMMER3" }]
35
+ batch.discount_codes = discount_codes
36
+ batch.save
37
+
38
+ expected_body = { discount_codes: discount_codes }.to_json
39
+ assert_equal(expected_body, WebMock.last_request.body)
40
+ end
41
+ end