Sha256: 22fe1a8f03b29e0a79a56679bd407215735e37643a48a592b74c29946d40d871

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

require 'test_helper'

class MessageEnricherTest < Test::Unit::TestCase

  def test_enriches_initial_message_when_body_contains_error
    response = enriched_response(422, 'InitialMessage', { error: 'My Error' })

    assert_equal 'InitialMessage (My Error)', response.message
  end

  def test_enriches_initial_message_when_body_contains_errors_array
    response = enriched_response(422, 'InitialMessage', { errors: ['My Error1', 'My Error2'] })

    assert_equal 'InitialMessage (My Error1; My Error2)', response.message
  end

  def test_enriches_initial_message_when_body_contains_errors_single_value
    response = enriched_response(422, 'InitialMessage', { errors: 'My Error1' })

    assert_equal 'InitialMessage (My Error1)', 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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shopify_api-9.2.0 test/message_enricher_test.rb
shopify_api-9.1.0 test/message_enricher_test.rb
shopify_api-9.0.4 test/message_enricher_test.rb
shopify_api-9.0.3 test/message_enricher_test.rb
shopify_api-9.0.2 test/message_enricher_test.rb
shopify_api-9.0.1 test/message_enricher_test.rb