debian-mirror-gitlab/spec/services/system_notes/alert_management_service_spec.rb

74 lines
2.2 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::SystemNotes::AlertManagementService do
let_it_be(:author) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
2021-10-27 15:23:28 +05:30
let_it_be(:noteable) { create(:alert_management_alert, :with_incident, :acknowledged, project: project) }
2020-07-28 23:09:34 +05:30
2020-11-24 15:15:51 +05:30
describe '#create_new_alert' do
subject { described_class.new(noteable: noteable, project: project).create_new_alert('Some Service') }
it_behaves_like 'a system note' do
let(:author) { User.alert_bot }
let(:action) { 'new_alert_added' }
end
it 'has the appropriate message' do
expect(subject.note).to eq('logged an alert from **Some Service**')
end
end
2020-07-28 23:09:34 +05:30
describe '#change_alert_status' do
2022-04-04 11:22:00 +05:30
subject { described_class.new(noteable: noteable, project: project, author: author).change_alert_status(reason) }
2020-07-28 23:09:34 +05:30
2022-04-04 11:22:00 +05:30
context 'with no specified reason' do
let(:reason) { nil }
it_behaves_like 'a system note' do
let(:action) { 'status' }
end
it 'has the appropriate message' do
expect(subject.note).to eq("changed the status to **Acknowledged**")
end
2020-07-28 23:09:34 +05:30
end
2022-04-04 11:22:00 +05:30
context 'with reason provided' do
let(:reason) { ' by changing incident status' }
it 'has the appropriate message' do
expect(subject.note).to eq("changed the status to **Acknowledged** by changing incident status")
end
2020-07-28 23:09:34 +05:30
end
end
describe '#new_alert_issue' do
let_it_be(:issue) { noteable.issue }
2020-10-24 23:57:45 +05:30
subject { described_class.new(noteable: noteable, project: project, author: author).new_alert_issue(issue) }
2020-07-28 23:09:34 +05:30
it_behaves_like 'a system note' do
let(:action) { 'alert_issue_added' }
end
it 'has the appropriate message' do
2022-04-04 11:22:00 +05:30
expect(subject.note).to eq("created incident #{issue.to_reference(project)} for this alert")
2020-10-24 23:57:45 +05:30
end
end
2021-04-17 20:07:23 +05:30
describe '#log_resolving_alert' do
subject { described_class.new(noteable: noteable, project: project).log_resolving_alert('Some Service') }
it_behaves_like 'a system note' do
let(:author) { User.alert_bot }
let(:action) { 'new_alert_added' }
end
it 'has the appropriate message' do
2021-04-29 21:17:54 +05:30
expect(subject.note).to eq('logged a recovery alert from **Some Service**')
2021-04-17 20:07:23 +05:30
end
end
2020-07-28 23:09:34 +05:30
end