summaryrefslogtreecommitdiff
path: root/spec/tooling/danger/user_types_spec.rb
blob: 535566012120b990b98ea523e1a91884e17c2203 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true

require 'gitlab-dangerfiles'
require 'gitlab/dangerfiles/spec_helper'
require_relative '../../../tooling/danger/user_types'

RSpec.describe Tooling::Danger::UserTypes, feature_category: :subscription_cost_management do
  include_context 'with dangerfile'

  let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) }
  let(:user_types) { fake_danger.new(helper: fake_helper) }

  describe 'changed files' do
    subject(:bot_user_types_change_warning) { user_types.bot_user_types_change_warning }

    before do
      allow(fake_helper).to receive(:modified_files).and_return(modified_files)
      allow(fake_helper).to receive(:changed_lines).and_return(changed_lines)
    end

    context 'when has_user_type.rb file is not impacted' do
      let(:modified_files) { ['app/models/concerns/importable.rb'] }
      let(:changed_lines) { ['+ANY_CHANGES'] }

      it "doesn't add any warnings" do
        expect(user_types).not_to receive(:warn)

        bot_user_types_change_warning
      end
    end

    context 'when the has_user_type.rb file is impacted' do
      let(:modified_files) { ['app/models/concerns/has_user_type.rb'] }

      context 'with BOT_USER_TYPES changes' do
        let(:changed_lines) { ['+BOT_USER_TYPES'] }

        it 'adds warning' do
          expect(user_types).to receive(:warn).with(described_class::BOT_USER_TYPES_CHANGED_WARNING)

          bot_user_types_change_warning
        end
      end

      context 'without BOT_USER_TYPES changes' do
        let(:changed_lines) { ['+OTHER_CHANGES'] }

        it "doesn't add any warnings" do
          expect(user_types).not_to receive(:warn)

          bot_user_types_change_warning
        end
      end
    end
  end
end