debian-mirror-gitlab/qa/spec/runtime/api/client_spec.rb

72 lines
2.2 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2021-01-03 14:25:43 +05:30
RSpec.describe QA::Runtime::API::Client do
2021-11-11 11:23:49 +05:30
include QA::Support::Helpers::StubEnv
2018-03-17 18:26:18 +05:30
describe 'initialization' do
it 'defaults to :gitlab address' do
expect(described_class.new.address).to eq :gitlab
end
it 'uses specified address' do
client = described_class.new('http:///example.com')
expect(client.address).to eq 'http:///example.com'
end
end
2018-12-13 13:39:08 +05:30
describe '#personal_access_token' do
2019-09-30 21:07:59 +05:30
context 'when user is nil and QA::Runtime::Env.personal_access_token is present' do
2018-12-13 13:39:08 +05:30
before do
allow(QA::Runtime::Env).to receive(:personal_access_token).and_return('a_token')
end
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
it 'returns specified token from env' do
2019-09-30 21:07:59 +05:30
expect(subject.personal_access_token).to eq 'a_token'
2018-12-13 13:39:08 +05:30
end
2018-03-17 18:26:18 +05:30
end
2019-09-30 21:07:59 +05:30
context 'when user is present and QA::Runtime::Env.personal_access_token is nil' do
2018-12-13 13:39:08 +05:30
before do
allow(QA::Runtime::Env).to receive(:personal_access_token).and_return(nil)
end
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
it 'returns a created token' do
2019-09-30 21:07:59 +05:30
subject { described_class.new(user: { username: 'foo' }) }
2018-12-13 13:39:08 +05:30
expect(subject).to receive(:create_personal_access_token).and_return('created_token')
expect(subject.personal_access_token).to eq 'created_token'
end
2018-03-17 18:26:18 +05:30
end
2019-09-30 21:07:59 +05:30
context 'when user is nil and QA::Runtime::Env.personal_access_token is nil' do
before do
allow(QA::Runtime::Env).to receive(:personal_access_token).and_return(nil)
end
it 'returns a created token' do
client = described_class.new
expect(client).to receive(:create_personal_access_token).and_return('created_token')
expect(client.personal_access_token).to eq 'created_token'
end
end
context 'when user is present and QA::Runtime::Env.personal_access_token is present' do
before do
allow(QA::Runtime::Env).to receive(:personal_access_token).and_return('a_token')
end
it 'returns a created token' do
2021-04-17 20:07:23 +05:30
client = described_class.new(user: Struct.new(:username, :admin?).new('foo', false))
2019-09-30 21:07:59 +05:30
expect(client).to receive(:create_personal_access_token).and_return('created_token')
expect(client.personal_access_token).to eq 'created_token'
end
end
2018-03-17 18:26:18 +05:30
end
end