debian-mirror-gitlab/spec/lib/bitbucket/connection_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.3 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Bitbucket::Connection do
2022-11-25 23:54:43 +05:30
let(:token) { 'token' }
2017-08-17 22:00:37 +05:30
before do
2020-01-01 13:55:28 +05:30
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:provider).and_return(double(app_id: '', app_secret: ''))
end
2017-08-17 22:00:37 +05:30
end
describe '#get' do
it 'calls OAuth2::AccessToken::get' do
2020-01-01 13:55:28 +05:30
expect_next_instance_of(OAuth2::AccessToken) do |instance|
expect(instance).to receive(:get).and_return(double(parsed: true))
end
2017-08-17 22:00:37 +05:30
2022-11-25 23:54:43 +05:30
connection = described_class.new({ token: token })
2017-08-17 22:00:37 +05:30
connection.get('/users')
end
end
describe '#expired?' do
it 'calls connection.expired?' do
2020-01-01 13:55:28 +05:30
expect_next_instance_of(OAuth2::AccessToken) do |instance|
expect(instance).to receive(:expired?).and_return(true)
end
2017-08-17 22:00:37 +05:30
2022-11-25 23:54:43 +05:30
expect(described_class.new({ token: token }).expired?).to be_truthy
2017-08-17 22:00:37 +05:30
end
end
describe '#refresh!' do
it 'calls connection.refresh!' do
2022-11-25 23:54:43 +05:30
response = double(token: token, expires_at: nil, expires_in: nil, refresh_token: nil)
2017-08-17 22:00:37 +05:30
2020-01-01 13:55:28 +05:30
expect_next_instance_of(OAuth2::AccessToken) do |instance|
expect(instance).to receive(:refresh!).and_return(response)
end
2017-08-17 22:00:37 +05:30
2022-11-25 23:54:43 +05:30
described_class.new({ token: token }).refresh!
2017-08-17 22:00:37 +05:30
end
end
end