assigned_fulfillment_order_test.rb 2.9 KB

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