2020-05-20 00:08:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 09:08:32 +00:00
|
|
|
RSpec.describe Gitlab::AlertManagement::AlertStatusCounts do
|
2020-05-20 00:08:20 +00:00
|
|
|
let_it_be(:current_user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
2020-07-21 00:09:37 +00:00
|
|
|
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) }
|
2020-05-20 00:08:20 +00:00
|
|
|
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)
|
|
|
|
|
2020-10-08 15:08:17 +00:00
|
|
|
::AlertManagement::Alert.status_names.each do |status|
|
2020-05-20 00:08:20 +00:00
|
|
|
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
|
2020-10-08 15:08:17 +00:00
|
|
|
let(:params) { { status: :resolved } }
|
2020-05-20 00:08:20 +00:00
|
|
|
|
|
|
|
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
|
2020-06-16 09:08:27 +00:00
|
|
|
|
|
|
|
context 'when search param is included' do
|
2020-07-21 00:09:37 +00:00
|
|
|
let(:params) { { search: alert_resolved.title } }
|
2020-06-16 09:08:27 +00:00
|
|
|
|
|
|
|
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
|
2020-05-20 00:08:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|