BigW Consortium Gitlab

connection_spec.rb 978 Bytes
Newer Older
1 2 3
require 'spec_helper'

describe Bitbucket::Connection do
Valery Sizov committed
4 5 6 7
  before do
    allow_any_instance_of(described_class).to receive(:provider).and_return(double(app_id: '', app_secret: ''))
  end

8 9 10
  describe '#get' do
    it 'calls OAuth2::AccessToken::get' do
      expect_any_instance_of(OAuth2::AccessToken).to receive(:get).and_return(double(parsed: true))
11

12
      connection = described_class.new({})
13

14 15 16 17 18 19 20
      connection.get('/users')
    end
  end

  describe '#expired?' do
    it 'calls connection.expired?' do
      expect_any_instance_of(OAuth2::AccessToken).to receive(:expired?).and_return(true)
21

22 23 24 25 26 27 28
      expect(described_class.new({}).expired?).to be_truthy
    end
  end

  describe '#refresh!' do
    it 'calls connection.refresh!' do
      response = double(token: nil, expires_at: nil, expires_in: nil, refresh_token: nil)
29

30
      expect_any_instance_of(OAuth2::AccessToken).to receive(:refresh!).and_return(response)
31

32 33 34 35
      described_class.new({}).refresh!
    end
  end
end