assigned_fulfillment_order_test.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # frozen_string_literal: true
  2. require 'test_helper'
  3. require 'fulfillment_order_test_helper'
  4. class AssignedFulFillmentOrderTest < Test::Unit::TestCase
  5. include FulfillmentOrderTestHelper
  6. def setup
  7. super
  8. @url_prefix = url_prefix_for_activated_session_for('2020-01')
  9. @fulfillment_order_fixture = load_fixture('assigned_fulfillment_orders')
  10. end
  11. context "AssignedFulfillmentOrder" do
  12. context ".new" do
  13. should "raise NotImplementedError when api_version is older than 2020-01" do
  14. url_prefix_for_activated_session_for('2019-10')
  15. assert_raises(NotImplementedError) do
  16. ShopifyAPI::AssignedFulfillmentOrder.new(ActiveSupport::JSON.decode(@fulfillment_order_fixture))
  17. end
  18. end
  19. end
  20. context "#all" do
  21. should "raise NotImplementedError when api_version is older than 2020-01" do
  22. @url_prefix = url_prefix_for_activated_session_for('2019-10')
  23. fake 'assigned_fulfillment_orders',
  24. url: "#{@url_prefix}/assigned_fulfillment_orders.json",
  25. method: :get,
  26. body: @fulfillment_order_fixture,
  27. extension: false
  28. assert_raises(NotImplementedError) do
  29. ShopifyAPI::AssignedFulfillmentOrder.all(params: { assigned_status: 'cancellation_requested' })
  30. end
  31. end
  32. should "list assigned fulfillment orders by assigned_status" do
  33. fake 'assigned_fulfillment_orders',
  34. url: "#{@url_prefix}/assigned_fulfillment_orders.json?assigned_status=cancellation_requested",
  35. method: :get,
  36. body: @fulfillment_order_fixture,
  37. extension: false
  38. assigned_fulfillment_orders = ShopifyAPI::AssignedFulfillmentOrder.all(
  39. params: { assigned_status: 'cancellation_requested' }
  40. )
  41. assert_equal 2, assigned_fulfillment_orders.count
  42. assigned_fulfillment_orders.each do |fulfillment_order|
  43. assert fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder)
  44. assert_equal 'in_progress', fulfillment_order.status
  45. assert_equal 'cancellation_accepted', fulfillment_order.request_status
  46. end
  47. end
  48. should "be able to list assigned fulfillment orders by location_ids" do
  49. assigned_location_id = 905684977
  50. fake 'assigned_fulfillment_orders',
  51. url: "#{@url_prefix}/assigned_fulfillment_orders.json?location_ids%5B%5D=#{assigned_location_id}",
  52. method: :get,
  53. body: @fulfillment_order_fixture, extension: false
  54. assigned_fulfillment_orders = ShopifyAPI::AssignedFulfillmentOrder.all(
  55. params: { location_ids: [assigned_location_id] }
  56. )
  57. assert_equal 2, assigned_fulfillment_orders.count
  58. assigned_fulfillment_orders.each do |fulfillment_order|
  59. assert fulfillment_order.is_a?(ShopifyAPI::FulfillmentOrder)
  60. assert_equal assigned_location_id, fulfillment_order.assigned_location_id
  61. end
  62. end
  63. end
  64. end
  65. end