2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-12 09:16:51 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Bitbucket::Connection do
|
2016-12-14 13:19:26 -05:00
|
|
|
before do
|
2019-11-20 01:06:16 -05:00
|
|
|
allow_next_instance_of(described_class) do |instance|
|
|
|
|
allow(instance).to receive(:provider).and_return(double(app_id: '', app_secret: ''))
|
|
|
|
end
|
2016-12-14 13:19:26 -05:00
|
|
|
end
|
|
|
|
|
2016-12-12 09:16:51 -05:00
|
|
|
describe '#get' do
|
|
|
|
it 'calls OAuth2::AccessToken::get' do
|
2019-11-20 01:06:16 -05:00
|
|
|
expect_next_instance_of(OAuth2::AccessToken) do |instance|
|
|
|
|
expect(instance).to receive(:get).and_return(double(parsed: true))
|
|
|
|
end
|
2016-12-13 10:59:21 -05:00
|
|
|
|
2016-12-12 09:16:51 -05:00
|
|
|
connection = described_class.new({})
|
2016-12-13 10:59:21 -05:00
|
|
|
|
2016-12-12 09:16:51 -05:00
|
|
|
connection.get('/users')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#expired?' do
|
|
|
|
it 'calls connection.expired?' do
|
2019-11-20 01:06:16 -05:00
|
|
|
expect_next_instance_of(OAuth2::AccessToken) do |instance|
|
|
|
|
expect(instance).to receive(:expired?).and_return(true)
|
|
|
|
end
|
2016-12-13 10:59:21 -05:00
|
|
|
|
2016-12-12 09:16:51 -05:00
|
|
|
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)
|
2016-12-13 10:59:21 -05:00
|
|
|
|
2019-11-20 01:06:16 -05:00
|
|
|
expect_next_instance_of(OAuth2::AccessToken) do |instance|
|
|
|
|
expect(instance).to receive(:refresh!).and_return(response)
|
|
|
|
end
|
2016-12-13 10:59:21 -05:00
|
|
|
|
2016-12-12 09:16:51 -05:00
|
|
|
described_class.new({}).refresh!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|