Sha256: 3bb62cd57f3f692a547f37f1acd4589c55bb6e0156d51a06f04ad24fa60c2403

Contents?: true

Size: 1.75 KB

Versions: 4

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'


describe "Integration" do
  subject { Shutl::Auth::AccessTokenRequest.new opts }
  let(:client_id) { "QUOTE_SERVICE_CLIENT_ID" }
  let(:url) { "http://localhost:3000" }

  let(:opts) do
    {
      client_id: client_id,
      client_secret: "QUOTE_SERVICE_CLIENT_SECRET",
      url: url
    }
  end

  context 'successful request to authentication service' do
    let(:token) { 's_CagcDP8PdsGb1B0iyLvNtanSxqZeQDQtGiIYtctKzyLzxAymhe-zGJwUrjxKQpO9EUdizDT3tqLt-iFeHapg' }

    specify do
      VCR.use_cassette 'get_token' do
        subject.access_token.should == token
      end
    end

    describe "with invalid auth service url" do
      specify do
        expect { Shutl::Auth::AccessTokenRequest.new(client_id: '', client_secret: '', url: '').access_token}.to raise_error Shutl::Auth::InvalidUrl
      end

      specify do
        expect {Shutl::Auth::AccessTokenRequest.new(client_id: '', client_secret: '', url: 'http://').access_token}.to raise_error Shutl::Auth::InvalidUrl
      end
    end

    specify "with 500 from auth server" do
      stub_request(:post, /.*#{url}.*/).to_return(
        { body: '',
           status: 500,
           headers: {"CONTENT_TYPE" => 'application/json'}}
        )

      Airbrake.should_receive(:notify)

      expect{ subject.access_token}.to raise_error Shutl::Auth::InternalServerError
    end

    describe "with invalid credentials" do
      let(:client_id) { 'egg' }

      specify do
        VCR.use_cassette 'invalid_credentials' do
          expect { subject.access_token}.to raise_error Shutl::Auth::InvalidCredentials
        end

        VCR.use_cassette 'invalid_credentials' do
          expect { subject.access_token}.to raise_error Shutl::Auth::InvalidCredentials
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shutl_auth-0.9.3 spec/integration/integration_spec.rb
shutl_auth-0.9.2 spec/integration/integration_spec.rb
shutl_auth-0.9.1 spec/integration/integration_spec.rb
shutl_auth-0.9.0 spec/integration/integration_spec.rb