2020-07-08 23:09:01 -04:00
|
|
|
# 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) }
|
2020-07-09 17:09:33 -04:00
|
|
|
let_it_be(:noteable) { create(:alert_management_alert, :with_issue, :acknowledged, project: project) }
|
2020-07-08 23:09:01 -04:00
|
|
|
|
2020-08-27 14:10:29 -04:00
|
|
|
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-08 23:09:01 -04:00
|
|
|
describe '#change_alert_status' do
|
|
|
|
subject { described_class.new(noteable: noteable, project: project, author: author).change_alert_status(noteable) }
|
|
|
|
|
|
|
|
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
|
2020-07-09 17:09:33 -04:00
|
|
|
|
|
|
|
describe '#new_alert_issue' do
|
|
|
|
let_it_be(:issue) { noteable.issue }
|
|
|
|
|
2020-07-23 05:09:18 -04:00
|
|
|
subject { described_class.new(noteable: noteable, project: project, author: author).new_alert_issue(issue) }
|
2020-07-09 17:09:33 -04:00
|
|
|
|
|
|
|
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 issue #{issue.to_reference(project)} for this alert")
|
|
|
|
end
|
|
|
|
end
|
2020-07-23 05:09:18 -04:00
|
|
|
|
|
|
|
describe '#closed_alert_issue' do
|
|
|
|
let_it_be(:issue) { noteable.issue }
|
|
|
|
|
|
|
|
subject { described_class.new(noteable: noteable, project: project, author: author).closed_alert_issue(issue) }
|
|
|
|
|
|
|
|
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 **Resolved** by closing issue #{issue.to_reference(project)}")
|
|
|
|
end
|
|
|
|
end
|
2021-02-23 13:10:40 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
expect(subject.note).to eq('logged a resolving alert from **Some Service**')
|
|
|
|
end
|
|
|
|
end
|
2020-07-08 23:09:01 -04:00
|
|
|
end
|