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,290 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class PaginationTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+
8
+ @version = ShopifyAPI::ApiVersion.find_version('2019-10')
9
+ ShopifyAPI::Base.api_version = @version.to_s
10
+ @next_page_info = "eyJkaXJlY3Rpb24iOiJuZXh0IiwibGFzdF9pZCI6NDQwMDg5NDIzLCJsYXN0X3ZhbHVlIjoiNDQwMDg5NDIzIn0%3D"
11
+ @previous_page_info = "eyJsYXN0X2lkIjoxMDg4MjgzMDksImxhc3RfdmFsdWUiOiIxMDg4MjgzMDkiLCJkaXJlY3Rpb24iOiJuZXh0In0%3D"
12
+
13
+ @next_link_header = "<https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/" \
14
+ "orders.json?page_info=#{@next_page_info}>; rel=\"next\""
15
+ @previous_link_header = "<https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/" \
16
+ "orders.json?page_info=#{@previous_page_info}>; rel=\"previous\""
17
+ end
18
+
19
+ test "navigates using next and previous link headers with no original params" do
20
+ link_header = "#{@previous_link_header}, #{@next_link_header}"
21
+
22
+ fake('orders', method: :get, status: 200, api_version: @version, body: load_fixture('orders'), link: link_header)
23
+ orders = ShopifyAPI::Order.all
24
+
25
+ fake(
26
+ 'orders',
27
+ url: "https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/orders.json?page_info=#{@next_page_info}",
28
+ method: :get,
29
+ status: 200,
30
+ body: load_fixture('orders')
31
+ )
32
+ next_page = orders.fetch_next_page
33
+ assert_equal(450789469, next_page.first.id)
34
+
35
+ fake(
36
+ 'orders',
37
+ url: "https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/orders.json?page_info=#{@previous_page_info}",
38
+ method: :get,
39
+ status: 200,
40
+ body: load_fixture('orders').gsub("450789469", "1122334455")
41
+ )
42
+
43
+ previous_page = orders.fetch_previous_page
44
+ assert_equal(1122334455, previous_page.first.id)
45
+ end
46
+
47
+ test "uses all passed in querystring parameters" do
48
+ params = "page_info=#{@next_page_info}&limit=50&fields=#{CGI.escape('id,created_at')}"
49
+ @next_link_header = "<https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/" \
50
+ "orders.json?#{params}>; rel=\"next\""
51
+ fake(
52
+ 'orders',
53
+ method: :get,
54
+ status: 200,
55
+ api_version: @version,
56
+ url: "https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/orders.json?fields=id%2Cupdated_at&limit=100",
57
+ body: load_fixture('orders'),
58
+ link: @next_link_header
59
+ )
60
+ orders = ShopifyAPI::Order.where(fields: 'id,updated_at', limit: 100)
61
+
62
+ fake(
63
+ 'orders',
64
+ method: :get,
65
+ status: 200,
66
+ api_version: @version,
67
+ url: "https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/" \
68
+ "orders.json?fields=id%2Ccreated_at&limit=50&page_info=#{@next_page_info}",
69
+ body: load_fixture('orders')
70
+ )
71
+ next_page = orders.fetch_next_page
72
+ assert_equal(450789469, next_page.first.id)
73
+ end
74
+
75
+ test "returns empty next page if just the previous page is present" do
76
+ fake(
77
+ 'orders', method: :get, status: 200, api_version: @version,
78
+ body: load_fixture('orders'), link: @previous_link_header
79
+ )
80
+ orders = ShopifyAPI::Order.all
81
+
82
+ next_page = orders.fetch_next_page
83
+ assert_empty(next_page)
84
+ end
85
+
86
+ test "returns an empty previous page if just the next page is present" do
87
+ fake(
88
+ 'orders', method: :get, status: 200, api_version: @version, body: load_fixture('orders'), link: @next_link_header
89
+ )
90
+ orders = ShopifyAPI::Order.all
91
+
92
+ next_page = orders.fetch_previous_page
93
+ assert_empty(next_page)
94
+ end
95
+
96
+ test "#next_page? returns true if next page is present" do
97
+ fake(
98
+ 'orders', method: :get, status: 200, api_version: @version, body: load_fixture('orders'), link: @next_link_header
99
+ )
100
+ orders = ShopifyAPI::Order.all
101
+
102
+ assert(orders.next_page?)
103
+ end
104
+
105
+ test "#next_page? returns false if next page is not present" do
106
+ fake(
107
+ 'orders', method: :get, status: 200, api_version: @version,
108
+ body: load_fixture('orders'), link: @previous_link_header
109
+ )
110
+ orders = ShopifyAPI::Order.all
111
+
112
+ refute(orders.next_page?)
113
+ end
114
+
115
+ test "#next_page_info returns next_page_info if next page is present" do
116
+ fake(
117
+ 'orders', method: :get, status: 200, api_version: @version, body: load_fixture('orders'), link: @next_link_header
118
+ )
119
+ orders = ShopifyAPI::Order.all
120
+
121
+ assert_equal(@next_page_info, orders.next_page_info)
122
+ end
123
+
124
+ test "#next_page_info returns nil if next page is not present" do
125
+ fake(
126
+ 'orders', method: :get, status: 200, api_version: @version,
127
+ body: load_fixture('orders'), link: @previous_link_header
128
+ )
129
+ orders = ShopifyAPI::Order.all
130
+
131
+ assert_nil(orders.next_page_info)
132
+ end
133
+
134
+ test "#previous_page? returns true if previous page is present" do
135
+ fake(
136
+ 'orders', method: :get, status: 200, api_version: @version,
137
+ body: load_fixture('orders'), link: @previous_link_header
138
+ )
139
+ orders = ShopifyAPI::Order.all
140
+
141
+ assert(orders.previous_page?)
142
+ end
143
+
144
+ test "#previous_page? returns false if next page is not present" do
145
+ fake(
146
+ 'orders', method: :get, status: 200, api_version: @version, body: load_fixture('orders'), link: @next_link_header
147
+ )
148
+ orders = ShopifyAPI::Order.all
149
+
150
+ refute(orders.previous_page?)
151
+ end
152
+
153
+ test "#previous_page_info returns previous_page_info if next page is present" do
154
+ fake(
155
+ 'orders', method: :get, status: 200, api_version: @version,
156
+ body: load_fixture('orders'), link: @previous_link_header
157
+ )
158
+ orders = ShopifyAPI::Order.all
159
+
160
+ assert_equal(@previous_page_info, orders.previous_page_info)
161
+ end
162
+
163
+ test "#previous_page_info returns nil if next page is not present" do
164
+ fake(
165
+ 'orders', method: :get, status: 200, api_version: @version, body: load_fixture('orders'), link: @next_link_header
166
+ )
167
+ orders = ShopifyAPI::Order.all
168
+
169
+ assert_nil(orders.previous_page_info)
170
+ end
171
+
172
+ test "pagination handles no link headers" do
173
+ fake('orders', method: :get, status: 200, api_version: @version, body: load_fixture('orders'))
174
+ orders = ShopifyAPI::Order.all
175
+
176
+ refute(orders.next_page?)
177
+ refute(orders.previous_page?)
178
+ assert_empty(orders.fetch_next_page)
179
+ assert_empty(orders.fetch_previous_page)
180
+ end
181
+
182
+ test "raises on invalid pagination links" do
183
+ link_header = "<https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/" \
184
+ "orders.json?page_info=#{@next_page_info}>;"
185
+ fake('orders', method: :get, status: 200, api_version: @version, body: load_fixture('orders'), link: link_header)
186
+
187
+ assert_raises(ShopifyAPI::InvalidPaginationLinksError) do
188
+ ShopifyAPI::Order.all
189
+ end
190
+ end
191
+
192
+ test "raises on an older API version" do
193
+ version = ShopifyAPI::ApiVersion.find_version('2019-04')
194
+ ShopifyAPI::Base.api_version = version.to_s
195
+
196
+ fake('orders', method: :get, status: 200, api_version: version, body: load_fixture('orders'))
197
+ orders = ShopifyAPI::Order.all
198
+
199
+ assert_raises(NotImplementedError) do
200
+ orders.fetch_next_page
201
+ end
202
+ end
203
+
204
+ test "raises on 2019-07 API version for models that don't support new pagination yet" do
205
+ version = ShopifyAPI::ApiVersion.find_version('2019-07')
206
+ ShopifyAPI::Base.api_version = version.to_s
207
+
208
+ fake('orders', method: :get, status: 200, api_version: version, body: load_fixture('orders'))
209
+ orders = ShopifyAPI::Order.all
210
+
211
+ assert_raises(NotImplementedError) do
212
+ orders.fetch_next_page
213
+ end
214
+ end
215
+
216
+ test "new pagination works on 2019-07 API version for select models" do
217
+ version = ShopifyAPI::ApiVersion.find_version('2019-07')
218
+ ShopifyAPI::Base.api_version = version.to_s
219
+
220
+ fake('events', method: :get, status: 200, api_version: version, body: load_fixture('events'))
221
+ events = ShopifyAPI::Event.all
222
+
223
+ assert_empty(events.fetch_next_page)
224
+ assert_empty(events.fetch_previous_page)
225
+ end
226
+
227
+ test "does not raise on the unstable version" do
228
+ version = ShopifyAPI::ApiVersion.find_version('unstable')
229
+ ShopifyAPI::Base.api_version = version.to_s
230
+ @next_link_header = "<https://this-is-my-test-shop.myshopify.com/admin/api/unstable/" \
231
+ "orders.json?page_info=#{@next_page_info}>; rel=\"next\""
232
+
233
+ link_header = "#{@previous_link_header}, #{@next_link_header}"
234
+
235
+ fake('orders', method: :get, status: 200, api_version: version, body: load_fixture('orders'), link: link_header)
236
+ orders = ShopifyAPI::Order.all
237
+
238
+ fake(
239
+ 'orders',
240
+ url: "https://this-is-my-test-shop.myshopify.com/admin/api/unstable/orders.json?page_info=#{@next_page_info}",
241
+ method: :get,
242
+ status: 200,
243
+ body: load_fixture('orders')
244
+ )
245
+ assert_nothing_raised do
246
+ next_page = orders.fetch_next_page
247
+ assert_equal(450789469, next_page.first.id)
248
+ end
249
+ end
250
+
251
+ test "allows for multiple concurrent API collection objects" do
252
+ first_request_params = "page_info=#{@next_page_info}&limit=5"
253
+ fake(
254
+ 'orders',
255
+ method: :get,
256
+ status: 200,
257
+ api_version: @version,
258
+ url: "https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/orders.json?limit=5",
259
+ body: load_fixture('orders'),
260
+ link: "<https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/" \
261
+ "orders.json?#{first_request_params}>; rel=\"next\""
262
+ )
263
+ ShopifyAPI::Order.where(limit: 5)
264
+
265
+ second_request_params = "page_info=#{@next_page_info}&limit=5"
266
+ fake(
267
+ 'orders',
268
+ method: :get,
269
+ status: 200,
270
+ api_version: @version,
271
+ url: "https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/orders.json?limit=10",
272
+ body: load_fixture('orders'),
273
+ link: "<https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/" \
274
+ "orders.json?#{second_request_params}>; rel=\"next\""
275
+ )
276
+ orders = ShopifyAPI::Order.where(limit: 10)
277
+
278
+ fake(
279
+ 'orders',
280
+ method: :get,
281
+ status: 200,
282
+ api_version: @version,
283
+ url: "https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/" \
284
+ "orders.json?limit=5&page_info=#{@next_page_info}",
285
+ body: load_fixture('orders')
286
+ )
287
+ next_page = orders.fetch_next_page
288
+ assert_equal(450789469, next_page.first.id)
289
+ end
290
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class PaymentTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+
8
+ @checkout_id = JSON.parse(load_fixture('checkout'))['checkout']['token']
9
+ @expected_payment = JSON.parse(load_fixture('payment'))['payment']
10
+ end
11
+
12
+ test ":create creates a new payment" do
13
+ fake "checkouts/#{@checkout_id}/payments", method: :post, status: 201, body: load_fixture('payment')
14
+
15
+ new_payment = ShopifyAPI::Payment.create(checkout_id: @checkout_id)
16
+
17
+ assert_equal @expected_payment['unique_token'], new_payment.attributes['unique_token']
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class PolicyTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+ fake('shop')
8
+ end
9
+
10
+ def test_getting_the_list_of_policies
11
+ fake('policies')
12
+
13
+ policies = ShopifyAPI::Policy.all
14
+ assert_equal(1, policies.length)
15
+
16
+ policy = policies.first
17
+ assert_equal('Privacy Policy', policy.title)
18
+ assert_equal('Your privacy is important to us', policy.body)
19
+ end
20
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class PriceRuleTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+ fake('price_rules/102586120', body: load_fixture('price_rule'))
8
+
9
+ @price_rule = ShopifyAPI::PriceRule.find(102586120)
10
+ end
11
+
12
+ def test_get_price_rule
13
+ fake('price_rules/102586120', method: :get, status: 200, body: load_fixture('price_rule'))
14
+ price_rule = ShopifyAPI::PriceRule.find(102586120)
15
+
16
+ assert_equal(102586120, price_rule.id)
17
+ end
18
+
19
+ def test_get_all_price_rules
20
+ fake('price_rules', method: :get, status: 200, body: load_fixture('price_rules'))
21
+ price_rules = ShopifyAPI::PriceRule.all
22
+
23
+ assert_equal(1, price_rules.length)
24
+ assert_equal(102586120, price_rules.first.id)
25
+ end
26
+
27
+ def test_get_all_discount_codes_for_a_price_rule
28
+ fake('price_rules/102586120/discount_codes', method: :get, status: 200, body: load_fixture('discount_codes'))
29
+ price_rule = ShopifyAPI::PriceRule.find(102586120)
30
+
31
+ assert_equal("SUMMERSALE10", price_rule.discount_codes.first.code)
32
+ end
33
+
34
+ def test_create_price_rule
35
+ fake('price_rules', method: :post, status: 201, body: load_fixture('price_rule'))
36
+
37
+ price_rule = ShopifyAPI::PriceRule.create(
38
+ target_type: "line_item",
39
+ allocation_method: "across",
40
+ value_type: "fixed_amount",
41
+ value: -10.0,
42
+ customer_selection: "all",
43
+ starts_at: "2017-01-19T00:00:00Z"
44
+ )
45
+
46
+ assert_equal(
47
+ '{"price_rule":{"target_type":"line_item","allocation_method":"across","value_type":"fixed_amount",' \
48
+ '"value":-10.0,"customer_selection":"all","starts_at":"2017-01-19T00:00:00Z"}}',
49
+ WebMock.last_request.body
50
+ )
51
+ assert_equal(-10, price_rule.value)
52
+ end
53
+
54
+ def test_update_price_rule
55
+ price_rule_response = ActiveSupport::JSON.decode(load_fixture('price_rule'))
56
+ price_rule_response['price_rule']['value'] = -50.0
57
+ @price_rule.value = -50.0
58
+ fake('price_rules/102586120', method: :put, status: 200, body: ActiveSupport::JSON.encode(price_rule_response))
59
+
60
+ @price_rule.save
61
+
62
+ assert_equal(price_rule_response['price_rule']['value'], @price_rule.value)
63
+ end
64
+
65
+ def test_delete_price_rule
66
+ fake('price_rules/102586120', method: :delete, body: 'destroyed')
67
+
68
+ assert(@price_rule.destroy)
69
+ end
70
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class ProductListingTest < Test::Unit::TestCase
5
+ def test_get_product_listings
6
+ fake("product_listings", method: :get, status: 201, body: load_fixture('product_listings'))
7
+
8
+ product_listings = ShopifyAPI::ProductListing.find(:all)
9
+ assert_equal(2, product_listings.count)
10
+ assert_equal(2, product_listings.first.product_id)
11
+ assert_equal(1, product_listings.last.product_id)
12
+ assert_equal('Synergistic Silk Chair', product_listings.first.title)
13
+ assert_equal('Rustic Copper Bottle', product_listings.last.title)
14
+ end
15
+
16
+ def test_get_product_listing
17
+ fake("product_listings/2", method: :get, status: 201, body: load_fixture('product_listing'))
18
+
19
+ product_listing = ShopifyAPI::ProductListing.find(2)
20
+ assert_equal('Synergistic Silk Chair', product_listing.title)
21
+ end
22
+
23
+ def test_reload_product_listing
24
+ fake("product_listings/2", method: :get, status: 201, body: load_fixture('product_listing'))
25
+
26
+ product_listing = ShopifyAPI::ProductListing.new(product_id: 2)
27
+ product_listing.reload
28
+
29
+ assert_equal('Synergistic Silk Chair', product_listing.title)
30
+ end
31
+
32
+ def test_get_product_listing_product_ids
33
+ fake("product_listings/product_ids", method: :get, status: 201, body: load_fixture('product_listing_product_ids'))
34
+
35
+ product_ids = ShopifyAPI::ProductListing.product_ids
36
+ assert_equal(2, product_ids.count)
37
+ assert_equal(4, product_ids.first)
38
+ assert_equal(3, product_ids.last)
39
+ end
40
+
41
+ def test_get_product_listing_product_ids_multi_page_with_cursor
42
+ version = ShopifyAPI::ApiVersion.find_version('2019-10')
43
+ ShopifyAPI::Base.api_version = version.to_s
44
+
45
+ url = "https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/product_listings/product_ids.json"
46
+
47
+ next_page_info = "notarealpageinfobutthatsokay"
48
+ next_page_url = "#{url}?page_info=#{next_page_info}"
49
+ link_header = "<#{next_page_url}>; rel=\"next\""
50
+
51
+ fake(
52
+ "product_listings/product_ids",
53
+ method: :get,
54
+ status: 201,
55
+ url: url,
56
+ body: load_fixture('product_listing_product_ids'),
57
+ link: link_header,
58
+ )
59
+
60
+ product_ids = ShopifyAPI::ProductListing.product_ids
61
+ assert_equal([4, 3], product_ids)
62
+ assert(product_ids.next_page?)
63
+
64
+ fake(
65
+ "product_listings/product_ids",
66
+ method: :get,
67
+ status: 201,
68
+ url: next_page_url,
69
+ body: load_fixture('product_listing_product_ids2'),
70
+ link: link_header,
71
+ )
72
+
73
+ next_page = product_ids.fetch_next_page
74
+ assert_equal([2, 1], next_page)
75
+ end
76
+
77
+ def test_get_product_listing_product_ids_multi_page_with_cursor_fails_on_older_api_version
78
+ version = ShopifyAPI::ApiVersion.find_version('2019-07')
79
+ ShopifyAPI::Base.api_version = version.to_s
80
+
81
+ url = "https://this-is-my-test-shop.myshopify.com/admin/api/2019-07/product_listings/product_ids.json"
82
+
83
+ fake(
84
+ "product_listings/product_ids",
85
+ method: :get,
86
+ status: 201,
87
+ url: url,
88
+ body: load_fixture('product_listing_product_ids'),
89
+ )
90
+
91
+ product_ids = ShopifyAPI::ProductListing.product_ids
92
+ assert_equal([4, 3], product_ids)
93
+ assert_raises(NotImplementedError) do
94
+ product_ids.next_page?
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class ProductPublicationTest < Test::Unit::TestCase
5
+ def test_get_all_product_publications
6
+ fake('publications/55650051/product_publications', body: load_fixture('product_publications'))
7
+ product_publications = ShopifyAPI::ProductPublication.find(:all, params: { publication_id: 55650051 })
8
+
9
+ assert_equal(647162527768, product_publications.first.id)
10
+ assert_equal(55650051, product_publications.first.publication_id)
11
+ end
12
+
13
+ def test_get_product_publication
14
+ fake('publications/55650051/product_publications/647162527768', body: load_fixture('product_publication'))
15
+ product_publication = ShopifyAPI::ProductPublication.find(647162527768, params: { publication_id: 55650051 })
16
+
17
+ assert_equal(647162527768, product_publication.id)
18
+ assert_equal(55650051, product_publication.publication_id)
19
+ end
20
+
21
+ def test_create_product_publication
22
+ fake('publications/55650051/product_publications', method: :post, body: load_fixture('product_publication'))
23
+ ShopifyAPI::ProductPublication.create(
24
+ publication_id: 55650051,
25
+ published_at: "2018-01-29T14:06:08-05:00",
26
+ published: true,
27
+ product_id: 8267093571
28
+ )
29
+
30
+ expected_body = {
31
+ product_publication: {
32
+ published_at: "2018-01-29T14:06:08-05:00",
33
+ published: true,
34
+ product_id: 8267093571,
35
+ },
36
+ }.to_json
37
+
38
+ assert_equal(expected_body, WebMock.last_request.body)
39
+ end
40
+ end
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class ProductTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+
8
+ refresh_product
9
+ end
10
+
11
+ def test_add_metafields_to_product
12
+ fake("products/632910392/metafields", method: :post, status: 201, body: load_fixture('metafield'))
13
+
14
+ field = @product.add_metafield(
15
+ ShopifyAPI::Metafield.new(namespace: "contact", key: "email", value: "123@example.com", value_type: "string")
16
+ )
17
+ assert_equal(
18
+ ActiveSupport::JSON.decode(
19
+ '{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'
20
+ ),
21
+ ActiveSupport::JSON.decode(WebMock.last_request.body)
22
+ )
23
+ assert(!field.new_record?)
24
+ assert_equal("contact", field.namespace)
25
+ assert_equal("email", field.key)
26
+ assert_equal("123@example.com", field.value)
27
+ end
28
+
29
+ def test_get_all_metafields_for_product
30
+ fake("products/632910392/metafields", body: load_fixture('metafields'))
31
+
32
+ metafields = @product.metafields
33
+
34
+ assert_equal(3, metafields.length)
35
+ assert(metafields.all? { |m| m.is_a?(ShopifyAPI::Metafield) })
36
+ end
37
+
38
+ def test_get_2_metafields_for_product
39
+ body = ActiveSupport::JSON.decode(load_fixture('metafields'))
40
+ body['metafields'].slice!(2, 1)
41
+
42
+ fake('products/632910392/metafields.json?limit=2', body: body.to_json, extension: false)
43
+
44
+ metafields = @product.metafields(limit: 2)
45
+
46
+ assert_equal(2, metafields.length)
47
+ assert(metafields.all? { |m| m.is_a?(ShopifyAPI::Metafield) })
48
+ end
49
+
50
+ def test_update_loaded_variant
51
+ fake("products/632910392/variants/808950810", method: :put, status: 200, body: load_fixture('variant'))
52
+
53
+ variant = @product.variants.first
54
+ variant.price = "0.50"
55
+ variant.save
56
+ end
57
+
58
+ def test_price_range
59
+ assert_equal('199.00', @product.price_range)
60
+ end
61
+
62
+ def test_price_range_when_has_different_price
63
+ @product.variants[0].price = '100.00'
64
+
65
+ assert_equal('100.00 - 199.00', @product.price_range)
66
+ end
67
+
68
+ def test_read_only_variant_inventory_fields_not_removed_in_2020_01
69
+ ShopifyAPI::Base.api_version = '2020-01'
70
+ refresh_product(api_version: ShopifyAPI::Base.api_version)
71
+
72
+ variant = @product.variants.first
73
+ assert_equal(10, variant.inventory_quantity)
74
+ end
75
+
76
+ def test_deprecated_inventory_fields_are_removed_in_2020_01
77
+ ShopifyAPI::Base.api_version = '2020-01'
78
+ refresh_product(api_version: ShopifyAPI::Base.api_version)
79
+
80
+ refute(@product.as_json.include?('total_inventory'))
81
+ end
82
+
83
+ def test_setting_product_total_inventory_passes_in_api_before_2019_10
84
+ ShopifyAPI::Base.api_version = '2019-07'
85
+ refresh_product(api_version: ShopifyAPI::Base.api_version)
86
+ @product.total_inventory = 8
87
+ end
88
+
89
+ def test_setting_product_total_inventory_fails_in_2019_10_api
90
+ ShopifyAPI::Base.api_version = '2019-10'
91
+ refresh_product(api_version: ShopifyAPI::Base.api_version)
92
+ assert_raises(ShopifyAPI::ValidationException) do
93
+ @product.total_inventory = 8
94
+ end
95
+ end
96
+
97
+ def test_setting_product_total_inventory_fails_in_the_unstable_api
98
+ ShopifyAPI::Base.api_version = :unstable
99
+ refresh_product(api_version: ShopifyAPI::Base.api_version)
100
+ assert_raises(ShopifyAPI::ValidationException) do
101
+ @product.total_inventory = 8
102
+ end
103
+ end
104
+
105
+ private
106
+
107
+ def refresh_product(api_version: nil)
108
+ fake("products/632910392", body: load_fixture('product'), api_version: api_version)
109
+ @product = ShopifyAPI::Product.find(632910392)
110
+ end
111
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class PublicationTest < Test::Unit::TestCase
5
+ def test_find_all_publications
6
+ fake('publications')
7
+ publications = ShopifyAPI::Publication.find(:all)
8
+
9
+ assert_equal(55650051, publications.first.id)
10
+ assert_equal("Buy Button", publications.first.name)
11
+ end
12
+ end