summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/danger/weightage/maintainers_spec.rb
blob: 066bb487fa2f1fbb97828f563791bc13d88ad524 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

require 'gitlab/danger/weightage/maintainers'

RSpec.describe Gitlab::Danger::Weightage::Maintainers do
  let(:multiplier) { Gitlab::Danger::Weightage::CAPACITY_MULTIPLIER }
  let(:regular_maintainer) { double('Teammate', reduced_capacity: false) }
  let(:reduced_capacity_maintainer) { double('Teammate', reduced_capacity: true) }
  let(:maintainers) do
    [
      regular_maintainer,
      reduced_capacity_maintainer
    ]
  end

  let(:maintainer_count) { Gitlab::Danger::Weightage::BASE_REVIEWER_WEIGHT * multiplier }
  let(:reduced_capacity_maintainer_count) { Gitlab::Danger::Weightage::BASE_REVIEWER_WEIGHT }

  subject(:weighted_maintainers) { described_class.new(maintainers).execute }

  describe '#execute' do
    it 'weights the maintainers overall' do
      expect(weighted_maintainers.count).to eq maintainer_count + reduced_capacity_maintainer_count
    end

    it 'has total count of regular maintainers' do
      expect(weighted_maintainers.count { |r| r.object_id == regular_maintainer.object_id }).to eq maintainer_count
    end

    it 'has count of reduced capacity maintainers' do
      expect(weighted_maintainers.count { |r| r.object_id == reduced_capacity_maintainer.object_id }).to eq reduced_capacity_maintainer_count
    end
  end
end