message_enricher_test.rb 900 B

123456789101112131415161718192021222324252627282930313233
  1. require 'test_helper'
  2. class MessageEnricherTest < Test::Unit::TestCase
  3. def test_enriches_initial_message_when_body_is_passed
  4. response = enriched_response(422, 'InitialMessage', { error: 'My Error' })
  5. assert_equal 'InitialMessage (My Error)', response.message
  6. end
  7. def test_returns_initial_message_when_code_is_200
  8. response = enriched_response(200, 'InitialMessage', { result: 'Success' })
  9. assert_equal 'InitialMessage', response.message
  10. end
  11. def test_returns_initial_message_when_body_cant_be_parsed
  12. response = enriched_response(422, 'InitialMessage', 'not a json')
  13. assert_equal 'InitialMessage', response.message
  14. end
  15. private
  16. def enriched_response(code, message, body)
  17. mock_response =
  18. Struct
  19. .new(:code, :message, :body)
  20. .new(code.to_s, message.to_s, body.to_json)
  21. ShopifyAPI::MessageEnricher.new(mock_response)
  22. end
  23. end