fulfillment_v2_test.rb 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # frozen_string_literal: true
  2. require 'test_helper'
  3. require 'fulfillment_order_test_helper'
  4. class FulfillmentV2Test < Test::Unit::TestCase
  5. include FulfillmentOrderTestHelper
  6. def setup
  7. super
  8. @tracking_info = {
  9. number: 'JSDHFHAG',
  10. url: 'https://example.com/fulfillment_tracking/JSDHFHAG',
  11. company: 'ACME co',
  12. }
  13. @fake_fulfillment = ActiveSupport::JSON.decode(load_fixture('fulfillment'))['fulfillment']
  14. @fake_fulfillment['tracking_number'] = @tracking_info[:number]
  15. @fake_fulfillment['tracking_numbers'] = [@tracking_info[:number]]
  16. @fake_fulfillment['tracking_url'] = @tracking_info[:url]
  17. @fake_fulfillment['tracking_urls'] = [@tracking_info[:url]]
  18. @fake_fulfillment['tracking_company'] = @tracking_info[:company]
  19. @request_body = {
  20. fulfillment: {
  21. tracking_info: @tracking_info,
  22. notify_customer: true,
  23. },
  24. }
  25. @url_prefix = url_prefix_for_activated_session_for('2020-01')
  26. fake(
  27. 'fulfillments',
  28. url: "#{@url_prefix}/fulfillments/#{@fake_fulfillment['id']}/update_tracking.json",
  29. method: :post,
  30. request_body: ActiveSupport::JSON.encode(@request_body),
  31. body: ActiveSupport::JSON.encode(fulfillment: @fake_fulfillment)
  32. )
  33. end
  34. context "FulfillmentV2" do
  35. context "#update_tracking" do
  36. should "be able to update tracking info for a fulfillment" do
  37. fulfillment = ShopifyAPI::FulfillmentV2.new(id: @fake_fulfillment['id'])
  38. assert(fulfillment.update_tracking(tracking_info: @tracking_info, notify_customer: true))
  39. assert_equal(@tracking_info[:number], fulfillment.tracking_number)
  40. assert_equal([@tracking_info[:number]], fulfillment.tracking_numbers)
  41. assert_equal(@tracking_info[:url], fulfillment.tracking_url)
  42. assert_equal([@tracking_info[:url]], fulfillment.tracking_urls)
  43. assert_equal(@tracking_info[:company], fulfillment.tracking_company)
  44. end
  45. should "raise NotImplementedError when api_version is older than 2020-01" do
  46. @url_prefix = url_prefix_for_activated_session_for('2019-10')
  47. fake(
  48. 'fulfillments',
  49. url: "#{@url_prefix}/fulfillments/#{@fake_fulfillment['id']}/update_tracking.json",
  50. method: :post,
  51. request_body: ActiveSupport::JSON.encode(@request_body),
  52. body: ActiveSupport::JSON.encode(fulfillment: @fake_fulfillment)
  53. )
  54. assert_raises(NotImplementedError) do
  55. ShopifyAPI::FulfillmentV2.new(id: @fake_fulfillment['id'])
  56. end
  57. end
  58. end
  59. end
  60. end