2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
require 'fast_spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
require 'timecop'
|
2019-12-21 20:55:43 +05:30
|
|
|
require 'rspec-parameterized'
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
require 'gitlab/danger/teammate'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Danger::Teammate do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
subject { described_class.new(options.stringify_keys) }
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
let(:tz_offset_hours) { 2.0 }
|
|
|
|
let(:options) do
|
|
|
|
{
|
|
|
|
username: 'luigi',
|
|
|
|
projects: projects,
|
|
|
|
role: role,
|
|
|
|
markdown_name: '[Luigi](https://gitlab.com/luigi) (`@luigi`)',
|
|
|
|
tz_offset_hours: tz_offset_hours
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:capabilities) { ['reviewer backend'] }
|
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
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
context 'when labels contain devops::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
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
context 'when role is Software Engineer in Test, Create' do
|
|
|
|
let(:role) { 'Software Engineer in Test, Create' }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
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
|
2020-01-01 13:55:28 +05:30
|
|
|
let(:role) { '<a href="#">Software Engineer in Test</a>, Create' }
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
context 'when role is Software Engineer in Test' do
|
|
|
|
let(:role) { 'Software Engineer in Test' }
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
it '#reviewer? returns false' do
|
|
|
|
expect(subject.reviewer?(project, :test, labels)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
context 'when role is Software Engineer in Test, Manage' do
|
|
|
|
let(:role) { 'Software Engineer in Test, Manage' }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
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
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
context 'when capabilities include maintainer backend' do
|
|
|
|
let(:capabilities) { ['maintainer backend'] }
|
|
|
|
|
|
|
|
it '#maintainer? returns true' do
|
|
|
|
expect(subject.maintainer?(project, :engineering_productivity, labels)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when capabilities include trainee_maintainer backend' do
|
|
|
|
let(:capabilities) { ['trainee_maintainer backend'] }
|
|
|
|
|
|
|
|
it '#traintainer? returns true' do
|
|
|
|
expect(subject.traintainer?(project, :engineering_productivity, labels)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
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
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
describe '#local_hour' do
|
|
|
|
around do |example|
|
|
|
|
Timecop.freeze(Time.utc(2020, 6, 23, 10)) { example.run }
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
context 'when author is given' do
|
|
|
|
where(:tz_offset_hours, :expected_local_hour) do
|
|
|
|
-12 | 22
|
|
|
|
-10 | 0
|
|
|
|
2 | 12
|
|
|
|
4 | 14
|
|
|
|
12 | 22
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
with_them do
|
|
|
|
it 'returns the correct local_hour' do
|
|
|
|
expect(subject.local_hour).to eq(expected_local_hour)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
describe '#markdown_name' do
|
|
|
|
context 'when timezone_experiment == false' do
|
|
|
|
it 'returns markdown name as-is' do
|
|
|
|
expect(subject.markdown_name).to eq(options[:markdown_name])
|
|
|
|
expect(subject.markdown_name(timezone_experiment: false)).to eq(options[:markdown_name])
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
context 'when timezone_experiment == true' do
|
|
|
|
it 'returns markdown name with timezone info' do
|
|
|
|
expect(subject.markdown_name(timezone_experiment: true)).to eq("#{options[:markdown_name]} (UTC+2)")
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when offset is 1.5' do
|
|
|
|
let(:tz_offset_hours) { 1.5 }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it 'returns markdown name with timezone info, not truncated' do
|
|
|
|
expect(subject.markdown_name(timezone_experiment: true)).to eq("#{options[:markdown_name]} (UTC+1.5)")
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
context 'when author is given' do
|
|
|
|
where(:tz_offset_hours, :author_offset, :diff_text) do
|
|
|
|
-12 | -10 | "2 hours behind `@mario`"
|
|
|
|
-10 | -12 | "2 hours ahead `@mario`"
|
|
|
|
-10 | 2 | "12 hours behind `@mario`"
|
|
|
|
2 | 4 | "2 hours behind `@mario`"
|
|
|
|
4 | 2 | "2 hours ahead `@mario`"
|
|
|
|
2 | 3 | "1 hour behind `@mario`"
|
|
|
|
3 | 2 | "1 hour ahead `@mario`"
|
|
|
|
2 | 2 | "same timezone as `@mario`"
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
with_them do
|
|
|
|
it 'returns markdown name with timezone info' do
|
|
|
|
author = described_class.new(options.merge(username: 'mario', tz_offset_hours: author_offset).stringify_keys)
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
floored_offset_hours = subject.__send__(:floored_offset_hours)
|
|
|
|
utc_offset = floored_offset_hours >= 0 ? "+#{floored_offset_hours}" : floored_offset_hours
|
|
|
|
|
|
|
|
expect(subject.markdown_name(timezone_experiment: true, author: author)).to eq("#{options[:markdown_name]} (UTC#{utc_offset}, #{diff_text})")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|