Commit 15ef1d80 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Add system note on change incident severity

parent 011f15a8
...@@ -14,7 +14,8 @@ module IncidentManagement ...@@ -14,7 +14,8 @@ module IncidentManagement
def execute def execute
return unless issuable.incident? return unless issuable.incident?
issuable_severity.update(severity: severity) update_severity!
add_system_note
end end
private private
...@@ -24,6 +25,14 @@ module IncidentManagement ...@@ -24,6 +25,14 @@ module IncidentManagement
def issuable_severity def issuable_severity
issuable.issuable_severity || issuable.build_issuable_severity(issue_id: issuable.id) issuable.issuable_severity || issuable.build_issuable_severity(issue_id: issuable.id)
end end
def update_severity!
issuable_severity.update!(severity: severity)
end
def add_system_note
SystemNoteService.change_incident_severity(issuable, current_user)
end
end end
end end
end end
...@@ -10,6 +10,12 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do ...@@ -10,6 +10,12 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do
subject(:update_severity) { described_class.new(issuable, user, severity).execute } subject(:update_severity) { described_class.new(issuable, user, severity).execute }
shared_examples 'adds a system note' do
it do
expect { update_severity }.to change { issuable.notes.where(author: user).count }.by(1)
end
end
context 'when issuable not an incident' do context 'when issuable not an incident' do
%i(issue merge_request).each do |issuable_type| %i(issue merge_request).each do |issuable_type|
let(:issuable) { build_stubbed(issuable_type) } let(:issuable) { build_stubbed(issuable_type) }
...@@ -17,7 +23,11 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do ...@@ -17,7 +23,11 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do
it { is_expected.to be_nil } it { is_expected.to be_nil }
it 'does not set severity' do it 'does not set severity' do
expect { subject }.not_to change(IssuableSeverity, :count) expect { update_severity }.not_to change(IssuableSeverity, :count)
end
it 'does not add a system note' do
expect { update_severity }.not_to change { issuable.notes.count }
end end
end end
end end
...@@ -33,6 +43,8 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do ...@@ -33,6 +43,8 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do
it 'sets severity to specified value' do it 'sets severity to specified value' do
expect { update_severity }.to change { issuable.severity }.to('low') expect { update_severity }.to change { issuable.severity }.to('low')
end end
it_behaves_like 'adds a system note'
end end
context 'when issuable has an issuable severity' do context 'when issuable has an issuable severity' do
...@@ -45,6 +57,8 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do ...@@ -45,6 +57,8 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do
it 'updates existing issuable severity' do it 'updates existing issuable severity' do
expect { update_severity }.to change { issuable_severity.severity }.to(severity) expect { update_severity }.to change { issuable_severity.severity }.to(severity)
end end
it_behaves_like 'adds a system note'
end end
context 'when severity value is unsupported' do context 'when severity value is unsupported' do
...@@ -55,6 +69,8 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do ...@@ -55,6 +69,8 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do
expect(issuable.issuable_severity.severity).to eq(IssuableSeverity::DEFAULT) expect(issuable.issuable_severity.severity).to eq(IssuableSeverity::DEFAULT)
end end
it_behaves_like 'adds a system note'
end end
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