2019-10-25 05:06:06 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-20 08:37:37 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe Ci::TriggerPresenter do
|
2020-02-16 22:09:00 -05:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
2018-12-20 08:37:37 -05:00
|
|
|
|
2020-02-16 22:09:00 -05:00
|
|
|
let_it_be(:trigger) do
|
2018-12-20 08:37:37 -05:00
|
|
|
create(:ci_trigger, token: '123456789abcd', project: project)
|
|
|
|
end
|
|
|
|
|
2019-01-03 04:54:05 -05:00
|
|
|
subject do
|
2018-12-20 08:37:37 -05:00
|
|
|
described_class.new(trigger, current_user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not a trigger owner' do
|
|
|
|
describe '#token' do
|
|
|
|
it 'exposes only short token' do
|
|
|
|
expect(subject.token).not_to eq trigger.token
|
|
|
|
expect(subject.token).to eq '1234'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#has_token_exposed?' do
|
|
|
|
it 'does not have token exposed' do
|
|
|
|
expect(subject).not_to have_token_exposed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is a trigger owner and builds admin' do
|
|
|
|
before do
|
|
|
|
trigger.update(owner: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#token' do
|
|
|
|
it 'exposes full token' do
|
|
|
|
expect(subject.token).to eq trigger.token
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#has_token_exposed?' do
|
|
|
|
it 'has token exposed' do
|
|
|
|
expect(subject).to have_token_exposed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|