diff options
author | Jacopo <beschi.jacopo@gmail.com> | 2019-05-30 13:50:40 +0300 |
---|---|---|
committer | Jacopo <beschi.jacopo@gmail.com> | 2019-06-12 22:32:35 +0300 |
commit | cef127e10778a21756c00c4226592f32f15a6c1f (patch) | |
tree | a3d1500d26ec126dd5c6921475727e2972bb8eb4 /spec/lib/gitlab/danger | |
parent | 8ade1f8758efa687e67c0c29e8d67217c31c9e0f (diff) |
Excludes MR author from Review roulette
Excludes MR author from gitlab_ui and single_codebase Review roulette
results.
Diffstat (limited to 'spec/lib/gitlab/danger')
-rw-r--r-- | spec/lib/gitlab/danger/helper_spec.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/danger/roulette_spec.rb | 43 |
2 files changed, 53 insertions, 0 deletions
diff --git a/spec/lib/gitlab/danger/helper_spec.rb b/spec/lib/gitlab/danger/helper_spec.rb index f7642182a17..22e52901758 100644 --- a/spec/lib/gitlab/danger/helper_spec.rb +++ b/spec/lib/gitlab/danger/helper_spec.rb @@ -202,4 +202,14 @@ describe Gitlab::Danger::Helper do it { is_expected.to eq(expected_label) } end end + + describe '#new_teammates' do + it 'returns an array of Teammate' do + usernames = %w[filipa iamphil] + + teammates = helper.new_teammates(usernames) + + expect(teammates.map(&:username)).to eq(usernames) + end + end end diff --git a/spec/lib/gitlab/danger/roulette_spec.rb b/spec/lib/gitlab/danger/roulette_spec.rb index 40dce0c5378..121c5d8ecd9 100644 --- a/spec/lib/gitlab/danger/roulette_spec.rb +++ b/spec/lib/gitlab/danger/roulette_spec.rb @@ -98,4 +98,47 @@ describe Gitlab::Danger::Roulette do is_expected.to contain_exactly(ce_teammate_matcher) end end + + describe '#spin_for_person' do + let(:person1) { Gitlab::Danger::Teammate.new('username' => 'rymai') } + let(:person2) { Gitlab::Danger::Teammate.new('username' => 'godfat') } + let(:author) { Gitlab::Danger::Teammate.new('username' => 'filipa') } + let(:ooo) { Gitlab::Danger::Teammate.new('username' => 'jacopo-beschi') } + + before do + stub_person_message(person1, 'making GitLab magic') + stub_person_message(person2, 'making GitLab magic') + stub_person_message(ooo, 'OOO till 15th') + # we don't stub Filipa, as she is the author and + # we should not fire request checking for her + + allow(subject).to receive_message_chain(:gitlab, :mr_author).and_return(author.username) + end + + it 'returns a random person' do + persons = [person1, person2] + + selected = subject.spin_for_person(persons, random: Random.new) + + expect(selected.username).to be_in(persons.map(&:username)) + end + + it 'excludes OOO persons' do + expect(subject.spin_for_person([ooo], random: Random.new)).to be_nil + end + + it 'excludes mr.author' do + expect(subject.spin_for_person([author], random: Random.new)).to be_nil + end + + private + + def stub_person_message(person, message) + body = { message: message }.to_json + + WebMock + .stub_request(:get, "https://gitlab.com/api/v4/users/#{person.username}/status") + .to_return(body: body) + end + end end |