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 69 70 71 72 73
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::SystemNotes::AlertManagementService, feature_category: :groups_and_projects do
let_it_be(:author) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:noteable) { create(:alert_management_alert, :with_incident, :acknowledged, project: project) }
describe '#create_new_alert' do
subject { described_class.new(noteable: noteable, container: project).create_new_alert('Some Service') }
it_behaves_like 'a system note' do
let(:author) { Users::Internal.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
describe '#change_alert_status' do
subject { described_class.new(noteable: noteable, container: project, author: author).change_alert_status(reason) }
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
end
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
end
end
describe '#new_alert_issue' do
let_it_be(:issue) { noteable.issue }
subject { described_class.new(noteable: noteable, container: project, author: author).new_alert_issue(issue) }
it_behaves_like 'a system note' do
let(:action) { 'alert_issue_added' }
end
it 'has the appropriate message' do
expect(subject.note).to eq("created incident #{issue.to_reference(project)} for this alert")
end
end
describe '#log_resolving_alert' do
subject { described_class.new(noteable: noteable, container: project).log_resolving_alert('Some Service') }
it_behaves_like 'a system note' do
let(:author) { Users::Internal.alert_bot }
let(:action) { 'new_alert_added' }
end
it 'has the appropriate message' do
expect(subject.note).to eq('logged a recovery alert from **Some Service**')
end
end
end
|