2020-09-21 17:09:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe ::SystemNotes::IncidentService do
|
|
|
|
let_it_be(:author) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:noteable) { create(:incident, project: project) }
|
|
|
|
let_it_be(:issuable_severity) { create(:issuable_severity, issue: noteable, severity: :medium) }
|
|
|
|
|
|
|
|
describe '#change_incident_severity' do
|
|
|
|
subject(:change_severity) { described_class.new(noteable: noteable, project: project, author: author).change_incident_severity }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Gitlab::AppLogger).to receive(:error).and_call_original
|
|
|
|
end
|
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
it_behaves_like 'a system note' do
|
|
|
|
let(:action) { 'severity' }
|
|
|
|
end
|
2020-09-21 17:09:27 -04:00
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
IssuableSeverity.severities.keys.each do |severity|
|
|
|
|
context "with #{severity} severity" do
|
2020-09-21 17:09:27 -04:00
|
|
|
before do
|
2020-10-02 08:09:03 -04:00
|
|
|
issuable_severity.update!(severity: severity)
|
2020-09-21 17:09:27 -04:00
|
|
|
end
|
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
it 'has the appropriate message' do
|
|
|
|
severity_label = IssuableSeverity::SEVERITY_LABELS.fetch(severity.to_sym)
|
2020-09-21 17:09:27 -04:00
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
expect(change_severity.note).to eq("changed the severity to **#{severity_label}**")
|
2020-09-21 17:09:27 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
context 'when severity is invalid' do
|
|
|
|
let(:invalid_severity) { 'invalid-severity' }
|
|
|
|
|
2020-09-21 17:09:27 -04:00
|
|
|
before do
|
2020-10-02 08:09:03 -04:00
|
|
|
allow(noteable).to receive(:severity).and_return(invalid_severity)
|
2020-09-21 17:09:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create system note' do
|
|
|
|
expect { change_severity }.not_to change { noteable.notes.count }
|
|
|
|
end
|
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
it 'writes error to logs' do
|
|
|
|
change_severity
|
|
|
|
|
|
|
|
expect(Gitlab::AppLogger).to have_received(:error).with(
|
|
|
|
message: 'Cannot create a system note for severity change',
|
|
|
|
noteable_class: noteable.class.to_s,
|
|
|
|
noteable_id: noteable.id,
|
|
|
|
severity: invalid_severity
|
|
|
|
)
|
2020-09-21 17:09:27 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|