ruby_shopify_api 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,239 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+ require 'fulfillment_order_test_helper'
4
+
5
+ class FulFillmentTest < Test::Unit::TestCase
6
+ include FulfillmentOrderTestHelper
7
+
8
+ def setup
9
+ super
10
+ fake("orders/450789469/fulfillments/255858046", method: :get, body: load_fixture('fulfillment'))
11
+ end
12
+
13
+ context "Fulfillment" do
14
+ context "#complete" do
15
+ should "be able to complete fulfillment" do
16
+ fulfillment = ShopifyAPI::Fulfillment.find(255858046, params: { order_id: 450789469 })
17
+
18
+ success = ActiveSupport::JSON.decode(load_fixture('fulfillment'))
19
+ success['fulfillment']['status'] = 'success'
20
+ fake(
21
+ "orders/450789469/fulfillments/255858046/complete", method: :post, body: ActiveSupport::JSON.encode(success)
22
+ )
23
+
24
+ assert_equal('pending', fulfillment.status)
25
+ assert(fulfillment.complete)
26
+ assert_equal('success', fulfillment.status)
27
+ end
28
+ end
29
+
30
+ context "#cancel" do
31
+ should "be able to cancel fulfillment" do
32
+ fulfillment = ShopifyAPI::Fulfillment.find(255858046, params: { order_id: 450789469 })
33
+
34
+ cancelled = ActiveSupport::JSON.decode(load_fixture('fulfillment'))
35
+ cancelled['fulfillment']['status'] = 'cancelled'
36
+ fake(
37
+ "orders/450789469/fulfillments/255858046/cancel", method: :post, body: ActiveSupport::JSON.encode(cancelled)
38
+ )
39
+
40
+ assert_equal('pending', fulfillment.status)
41
+ assert(fulfillment.cancel)
42
+ assert_equal('cancelled', fulfillment.status)
43
+ end
44
+ end
45
+
46
+ context "#open" do
47
+ should "be able to open a fulfillment" do
48
+ fulfillment = ShopifyAPI::Fulfillment.find(255858046, params: { order_id: 450789469 })
49
+
50
+ open_fulfillment = ActiveSupport::JSON.decode(load_fixture('fulfillment'))
51
+ open_fulfillment['fulfillment']['status'] = 'open'
52
+ fake(
53
+ "orders/450789469/fulfillments/255858046/open",
54
+ method: :post,
55
+ body: ActiveSupport::JSON.encode(open_fulfillment)
56
+ )
57
+
58
+ assert_equal('pending', fulfillment.status)
59
+ assert(fulfillment.open)
60
+ assert_equal('open', fulfillment.status)
61
+ end
62
+ end
63
+
64
+ context "#find" do
65
+ should "be able to find fulfillment" do
66
+ fulfillment = ShopifyAPI::Fulfillment.find(255858046, params: { order_id: 450789469 })
67
+ assert_equal(255858046, fulfillment.id)
68
+ assert_equal(450789469, fulfillment.order_id)
69
+ end
70
+ end
71
+
72
+ context "#create" do
73
+ should "create a fulfillment with line_items_by_fulfillment_order" do
74
+ create_fulfillment_attributes = {
75
+ message: "The message for this FO fulfillment",
76
+ notify_customer: true,
77
+ tracking_info: {
78
+ number: "XSDFHYR23475",
79
+ url: "https://tracking.example.com/XSDFHYR23475",
80
+ company: "TFTC - the fulfillment/tracking company",
81
+ },
82
+ line_items_by_fulfillment_order: [
83
+ {
84
+ fulfillment_order_id: 3,
85
+ fulfillment_order_line_items: [{ id: 2, quantity: 1 }],
86
+ },
87
+ ],
88
+ }
89
+ request_body = { fulfillment: create_fulfillment_attributes }
90
+ response_body = { fulfillment: create_fulfillment_attributes.merge(id: 346743624) }
91
+ url_prefix = url_prefix_for_activated_session_for('2020-01')
92
+ fake(
93
+ 'fulfillments',
94
+ url: "#{url_prefix}/fulfillments.json",
95
+ method: :post,
96
+ request_body: ActiveSupport::JSON.encode(request_body),
97
+ body: ActiveSupport::JSON.encode(response_body)
98
+ )
99
+ fulfillment = ShopifyAPI::Fulfillment.create(create_fulfillment_attributes)
100
+ assert(fulfillment.is_a?(ShopifyAPI::Fulfillment))
101
+ assert(fulfillment.persisted?)
102
+ assert_equal(346743624, fulfillment.id)
103
+ end
104
+
105
+ should "raise NotImplementedError when api_version is older than 2020-01" do
106
+ create_fulfillment_attributes = {
107
+ message: "The message for this FO fulfillment",
108
+ notify_customer: true,
109
+ tracking_info: {
110
+ number: "XSDFHYR23475",
111
+ url: "https://tracking.example.com/XSDFHYR23475",
112
+ company: "TFTC - the fulfillment/tracking company",
113
+ },
114
+ line_items_by_fulfillment_order: [
115
+ {
116
+ fulfillment_order_id: 3,
117
+ fulfillment_order_line_items: [{ id: 2, quantity: 1 }],
118
+ },
119
+ ],
120
+ }
121
+ request_body = { fulfillment: create_fulfillment_attributes }
122
+ response_body = { fulfillment: create_fulfillment_attributes.merge(id: 346743624) }
123
+ url_prefix = url_prefix_for_activated_session_for('2019-10')
124
+ fake(
125
+ 'fulfillments',
126
+ url: "#{url_prefix}/fulfillments.json",
127
+ method: :post,
128
+ request_body: ActiveSupport::JSON.encode(request_body),
129
+ body: ActiveSupport::JSON.encode(response_body)
130
+ )
131
+ assert_raises(NotImplementedError) do
132
+ ShopifyAPI::Fulfillment.create(create_fulfillment_attributes)
133
+ end
134
+ end
135
+ end
136
+
137
+ context "#save" do
138
+ should "save a fulfillment with line_items_by_fulfillment_order" do
139
+ create_fulfillment_attributes = {
140
+ message: "The message for this FO fulfillment",
141
+ notify_customer: true,
142
+ tracking_info: {
143
+ number: "XSDFHYR23475",
144
+ url: "https://tracking.example.com/XSDFHYR23475",
145
+ company: "TFTC - the fulfillment/tracking company",
146
+ },
147
+ line_items_by_fulfillment_order: [
148
+ {
149
+ fulfillment_order_id: 3,
150
+ fulfillment_order_line_items: [{ id: 2, quantity: 1 }],
151
+ },
152
+ ],
153
+ }
154
+ request_body = { fulfillment: create_fulfillment_attributes }
155
+ response_body = { fulfillment: create_fulfillment_attributes.merge(id: 346743624) }
156
+ url_prefix = url_prefix_for_activated_session_for('2020-01')
157
+ fake(
158
+ 'fulfillments',
159
+ url: "#{url_prefix}/fulfillments.json",
160
+ method: :post,
161
+ request_body: ActiveSupport::JSON.encode(request_body),
162
+ body: ActiveSupport::JSON.encode(response_body)
163
+ )
164
+ fulfillment = ShopifyAPI::Fulfillment.new(create_fulfillment_attributes)
165
+ assert(fulfillment.save)
166
+ assert(fulfillment.is_a?(ShopifyAPI::Fulfillment))
167
+ assert(fulfillment.persisted?)
168
+ assert_equal(346743624, fulfillment.id)
169
+ end
170
+
171
+ should "save a fulfillment without line_items_by_fulfillment_order" do
172
+ order_id = 8
173
+ create_fulfillment_attributes = {
174
+ message: "The message for this FO fulfillment",
175
+ notify_customer: true,
176
+ tracking_info: {
177
+ number: "XSDFHYR23475",
178
+ url: "https://tracking.example.com/XSDFHYR23475",
179
+ company: "TFTC - the fulfillment/tracking company",
180
+ },
181
+ }
182
+ request_body = { fulfillment: create_fulfillment_attributes }
183
+ response_body = { fulfillment: create_fulfillment_attributes.merge(id: 346743624) }
184
+ fake(
185
+ "orders/#{order_id}/fulfillments",
186
+ method: :post,
187
+ request_body: ActiveSupport::JSON.encode(request_body),
188
+ body: ActiveSupport::JSON.encode(response_body)
189
+ )
190
+ fulfillment = ShopifyAPI::Fulfillment.new(create_fulfillment_attributes)
191
+ fulfillment.prefix_options[:order_id] = order_id
192
+
193
+ assert(fulfillment.save)
194
+ assert(fulfillment.is_a?(ShopifyAPI::Fulfillment))
195
+ assert(fulfillment.persisted?)
196
+ assert_equal(346743624, fulfillment.id)
197
+ end
198
+ end
199
+
200
+ context "#update_tracking" do
201
+ should "be able to update tracking info for a fulfillment" do
202
+ tracking_info = {
203
+ number: 'JSDHFHAG',
204
+ url: 'https://example.com/fulfillment_tracking/JSDHFHAG',
205
+ company: 'ACME co',
206
+ }
207
+ fake_fulfillment = ActiveSupport::JSON.decode(load_fixture('fulfillment'))['fulfillment']
208
+ fake_fulfillment['tracking_number'] = tracking_info[:number]
209
+ fake_fulfillment['tracking_numbers'] = [tracking_info[:number]]
210
+ fake_fulfillment['tracking_url'] = tracking_info[:url]
211
+ fake_fulfillment['tracking_urls'] = [tracking_info[:url]]
212
+ fake_fulfillment['tracking_company'] = tracking_info[:company]
213
+
214
+ request_body = {
215
+ fulfillment: {
216
+ tracking_info: tracking_info,
217
+ notify_customer: true,
218
+ },
219
+ }
220
+ url_prefix = url_prefix_for_activated_session_for('2020-01')
221
+ fake(
222
+ 'fulfillments',
223
+ url: "#{url_prefix}/fulfillments/#{fake_fulfillment['id']}/update_tracking.json",
224
+ method: :post,
225
+ request_body: ActiveSupport::JSON.encode(request_body),
226
+ body: ActiveSupport::JSON.encode(fulfillment: fake_fulfillment)
227
+ )
228
+ fulfillment = ShopifyAPI::Fulfillment.new(id: fake_fulfillment['id'])
229
+ assert(fulfillment.update_tracking(tracking_info: tracking_info, notify_customer: true))
230
+
231
+ assert_equal(tracking_info[:number], fulfillment.tracking_number)
232
+ assert_equal([tracking_info[:number]], fulfillment.tracking_numbers)
233
+ assert_equal(tracking_info[:url], fulfillment.tracking_url)
234
+ assert_equal([tracking_info[:url]], fulfillment.tracking_urls)
235
+ assert_equal(tracking_info[:company], fulfillment.tracking_company)
236
+ end
237
+ end
238
+ end
239
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+ require 'fulfillment_order_test_helper'
4
+
5
+ class FulfillmentV2Test < Test::Unit::TestCase
6
+ include FulfillmentOrderTestHelper
7
+
8
+ def setup
9
+ super
10
+ @tracking_info = {
11
+ number: 'JSDHFHAG',
12
+ url: 'https://example.com/fulfillment_tracking/JSDHFHAG',
13
+ company: 'ACME co',
14
+ }
15
+ @fake_fulfillment = ActiveSupport::JSON.decode(load_fixture('fulfillment'))['fulfillment']
16
+ @fake_fulfillment['tracking_number'] = @tracking_info[:number]
17
+ @fake_fulfillment['tracking_numbers'] = [@tracking_info[:number]]
18
+ @fake_fulfillment['tracking_url'] = @tracking_info[:url]
19
+ @fake_fulfillment['tracking_urls'] = [@tracking_info[:url]]
20
+ @fake_fulfillment['tracking_company'] = @tracking_info[:company]
21
+
22
+ @request_body = {
23
+ fulfillment: {
24
+ tracking_info: @tracking_info,
25
+ notify_customer: true,
26
+ },
27
+ }
28
+ @url_prefix = url_prefix_for_activated_session_for('2020-01')
29
+ fake(
30
+ 'fulfillments',
31
+ url: "#{@url_prefix}/fulfillments/#{@fake_fulfillment['id']}/update_tracking.json",
32
+ method: :post,
33
+ request_body: ActiveSupport::JSON.encode(@request_body),
34
+ body: ActiveSupport::JSON.encode(fulfillment: @fake_fulfillment)
35
+ )
36
+ end
37
+
38
+ context "FulfillmentV2" do
39
+ context "#update_tracking" do
40
+ should "be able to update tracking info for a fulfillment" do
41
+ fulfillment = ShopifyAPI::FulfillmentV2.new(id: @fake_fulfillment['id'])
42
+ assert(fulfillment.update_tracking(tracking_info: @tracking_info, notify_customer: true))
43
+
44
+ assert_equal(@tracking_info[:number], fulfillment.tracking_number)
45
+ assert_equal([@tracking_info[:number]], fulfillment.tracking_numbers)
46
+ assert_equal(@tracking_info[:url], fulfillment.tracking_url)
47
+ assert_equal([@tracking_info[:url]], fulfillment.tracking_urls)
48
+ assert_equal(@tracking_info[:company], fulfillment.tracking_company)
49
+ end
50
+
51
+ should "raise NotImplementedError when api_version is older than 2020-01" do
52
+ @url_prefix = url_prefix_for_activated_session_for('2019-10')
53
+ fake(
54
+ 'fulfillments',
55
+ url: "#{@url_prefix}/fulfillments/#{@fake_fulfillment['id']}/update_tracking.json",
56
+ method: :post,
57
+ request_body: ActiveSupport::JSON.encode(@request_body),
58
+ body: ActiveSupport::JSON.encode(fulfillment: @fake_fulfillment)
59
+ )
60
+ assert_raises(NotImplementedError) do
61
+ ShopifyAPI::FulfillmentV2.new(id: @fake_fulfillment['id'])
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class GiftCardTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+ load_gift_card
8
+ end
9
+
10
+ def test_disable
11
+ fake('gift_cards/1023670/disable.json', body: load_fixture('gift_card_disabled'), method: :post, extension: false)
12
+
13
+ refute(@gift_card.disabled_at)
14
+ @gift_card.disable
15
+ assert(@gift_card.disabled_at)
16
+ end
17
+
18
+ private
19
+
20
+ def load_gift_card
21
+ fake('gift_cards/1023670', body: load_fixture('gift_card'))
22
+ @gift_card = ShopifyAPI::GiftCard.find(1023670)
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ module GraphQL
5
+ class HTTPClientTest < Test::Unit::TestCase
6
+ test '#headers uses the Base headers' do
7
+ ShopifyAPI::Base.headers['X-Custom'] = 'abc'
8
+
9
+ client = ShopifyAPI::GraphQL::HTTPClient.new('2019-07')
10
+
11
+ assert_equal 'abc', client.headers({})['X-Custom']
12
+
13
+ ShopifyAPI::Base.headers.delete('X-Custom')
14
+ end
15
+
16
+ test '#uri uses the Base site and the API version' do
17
+ ShopifyAPI::Base.site = 'https://foo:bar@www.zombo.com'
18
+ api_version = ShopifyAPI::ApiVersion.new(handle: '2019-07')
19
+
20
+ client = ShopifyAPI::GraphQL::HTTPClient.new(api_version)
21
+ expected_uri = URI('https://foo:bar@www.zombo.com/admin/api/2019-07/graphql.json')
22
+
23
+ assert_equal expected_uri, client.uri
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,190 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+ require_relative 'fixtures/graphql/dummy_schema'
4
+
5
+ class GraphQLTest < Test::Unit::TestCase
6
+ def setup
7
+ ShopifyAPI::ApiVersion.version_lookup_mode = :define_on_unknown
8
+ @fixture_location = Pathname('test/fixtures/graphql')
9
+ @site = 'https://this-is-my-test-shop.myshopify.com'
10
+ ShopifyAPI::Base.site = @site
11
+ end
12
+
13
+ def teardown
14
+ ShopifyAPI::GraphQL.clear_clients
15
+ end
16
+
17
+ test '#initialize_clients creates a GraphQL::Client from local schema file' do
18
+ version_fixtures('unstable') do |_dir|
19
+ ShopifyAPI::GraphQL.initialize_clients
20
+
21
+ assert(ShopifyAPI::GraphQL.client('unstable'))
22
+ end
23
+ end
24
+
25
+ test '#initialize_clients handles multiple schema files' do
26
+ version_fixtures('unstable', '2019-10') do |_dir|
27
+ ShopifyAPI::GraphQL.initialize_clients
28
+
29
+ assert(ShopifyAPI::GraphQL.client('unstable'))
30
+ assert(ShopifyAPI::GraphQL.client('2019-10'))
31
+ end
32
+ end
33
+
34
+ test '#initialize_clients ignores non JSON schema files' do
35
+ version_fixtures('unstable', '2019-10') do |_dir|
36
+ FileUtils.touch(ShopifyAPI::GraphQL.schema_location.join('nope.txt'))
37
+
38
+ ShopifyAPI::GraphQL.initialize_clients
39
+
40
+ assert(ShopifyAPI::GraphQL.client('unstable'))
41
+ assert(ShopifyAPI::GraphQL.client('2019-10'))
42
+ end
43
+ end
44
+
45
+ test '#initialize_clients raises if a JSON schema file is not named after a version' do
46
+ version_fixtures do |dir|
47
+ ShopifyAPI::GraphQL.schema_location = dir
48
+ FileUtils.touch(ShopifyAPI::GraphQL.schema_location.join('nope.json'))
49
+
50
+ assert_raises(ShopifyAPI::GraphQL::InvalidSchema) do
51
+ ShopifyAPI::GraphQL.initialize_clients
52
+ end
53
+ end
54
+ end
55
+
56
+ test '#initialize_clients does not raise if raise_on_invalid_schema is set to false' do
57
+ version_fixtures('unstable') do |dir|
58
+ ShopifyAPI::GraphQL.schema_location = dir
59
+ FileUtils.touch(ShopifyAPI::GraphQL.schema_location.join('nope.json'))
60
+
61
+ ShopifyAPI::GraphQL.initialize_clients(raise_on_invalid_schema: false)
62
+
63
+ assert(ShopifyAPI::GraphQL.client('unstable'))
64
+ end
65
+ end
66
+
67
+ test '#client returns default schema if only one exists' do
68
+ version_fixtures('unstable') do |_dir|
69
+ ShopifyAPI::Base.api_version = 'unstable'
70
+
71
+ ShopifyAPI::GraphQL.initialize_clients
72
+
73
+ assert_instance_of(::GraphQL::Client, ShopifyAPI::GraphQL.client)
74
+ end
75
+ end
76
+
77
+ test '#client accepts optional api_version parameter' do
78
+ version_fixtures('unstable') do |_dir|
79
+ ShopifyAPI::Base.api_version = 'unstable'
80
+
81
+ ShopifyAPI::GraphQL.initialize_clients
82
+
83
+ assert_instance_of(::GraphQL::Client, ShopifyAPI::GraphQL.client('unstable'))
84
+ end
85
+ end
86
+
87
+ test '#client executes queries on specified API version' do
88
+ version_fixtures('unstable', '2019-10') do |_dir|
89
+ ShopifyAPI::Base.api_version = 'unstable'
90
+
91
+ ShopifyAPI::GraphQL.initialize_clients
92
+ ShopifyAPI::Base.site = 'https://this-is-my-test-shop.myshopify.com'
93
+
94
+ client = ShopifyAPI::GraphQL.client('2019-10')
95
+
96
+ assert_instance_of(::GraphQL::Client, client)
97
+
98
+ query = client.parse(<<~GRAPHQL)
99
+ {
100
+ product {
101
+ name
102
+ }
103
+ }
104
+ GRAPHQL
105
+
106
+ path = ShopifyAPI::ApiVersion.new('2019-10').construct_graphql_path
107
+ stub_request(:post, "#{@site}#{path}").to_return(body: { product: { name: 'Shirt' } }.to_json)
108
+
109
+ client.query(query)
110
+ end
111
+ end
112
+
113
+ test '#client raises exception for version that does not exist' do
114
+ version_fixtures('unstable') do |_dir|
115
+ ShopifyAPI::Base.api_version = '2019-10'
116
+
117
+ ShopifyAPI::GraphQL.initialize_clients
118
+
119
+ assert_raises(ShopifyAPI::GraphQL::InvalidClient) do
120
+ ShopifyAPI::GraphQL.client('2019-10')
121
+ end
122
+ end
123
+ end
124
+
125
+ test '#client lazily initializes clients' do
126
+ version_fixtures('unstable') do |_dir|
127
+ ShopifyAPI::Base.api_version = 'unstable'
128
+
129
+ assert_raises(ShopifyAPI::GraphQL::InvalidClient) do
130
+ ShopifyAPI::GraphQL.client('2019-10')
131
+ end
132
+ end
133
+ end
134
+
135
+ test '#client caches lookups' do
136
+ version_fixtures('unstable') do |_dir|
137
+ ShopifyAPI::Base.api_version = 'unstable'
138
+
139
+ client1 = ShopifyAPI::GraphQL.client
140
+ client2 = ShopifyAPI::GraphQL.client('unstable')
141
+
142
+ assert_equal(client1, client2)
143
+ end
144
+ end
145
+
146
+ test '#client creates execution adapter based off configured class' do
147
+ class SuperDuperExecutionAdapter < ShopifyAPI::GraphQL::HTTPClient
148
+ end
149
+
150
+ ShopifyAPI::GraphQL.execution_adapter = SuperDuperExecutionAdapter
151
+ version_fixtures('unstable') do |_dir|
152
+ ShopifyAPI::Base.api_version = 'unstable'
153
+
154
+ ShopifyAPI::GraphQL.initialize_clients
155
+ assert_instance_of(SuperDuperExecutionAdapter, ShopifyAPI::GraphQL.client('unstable').execute)
156
+ end
157
+
158
+ ShopifyAPI::GraphQL.execution_adapter = nil
159
+ end
160
+
161
+ test '#client creates client based off configured class' do
162
+ class SuperDuperClient < ::GraphQL::Client
163
+ end
164
+
165
+ ShopifyAPI::GraphQL.graphql_client = SuperDuperClient
166
+ version_fixtures('unstable') do |_dir|
167
+ ShopifyAPI::Base.api_version = 'unstable'
168
+
169
+ ShopifyAPI::GraphQL.initialize_clients
170
+
171
+ assert_instance_of(SuperDuperClient, ShopifyAPI::GraphQL.client('unstable'))
172
+ end
173
+
174
+ ShopifyAPI::GraphQL.clear_clients
175
+ ShopifyAPI::GraphQL.graphql_client = nil
176
+ end
177
+
178
+ private
179
+
180
+ def version_fixtures(*versions)
181
+ Dir.mktmpdir do |dir|
182
+ versions.each do |version|
183
+ FileUtils.cp(@fixture_location.join("#{version}.json"), dir)
184
+ end
185
+
186
+ ShopifyAPI::GraphQL.schema_location = dir
187
+ yield(dir)
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class HmacParamsTest < Test::Unit::TestCase
5
+ test "cgi param keys are prepared for hmac validation by encoding equals, ampersand, and percent characters" do
6
+ assert_equal(
7
+ "abcd%26%3D%251234",
8
+ ShopifyAPI::HmacParams.encode_key("abcd&=%1234")
9
+ )
10
+ end
11
+
12
+ test "cgi param values are prepared for hmac validation by encoding ampersand and percent characters" do
13
+ assert_equal(
14
+ "abcd%26=%251234",
15
+ ShopifyAPI::HmacParams.encode_value("abcd&=%1234")
16
+ )
17
+ end
18
+
19
+ test "cgi params are encoded properly for hmac validation" do
20
+ assert_equal(
21
+ "abcd%26%3D%251234=abcd%26=%251234",
22
+ ShopifyAPI::HmacParams.encode({"abcd&=%1234" => "abcd&=%1234"})
23
+ )
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class ImageTest < Test::Unit::TestCase
5
+ def test_create_image
6
+ fake("products/632910392/images", method: :post, body: load_fixture('image'))
7
+ image = ShopifyAPI::Image.new(product_id: 632910392)
8
+ image.position = 1
9
+ image.attachment = "R0lGODlhbgCMAPf/APbr48VySrxTO7IgKt2qmKQdJeK8lsFjROG5p/nz7Zg3MN" \
10
+ "mnd7Q1MLNVS9GId71hSJMZIuzTu4UtKbeEeakhKMl8U8WYjfr18YQaIbAf=="
11
+ image.save
12
+
13
+ assert_equal('http://cdn.shopify.com/s/files/1/0006/9093/3842/products/ipod-nano.png?v=1389388540', image.src)
14
+ assert_equal(850703190, image.id)
15
+ end
16
+
17
+ def test_get_images
18
+ fake("products/632910392/images", method: :get, body: load_fixture('images'))
19
+ image = ShopifyAPI::Image.find(:all, params: { product_id: 632910392 })
20
+ assert_equal(2, image.size)
21
+ end
22
+
23
+ def test_get_image
24
+ fake("products/632910392/images/850703190", method: :get, body: load_fixture('image'))
25
+ image = ShopifyAPI::Image.find(850703190, params: { product_id: 632910392 })
26
+ assert_equal(850703190, image.id)
27
+ end
28
+
29
+ def test_delete_image
30
+ fake("products/632910392/images/850703190", method: :get, body: load_fixture('image'))
31
+ fake("products/632910392/images/850703190", method: :delete, body: "destroyed")
32
+ image = ShopifyAPI::Image.find(850703190, params: { product_id: 632910392 })
33
+ assert(image.destroy)
34
+ end
35
+
36
+ def test_delete_image_without_fetching
37
+ fake("products/632910392/images/850703190", method: :delete, body: "destroyed")
38
+ image = ShopifyAPI::Image.new(product_id: 632910392, id: 850703190)
39
+ assert(image.destroy)
40
+ end
41
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class InventoryLevelTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+ @inventory_level_response = ActiveSupport::JSON.decode(load_fixture('inventory_level'))
8
+ @inventory_level = ShopifyAPI::InventoryLevel.new(@inventory_level_response['inventory_level'])
9
+ end
10
+
11
+ test ".find with inventory_item_ids and location_ids returns expected inventory levels" do
12
+ params = { inventory_item_ids: [808950810, 39072856], location_ids: [905684977, 487838322] }
13
+ fake(
14
+ "inventory_levels.json?#{params.to_param}",
15
+ extension: false,
16
+ method: :get,
17
+ status: 200,
18
+ body: load_fixture('inventory_levels')
19
+ )
20
+ inventory_levels = ShopifyAPI::InventoryLevel.find(:all, params: params)
21
+
22
+ assert(
23
+ inventory_levels.all? do |item|
24
+ params[:location_ids].include?(item.location_id) &&
25
+ params[:inventory_item_ids].include?(item.inventory_item_id)
26
+ end,
27
+ message: 'Response contained inventory_items or locations not requested.'
28
+ )
29
+ end
30
+
31
+ test '#adjust with adjustment value returns inventory_level with available increased by adjustment value' do
32
+ adjustment = 5
33
+ updated_available = @inventory_level.available + adjustment
34
+ @inventory_level_response[:available] = updated_available
35
+
36
+ fake('inventory_levels/adjust', method: :post, body: ActiveSupport::JSON.encode(@inventory_level_response))
37
+ @inventory_level.adjust(adjustment)
38
+ assert_equal(updated_available, @inventory_level.available)
39
+ end
40
+
41
+ test '#connect saves an inventory_level associated with inventory_item and location_id' do
42
+ params = { inventory_item_id: 808950810, location_id: 99999999 }
43
+ response = params.clone
44
+ response[:available] = 0
45
+
46
+ fake('inventory_levels/connect', method: :post, body: ActiveSupport::JSON.encode(response))
47
+ inventory_level = ShopifyAPI::InventoryLevel.new(params)
48
+ inventory_level.connect
49
+ assert_equal(0, inventory_level.available, message: 'expected newly connected location to have 0 inventory')
50
+ end
51
+
52
+ test '#destroy removes inventory_level and returns nil' do
53
+ params = { inventory_item_id: @inventory_level.inventory_item_id, location_id: @inventory_level.location_id }
54
+ fake("inventory_levels.json?#{params.to_param}", extension: false, method: :delete, status: 204, body: nil)
55
+ assert_nil(@inventory_level.destroy)
56
+ end
57
+
58
+ test '#set with available value returns inventory_level with available as the available value' do
59
+ available = 13
60
+ response = @inventory_level_response.clone
61
+ response['inventory_level']['available'] = available
62
+
63
+ fake('inventory_levels/set', method: :post, body: ActiveSupport::JSON.encode(response))
64
+ @inventory_level.set(available)
65
+
66
+ assert_equal(available, @inventory_level.available)
67
+ end
68
+ end