Commit 2c1600a8 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '222520-update-more-alert-factory-usages' into 'master'

Update ambiguous alert var name in specs

Closes #222520

See merge request gitlab-org/gitlab!37384
parents be5e9d74 03848e84
......@@ -5,9 +5,9 @@ require 'spec_helper'
RSpec.describe AlertManagement::AlertsFinder, '#execute' do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:alert_1) { create(:alert_management_alert, :all_fields, :resolved, project: project, ended_at: 1.year.ago, events: 2, severity: :high) }
let_it_be(:alert_2) { create(:alert_management_alert, :all_fields, :ignored, project: project, events: 1, severity: :critical) }
let_it_be(:alert_3) { create(:alert_management_alert, :all_fields) }
let_it_be(:resolved_alert) { create(:alert_management_alert, :all_fields, :resolved, project: project, ended_at: 1.year.ago, events: 2, severity: :high) }
let_it_be(:ignored_alert) { create(:alert_management_alert, :all_fields, :ignored, project: project, events: 1, severity: :critical) }
let_it_be(:triggered_alert) { create(:alert_management_alert, :all_fields) }
let(:params) { {} }
describe '#execute' do
......@@ -23,13 +23,13 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do
end
context 'empty params' do
it { is_expected.to contain_exactly(alert_1, alert_2) }
it { is_expected.to contain_exactly(resolved_alert, ignored_alert) }
end
context 'iid given' do
let(:params) { { iid: alert_1.iid } }
let(:params) { { iid: resolved_alert.iid } }
it { is_expected.to match_array(alert_1) }
it { is_expected.to match_array(resolved_alert) }
context 'unknown iid' do
let(:params) { { iid: 'unknown' } }
......@@ -41,13 +41,13 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do
context 'status given' do
let(:params) { { status: AlertManagement::Alert::STATUSES[:resolved] } }
it { is_expected.to match_array(alert_1) }
it { is_expected.to match_array(resolved_alert) }
context 'with an array of statuses' do
let(:alert_3) { create(:alert_management_alert) }
let(:triggered_alert) { create(:alert_management_alert) }
let(:params) { { status: [AlertManagement::Alert::STATUSES[:resolved]] } }
it { is_expected.to match_array(alert_1) }
it { is_expected.to match_array(resolved_alert) }
end
context 'with no alerts of status' do
......@@ -59,13 +59,13 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do
context 'with an empty status array' do
let(:params) { { status: [] } }
it { is_expected.to match_array([alert_1, alert_2]) }
it { is_expected.to match_array([resolved_alert, ignored_alert]) }
end
context 'with an nil status' do
let(:params) { { status: nil } }
it { is_expected.to match_array([alert_1, alert_2]) }
it { is_expected.to match_array([resolved_alert, ignored_alert]) }
end
end
......@@ -74,13 +74,13 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do
context 'sorts alerts ascending' do
let(:params) { { sort: 'created_asc' } }
it { is_expected.to eq [alert_1, alert_2] }
it { is_expected.to eq [resolved_alert, ignored_alert] }
end
context 'sorts alerts descending' do
let(:params) { { sort: 'created_desc' } }
it { is_expected.to eq [alert_2, alert_1] }
it { is_expected.to eq [ignored_alert, resolved_alert] }
end
end
......@@ -88,13 +88,13 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do
context 'sorts alerts ascending' do
let(:params) { { sort: 'updated_asc' } }
it { is_expected.to eq [alert_1, alert_2] }
it { is_expected.to eq [resolved_alert, ignored_alert] }
end
context 'sorts alerts descending' do
let(:params) { { sort: 'updated_desc' } }
it { is_expected.to eq [alert_2, alert_1] }
it { is_expected.to eq [ignored_alert, resolved_alert] }
end
end
......@@ -102,13 +102,13 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do
context 'sorts alerts ascending' do
let(:params) { { sort: 'started_at_asc' } }
it { is_expected.to eq [alert_1, alert_2] }
it { is_expected.to eq [resolved_alert, ignored_alert] }
end
context 'sorts alerts descending' do
let(:params) { { sort: 'started_at_desc' } }
it { is_expected.to eq [alert_2, alert_1] }
it { is_expected.to eq [ignored_alert, resolved_alert] }
end
end
......@@ -116,13 +116,13 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do
context 'sorts alerts ascending' do
let(:params) { { sort: 'ended_at_asc' } }
it { is_expected.to eq [alert_1, alert_2] }
it { is_expected.to eq [resolved_alert, ignored_alert] }
end
context 'sorts alerts descending' do
let(:params) { { sort: 'ended_at_desc' } }
it { is_expected.to eq [alert_2, alert_1] }
it { is_expected.to eq [ignored_alert, resolved_alert] }
end
end
......@@ -133,13 +133,13 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do
context 'sorts alerts ascending' do
let(:params) { { sort: 'event_count_asc' } }
it { is_expected.to eq [alert_2, alert_1, alert_count_3, alert_count_6] }
it { is_expected.to eq [ignored_alert, resolved_alert, alert_count_3, alert_count_6] }
end
context 'sorts alerts descending' do
let(:params) { { sort: 'event_count_desc' } }
it { is_expected.to eq [alert_count_6, alert_count_3, alert_1, alert_2] }
it { is_expected.to eq [alert_count_6, alert_count_3, resolved_alert, ignored_alert] }
end
end
......
......@@ -7,8 +7,8 @@ RSpec.describe Resolvers::AlertManagement::AlertResolver 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, ended_at: 1.year.ago, events: 2, severity: :high) }
let_it_be(:alert_2) { create(:alert_management_alert, :ignored, project: project, events: 1, severity: :critical) }
let_it_be(:resolved_alert) { create(:alert_management_alert, :resolved, project: project, ended_at: 1.year.ago, events: 2, severity: :high) }
let_it_be(:ignored_alert) { create(:alert_management_alert, :ignored, project: project, events: 1, severity: :critical) }
let_it_be(:alert_other_proj) { create(:alert_management_alert) }
let(:args) { {} }
......@@ -24,18 +24,18 @@ RSpec.describe Resolvers::AlertManagement::AlertResolver do
project.add_developer(current_user)
end
it { is_expected.to contain_exactly(alert_1, alert_2) }
it { is_expected.to contain_exactly(resolved_alert, ignored_alert) }
context 'finding by iid' do
let(:args) { { iid: alert_1.iid } }
let(:args) { { iid: resolved_alert.iid } }
it { is_expected.to contain_exactly(alert_1) }
it { is_expected.to contain_exactly(resolved_alert) }
end
context 'finding by status' do
let(:args) { { status: [Types::AlertManagement::StatusEnum.values['IGNORED'].value] } }
it { is_expected.to contain_exactly(alert_2) }
it { is_expected.to contain_exactly(ignored_alert) }
end
describe 'sorting' do
......@@ -45,11 +45,11 @@ RSpec.describe Resolvers::AlertManagement::AlertResolver do
let_it_be(:alert_count_3) { create(:alert_management_alert, project: project, events: 3) }
it 'sorts alerts ascending' do
expect(resolve_alerts(sort: :event_count_asc)).to eq [alert_2, alert_1, alert_count_3, alert_count_6]
expect(resolve_alerts(sort: :event_count_asc)).to eq [ignored_alert, resolved_alert, alert_count_3, alert_count_6]
end
it 'sorts alerts descending' do
expect(resolve_alerts(sort: :event_count_desc)).to eq [alert_count_6, alert_count_3, alert_1, alert_2]
expect(resolve_alerts(sort: :event_count_desc)).to eq [alert_count_6, alert_count_3, resolved_alert, ignored_alert]
end
end
end
......
......@@ -249,15 +249,15 @@ RSpec.describe AlertManagement::Alert do
subject { described_class.last_prometheus_alert_by_project_id }
let(:project_1) { create(:project) }
let!(:alert_1) { create(:alert_management_alert, project: project_1) }
let!(:alert_2) { create(:alert_management_alert, project: project_1) }
let!(:p1_alert_1) { create(:alert_management_alert, project: project_1) }
let!(:p1_alert_2) { create(:alert_management_alert, project: project_1) }
let(:project_2) { create(:project) }
let!(:alert_3) { create(:alert_management_alert, project: project_2) }
let!(:alert_4) { create(:alert_management_alert, project: project_2) }
let!(:p2_alert_1) { create(:alert_management_alert, project: project_2) }
let!(:p2_alert_2) { create(:alert_management_alert, project: project_2) }
it 'returns the latest alert for each project' do
expect(subject).to contain_exactly(alert_2, alert_4)
expect(subject).to contain_exactly(p1_alert_2, p2_alert_2)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment