Sha256: 477d6c02c5d6900594cbb9d4c24ba72ca76d4b8ffda2a9924a9191163f310b49

Contents?: true

Size: 1.38 KB

Versions: 9

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true
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

9 entries across 9 versions & 2 rubygems

Version Path
shopify_api-9.5.2 test/message_enricher_test.rb
ruby_shopify_api-1.2.0 test/message_enricher_test.rb
ruby_shopify_api-1.1.0 test/message_enricher_test.rb
ruby_shopify_api-1.0.0 test/message_enricher_test.rb
shopify_api-9.5.1 test/message_enricher_test.rb
shopify_api-9.5 test/message_enricher_test.rb
shopify_api-9.4.1 test/message_enricher_test.rb
shopify_api-9.4.0 test/message_enricher_test.rb
shopify_api-9.3.0 test/message_enricher_test.rb