|
@@ -0,0 +1,33 @@
|
|
|
+require 'test_helper'
|
|
|
+
|
|
|
+class MessageEnricherTest < Test::Unit::TestCase
|
|
|
+
|
|
|
+ def test_enriches_initial_message_when_body_is_passed
|
|
|
+ response = enriched_response(422, 'InitialMessage', { error: 'My Error' })
|
|
|
+
|
|
|
+ assert_equal 'InitialMessage (My Error)', response.message
|
|
|
+ end
|
|
|
+
|
|
|
+ def test_returns_initial_message_when_code_is_200
|
|
|
+ response = enriched_response(200, 'InitialMessage', { result: 'Success' })
|
|
|
+
|
|
|
+ assert_equal 'InitialMessage', response.message
|
|
|
+ end
|
|
|
+
|
|
|
+ def test_returns_initial_message_when_body_cant_be_parsed
|
|
|
+ response = enriched_response(422, 'InitialMessage', 'not a json')
|
|
|
+
|
|
|
+ assert_equal 'InitialMessage', response.message
|
|
|
+ end
|
|
|
+
|
|
|
+ private
|
|
|
+
|
|
|
+ def enriched_response(code, message, body)
|
|
|
+ mock_response =
|
|
|
+ Struct
|
|
|
+ .new(:code, :message, :body)
|
|
|
+ .new(code.to_s, message.to_s, body.to_json)
|
|
|
+
|
|
|
+ ShopifyAPI::MessageEnricher.new(mock_response)
|
|
|
+ end
|
|
|
+end
|