diff options
Diffstat (limited to 'spec/lib/gitlab/alert_management/alert_status_counts_spec.rb')
-rw-r--r-- | spec/lib/gitlab/alert_management/alert_status_counts_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/lib/gitlab/alert_management/alert_status_counts_spec.rb b/spec/lib/gitlab/alert_management/alert_status_counts_spec.rb new file mode 100644 index 00000000000..816ed918fe8 --- /dev/null +++ b/spec/lib/gitlab/alert_management/alert_status_counts_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::AlertManagement::AlertStatusCounts do + let_it_be(:current_user) { create(:user) } + let_it_be(:project) { create(:project) } + let_it_be(:alert_1) { create(:alert_management_alert, :resolved, project: project) } + let_it_be(:alert_2) { create(:alert_management_alert, :ignored, project: project) } + let_it_be(:alert_3) { 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::STATUSES.each_key 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: AlertManagement::Alert::STATUSES[: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 + end + end +end |