Commit d1d6903c authored by Vitali Tatarintev's avatar Vitali Tatarintev

Write error to log for invalid severity

Write an error to log on an attempt to create a system note
with the invalid severity value.
parent 15ef1d80
......@@ -11,10 +11,19 @@ module SystemNotes
# Returns the created Note object
def change_incident_severity
severity = noteable.severity
severity_label = IssuableSeverity::SEVERITY_LABELS.fetch(severity.to_sym)
body = "changed the severity to **#{severity_label}**"
create_note(NoteSummary.new(noteable, project, author, body, action: 'severity'))
if severity_label = IssuableSeverity::SEVERITY_LABELS[severity.to_sym]
body = "changed the severity to **#{severity_label}**"
create_note(NoteSummary.new(noteable, project, author, body, action: 'severity'))
else
Gitlab::AppLogger.error(
message: 'Cannot create a system note for severity change',
noteable_class: noteable.class.to_s,
noteable_id: noteable.id,
severity: severity
)
end
end
end
end
......@@ -28,5 +28,29 @@ RSpec.describe ::SystemNotes::IncidentService do
end
end
end
context 'when severity is invalid' do
let(:invalid_severity) { 'invalid-severity' }
before do
allow(noteable).to receive(:severity).and_return(invalid_severity)
allow(Gitlab::AppLogger).to receive(:error).and_call_original
end
it 'does not create system note' do
expect { change_severity }.not_to change { noteable.notes.count }
end
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
)
end
end
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