Sha256: d63becd2075644669c8b000adb78abec11c26f84620f0f152d5f0e59ddc57224

Contents?: true

Size: 1.44 KB

Versions: 19

Compression:

Stored size: 1.44 KB

Contents

# -*- coding: utf-8 -*-
require File.expand_path('../../test_helper', __FILE__)

module Checkr
  class StatusCodesTest < Test::Unit::TestCase

    context 'AuthenticationError' do
      should 'be raised with no API credentials' do
        Checkr.api_key = nil
        assert_raises(AuthenticationError) do
          MockResource.retrieve('fake_id')
        end
      end

      should 'be raised with invalid credentials' do
        Checkr.api_key = 'invalid api key' # spaces aren't valid
        assert_raises(AuthenticationError) do
          MockResource.new('fake_id').refresh
        end
      end

      context 'that has been raised' do
        setup do
          Checkr.api_key = 'invalid'
          response = test_response(test_invalid_api_key_error, 401)
          begin
            @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
            MockResource.retrieve('failing')
          rescue AuthenticationError => e
            @error = e
          end
        end

        should 'have an http status of 401' do
          assert_equal(401, @error.http_status)
        end

        should 'have an http body' do
          assert(!!@error.http_body)
        end

        should 'have a JSON body with an error message' do
          assert(!!@error.json_body[:error][:message])
          assert_equal(test_invalid_api_key_error[:error][:message], @error.json_body[:error][:message])
        end
      end
    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
checkr-official-1.8.0 test/checkr/authentication_test.rb
checkr-official-1.7.1 test/checkr/authentication_test.rb
checkr-official-1.7 test/checkr/authentication_test.rb
checkr-official-1.6 test/checkr/authentication_test.rb
checkr-official-1.5.4 test/checkr/authentication_test.rb
checkr-official-1.5.3 test/checkr/authentication_test.rb
checkr-official-1.5.2 test/checkr/authentication_test.rb
checkr-official-1.5.1 test/checkr/authentication_test.rb
checkr-official-1.5.0 test/checkr/authentication_test.rb
checkr-official-1.4.0 test/checkr/authentication_test.rb
checkr-official-1.3.1 test/checkr/authentication_test.rb
checkr-official-1.2.1 test/checkr/authentication_test.rb
checkr-official-1.2.0 test/checkr/authentication_test.rb
checkr-official-1.1.2 test/checkr/authentication_test.rb
checkr-official-1.1.1 test/checkr/authentication_test.rb
checkr-official-1.1.0 test/checkr/authentication_test.rb
checkr-official-1.0.2 test/checkr/authentication_test.rb
checkr-official-1.0.1 test/checkr/authentication_test.rb
checkr-official-1.0.0 test/checkr/authentication_test.rb