2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
require 'fast_spec_helper'
|
|
|
|
|
|
|
|
require 'gitlab/danger/teammate'
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe Gitlab::Danger::Teammate do
|
2019-09-04 21:01:54 +05:30
|
|
|
subject { described_class.new(options) }
|
|
|
|
let(:options) { { 'projects' => projects, 'role' => role } }
|
2019-07-07 11:18:12 +05:30
|
|
|
let(:projects) { { project => capabilities } }
|
2019-09-04 21:01:54 +05:30
|
|
|
let(:role) { 'Engineer, Manage' }
|
|
|
|
let(:labels) { [] }
|
2019-07-07 11:18:12 +05:30
|
|
|
let(:project) { double }
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
context 'when having multiple capabilities' do
|
|
|
|
let(:capabilities) { ['reviewer backend', 'maintainer frontend', 'trainee_maintainer qa'] }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
it '#reviewer? supports multiple roles per project' do
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(subject.reviewer?(project, :backend, labels)).to be_truthy
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it '#traintainer? supports multiple roles per project' do
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(subject.traintainer?(project, :qa, labels)).to be_truthy
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it '#maintainer? supports multiple roles per project' do
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(subject.maintainer?(project, :frontend, labels)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when labels contain Create and the category is test' do
|
2019-12-04 20:38:33 +05:30
|
|
|
let(:labels) { ['devops::create'] }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
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-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
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-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
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-09-04 21:01:54 +05:30
|
|
|
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-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
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-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
context 'when having single capability' do
|
2019-07-07 11:18:12 +05:30
|
|
|
let(:capabilities) { 'reviewer backend' }
|
|
|
|
|
|
|
|
it '#reviewer? supports one role per project' do
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(subject.reviewer?(project, :backend, labels)).to be_truthy
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it '#traintainer? supports one role per project' do
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(subject.traintainer?(project, :database, labels)).to be_falsey
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it '#maintainer? supports one role per project' do
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(subject.maintainer?(project, :frontend, labels)).to be_falsey
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|