Welcome to mirror list, hosted at ThFree Co, Russian Federation.

alert_status_counts_spec.rb « alert_management « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fceda763717ed3becf9aaf7110406d7f771e1b5c (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
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::AlertManagement::AlertStatusCounts do
  let_it_be(:current_user) { create(:user) }
  let_it_be(:project) { create(:project) }
  let_it_be(:alert_resolved) { create(:alert_management_alert, :resolved, project: project) }
  let_it_be(:alert_ignored) { create(:alert_management_alert, :ignored, project: project) }
  let_it_be(:alert_triggered) { create(:alert_management_alert) }
  let(:params) { {} }

  describe '#execute' do
    subject(:counts) { described_class.new(current_user, project, params) }

    context 'for an unauthorized user' do
      it 'returns zero for all statuses' do
        expect(counts.open).to eq(0)
        expect(counts.all).to eq(0)

        ::AlertManagement::Alert.status_names.each do |status|
          expect(counts.send(status)).to eq(0)
        end
      end
    end

    context 'for an authorized user' do
      before do
        project.add_developer(current_user)
      end

      it 'returns the correct counts for each status' do
        expect(counts.open).to eq(0)
        expect(counts.all).to eq(2)
        expect(counts.resolved).to eq(1)
        expect(counts.ignored).to eq(1)
        expect(counts.triggered).to eq(0)
        expect(counts.acknowledged).to eq(0)
      end

      context 'when filtering params are included' do
        let(:params) { { status: :resolved } }

        it 'returns the correct counts for each status' do
          expect(counts.open).to eq(0)
          expect(counts.all).to eq(1)
          expect(counts.resolved).to eq(1)
          expect(counts.ignored).to eq(0)
          expect(counts.triggered).to eq(0)
          expect(counts.acknowledged).to eq(0)
        end
      end

      context 'when search param is included' do
        let(:params) { { search: alert_resolved.title } }

        it 'returns the correct countss' do
          expect(counts.open).to eq(0)
          expect(counts.all).to eq(1)
          expect(counts.resolved).to eq(1)
          expect(counts.ignored).to eq(0)
          expect(counts.triggered).to eq(0)
          expect(counts.acknowledged).to eq(0)
        end
      end
    end
  end
end