Sha256: 03d3263e0108d1a50fa505d10d079c39cf4e222edf4a16d0811f415231386078

Contents?: true

Size: 1.32 KB

Versions: 10

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

describe BrowseEverything::Auth::Google::Credentials do
  subject(:credentials) { described_class.new }

  describe '#fetch_access_token' do
    let(:response) { double }

    before do
      WebMock.disable!

      allow(response).to receive(:status_code).and_return('200')
      allow(response).to receive(:body).and_return('{}')
      allow(response).to receive(:header).and_return(content_type: 'application/json')

      connection = instance_double(Faraday::Connection)
      allow(connection).to receive(:post).and_return(response)
      faraday = class_double('Faraday').as_stubbed_const(transfer_nested_constants: true)
      allow(faraday).to receive(:default_connection).and_return(connection)
    end

    context 'when an access has already been retrieved' do
      before do
        credentials.access_token = 'test-token'
      end

      it 'generates a Hash if an access token has already been set' do
        expect(credentials.fetch_access_token).to be_a Hash
        expect(credentials.fetch_access_token).to include('access_token' => 'test-token')
      end
    end

    it 'requests a new token from the OAuth provider' do
      expect(credentials.fetch_access_token).to be_a Hash
      expect(credentials.fetch_access_token).to eq({})
    end

    after do
      WebMock.enable!
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
browse-everything-1.2.0 spec/lib/browse_everything/auth/google/credentials_spec.rb
browse-everything-1.1.2 spec/lib/browse_everything/auth/google/credentials_spec.rb
browse-everything-1.1.1 spec/lib/browse_everything/auth/google/credentials_spec.rb
browse-everything-1.1.0 spec/lib/browse_everything/auth/google/credentials_spec.rb
browse-everything-1.0.2 spec/lib/browse_everything/auth/google/credentials_spec.rb
browse-everything-1.0.1 spec/lib/browse_everything/auth/google/credentials_spec.rb
browse-everything-1.0.0 spec/lib/browse_everything/auth/google/credentials_spec.rb
browse-everything-1.0.0.rc2 spec/lib/browse_everything/auth/google/credentials_spec.rb
browse-everything-1.0.0.rc1 spec/lib/browse_everything/auth/google/credentials_spec.rb
browse-everything-0.16.1 spec/lib/browse_everything/auth/google/credentials_spec.rb