2019-03-06 11:00:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-05-29 10:38:26 -04:00
|
|
|
require 'fast_spec_helper'
|
|
|
|
|
2019-10-16 05:07:51 -04:00
|
|
|
require 'rspec-parameterized'
|
|
|
|
|
2019-05-29 10:38:26 -04:00
|
|
|
require 'gitlab/danger/teammate'
|
|
|
|
|
2019-03-06 11:00:27 -05:00
|
|
|
describe Gitlab::Danger::Teammate do
|
2019-10-16 05:07:51 -04:00
|
|
|
subject { described_class.new(options.stringify_keys) }
|
|
|
|
let(:options) { { username: 'luigi', projects: projects, role: role } }
|
2019-03-06 11:00:27 -05:00
|
|
|
let(:projects) { { project => capabilities } }
|
2019-05-23 14:07:59 -04:00
|
|
|
let(:role) { 'Engineer, Manage' }
|
|
|
|
let(:labels) { [] }
|
2019-03-06 11:00:27 -05:00
|
|
|
let(:project) { double }
|
|
|
|
|
2019-05-23 14:07:59 -04:00
|
|
|
context 'when having multiple capabilities' do
|
|
|
|
let(:capabilities) { ['reviewer backend', 'maintainer frontend', 'trainee_maintainer qa'] }
|
2019-03-06 11:00:27 -05:00
|
|
|
|
|
|
|
it '#reviewer? supports multiple roles per project' do
|
2019-05-23 14:07:59 -04:00
|
|
|
expect(subject.reviewer?(project, :backend, labels)).to be_truthy
|
2019-03-06 11:00:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it '#traintainer? supports multiple roles per project' do
|
2019-05-23 14:07:59 -04:00
|
|
|
expect(subject.traintainer?(project, :qa, labels)).to be_truthy
|
2019-03-06 11:00:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it '#maintainer? supports multiple roles per project' do
|
2019-05-23 14:07:59 -04:00
|
|
|
expect(subject.maintainer?(project, :frontend, labels)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when labels contain Create and the category is test' do
|
2019-08-27 06:16:44 -04:00
|
|
|
let(:labels) { ['devops::create'] }
|
2019-05-23 14:07:59 -04:00
|
|
|
|
|
|
|
context 'when role is Test Automation Engineer, Create' do
|
|
|
|
let(:role) { 'Test Automation Engineer, Create' }
|
|
|
|
|
|
|
|
it '#reviewer? returns true' do
|
|
|
|
expect(subject.reviewer?(project, :test, labels)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it '#maintainer? returns false' do
|
|
|
|
expect(subject.maintainer?(project, :test, labels)).to be_falsey
|
|
|
|
end
|
2019-07-30 10:29:02 -04:00
|
|
|
|
|
|
|
context 'when hyperlink is mangled in the role' do
|
|
|
|
let(:role) { '<a href="#">Test Automation Engineer</a>, Create' }
|
|
|
|
|
|
|
|
it '#reviewer? returns true' do
|
|
|
|
expect(subject.reviewer?(project, :test, labels)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
2019-05-23 14:07:59 -04:00
|
|
|
end
|
|
|
|
|
2019-08-27 13:13:55 -04:00
|
|
|
context 'when role is Test Automation Engineer' do
|
|
|
|
let(:role) { 'Test Automation Engineer' }
|
|
|
|
|
|
|
|
it '#reviewer? returns false' do
|
|
|
|
expect(subject.reviewer?(project, :test, labels)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-23 14:07:59 -04:00
|
|
|
context 'when role is Test Automation Engineer, Manage' do
|
|
|
|
let(:role) { 'Test Automation Engineer, Manage' }
|
|
|
|
|
|
|
|
it '#reviewer? returns false' do
|
|
|
|
expect(subject.reviewer?(project, :test, labels)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
2019-09-03 18:02:55 -04:00
|
|
|
|
|
|
|
context 'when role is Backend Engineer, Engineering Productivity' do
|
|
|
|
let(:role) { 'Backend Engineer, Engineering Productivity' }
|
|
|
|
|
|
|
|
it '#reviewer? returns true' do
|
|
|
|
expect(subject.reviewer?(project, :engineering_productivity, labels)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it '#maintainer? returns false' do
|
|
|
|
expect(subject.maintainer?(project, :engineering_productivity, labels)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
2019-03-06 11:00:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-23 14:07:59 -04:00
|
|
|
context 'when having single capability' do
|
2019-03-06 11:00:27 -05:00
|
|
|
let(:capabilities) { 'reviewer backend' }
|
|
|
|
|
|
|
|
it '#reviewer? supports one role per project' do
|
2019-05-23 14:07:59 -04:00
|
|
|
expect(subject.reviewer?(project, :backend, labels)).to be_truthy
|
2019-03-06 11:00:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it '#traintainer? supports one role per project' do
|
2019-05-23 14:07:59 -04:00
|
|
|
expect(subject.traintainer?(project, :database, labels)).to be_falsey
|
2019-03-06 11:00:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it '#maintainer? supports one role per project' do
|
2019-05-23 14:07:59 -04:00
|
|
|
expect(subject.maintainer?(project, :frontend, labels)).to be_falsey
|
2019-03-06 11:00:27 -05:00
|
|
|
end
|
|
|
|
end
|
2019-10-16 05:07:51 -04:00
|
|
|
|
|
|
|
describe '#status' do
|
|
|
|
let(:capabilities) { ['dish washing'] }
|
|
|
|
|
|
|
|
context 'with empty cache' do
|
|
|
|
context 'for successful request' do
|
|
|
|
it 'returns the response' do
|
|
|
|
mock_status = double(does_not: 'matter')
|
|
|
|
expect(Gitlab::Danger::RequestHelper).to receive(:http_get_json)
|
|
|
|
.and_return(mock_status)
|
|
|
|
|
|
|
|
expect(subject.status).to be mock_status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for failing request' do
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(Gitlab::Danger::RequestHelper).to receive(:http_get_json)
|
|
|
|
.and_raise(Gitlab::Danger::RequestHelper::HTTPError.new)
|
|
|
|
|
|
|
|
expect(subject.status).to be nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with filled cache' do
|
|
|
|
it 'returns the cached response' do
|
|
|
|
mock_status = double(does_not: 'matter')
|
|
|
|
expect(Gitlab::Danger::RequestHelper).to receive(:http_get_json)
|
|
|
|
.and_return(mock_status)
|
|
|
|
subject.status
|
|
|
|
|
|
|
|
expect(Gitlab::Danger::RequestHelper).not_to receive(:http_get_json)
|
|
|
|
expect(subject.status).to be mock_status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#out_of_office?' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
let(:capabilities) { ['dry head'] }
|
|
|
|
|
|
|
|
where(:status, :result) do
|
|
|
|
nil | false
|
|
|
|
{} | false
|
|
|
|
{ message: 'dear reader' } | false
|
|
|
|
{ message: 'OOO: massage' } | true
|
|
|
|
{ message: 'love it SOOO much' } | true
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
before do
|
|
|
|
expect(Gitlab::Danger::RequestHelper).to receive(:http_get_json)
|
|
|
|
.and_return(status&.stringify_keys)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject.out_of_office?).to be result }
|
|
|
|
end
|
|
|
|
end
|
2019-03-06 11:00:27 -05:00
|
|
|
end
|