Sha256: e12ad4311f140800f859dfb0e6abd41f90cb74905332577279bde65844b6d2e3

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true
require 'spec_helper'
require 'drillbit/responses/invalid_token'

# rubocop:disable Metrics/LineLength
module          Drillbit
module          Responses
RSpec.describe  InvalidToken, singletons: Erratum::Configuration do
  it 'returns the proper response' do
    Erratum.configuration.url_mappings = {
      'external_documentation_urls'  => {
        'errors.responses.invalid_token' => 'http://example.com/foo',
      },
      'developer_documentation_urls' => {
        'errors.responses.invalid_token' => 'http://example.com/foo',
      },
    }

    request                   = { 'HTTP_HOST' => 'api.example.com' }
    status, headers, response = InvalidToken.call(request, application_name: 'my_app')

    expect(status).to                 eql 401
    expect(headers).to                eql('WWW-Authenticate' => 'Token realm="my_app"')
    expect(JSON.load(response[0])).to include(
      'errors' => [
                    include(
                      'id'     => match(/[a-f0-9\-]+/),
                      'links'  => {
                        'about'         => nil,
                        'documentation' => nil,
                      },
                      'status' => 401,
                      'code'   => 'errors.invalid_token',
                      'title'  => 'Invalid or Unauthorized Token',
                      'detail' => 'Either the token you passed is invalid or is not allowed to ' \
                                  'perform this action.',
                      'source' => {},
                    ),
                  ],
    )
  end
end
end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
drillbit-1.1.0 spec/drillbit/invalid_token_spec.rb
drillbit-1.0.1 spec/drillbit/invalid_token_spec.rb
drillbit-1.0.0 spec/drillbit/invalid_token_spec.rb
drillbit-0.0.1 spec/drillbit/invalid_token_spec.rb