Sha256: 5f74f6d7e6660fada6fb1759dbd516c278e4b9d0ace38c80e26c434009f08034

Contents?: true

Size: 1.62 KB

Versions: 15

Compression:

Stored size: 1.62 KB

Contents

require 'hyperion'

describe ClientErrorResponse do
  describe '::from_attrs' do
    it 'creates a ClientErrorResponse from a hash' do
      hash = {
          'message' => 'oops',
          'code' => 'missing',
          'errors' => [ make_error_attrs('assay') ],
          'content' => 'stuff'
      }
      result = ClientErrorResponse.from_attrs(hash)
      expect(result.message).to eql 'oops'
      expect(result.code).to eql ClientErrorCode::MISSING
      expect(result.content).to eql 'stuff'
      expect(result.errors.size).to eql 1
      error = result.errors.first
      expect(error.code).to eql ClientErrorCode::MISSING
      expect(error.resource).to eql 'assay'
      expect(error.field).to eql 'name'
      expect(error.value).to eql 'foo'
      expect(error.reason).to eql 'because'
    end
  end

  describe '::as_json' do
    it 'converts to a hash' do
      errors = [ ClientErrorDetail.new(ClientErrorCode::MISSING, 'x'),
                 ClientErrorDetail.new(ClientErrorCode::INVALID, 'x') ]
      err = ClientErrorResponse.new('oops', errors, ClientErrorCode::INVALID, 'the_content')
      result = err.as_json
      expect(result['message']).to eql 'oops'
      expect(result['code']).to eql 'invalid'
      expect(result['content']).to eql 'the_content'
      expect(result['errors'].map(&['code'])).to eql %w(missing invalid)
    end
  end

  def make_error(resource)
    ClientErrorDetail.from_attrs(make_error_attrs(resource))
  end

  def make_error_attrs(resource)
    {
        'code' => 'missing',
        'resource' => resource,
        'field' => 'name',
        'value' => 'foo',
        'reason' => 'because'
    }
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
hyperion_http-0.6.0 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.5.0 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.3.0 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.2.4 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.2.3 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.2.2 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.2.1 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.1.9 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.1.8 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.1.7 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.1.6 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.1.5 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.1.4 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.1.3 spec/lib/hyperion/types/client_error_response_spec.rb
hyperion_http-0.1.2 spec/lib/hyperion/types/client_error_response_spec.rb