Commit 0deaeb61 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Add severity system note in background job

Move adding a severity system note into a background job
parent d1d6903c
......@@ -31,7 +31,7 @@ module IncidentManagement
end
def add_system_note
SystemNoteService.change_incident_severity(issuable, current_user)
::IncidentManagement::AddSeveritySystemNoteWorker.perform_async(issuable.id, current_user.id)
end
end
end
......
......@@ -715,6 +715,14 @@
:weight: 2
:idempotent: true
:tags: []
- :name: incident_management:incident_management_add_severity_system_note
:feature_category: :incident_management
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 2
:idempotent:
:tags: []
- :name: incident_management:incident_management_pager_duty_process_incident
:feature_category: :incident_management
:has_external_dependencies:
......
# frozen_string_literal: true
module IncidentManagement
class AddSeveritySystemNoteWorker # rubocop:disable Scalability/IdempotentWorker
include ApplicationWorker
queue_namespace :incident_management
feature_category :incident_management
def perform(incident_id, user_id)
return if incident_id.blank? || user_id.blank?
incident = Issue.with_issue_type(:incident).find_by_id(incident_id)
return unless incident
user = User.find_by_id(user_id)
return unless user
SystemNoteService.change_incident_severity(incident, user)
end
end
end
......@@ -7,12 +7,19 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do
describe '#execute' do
let(:severity) { 'low' }
let(:system_note_worker) { ::IncidentManagement::AddSeveritySystemNoteWorker }
subject(:update_severity) { described_class.new(issuable, user, severity).execute }
before do
allow(system_note_worker).to receive(:perform_async)
end
shared_examples 'adds a system note' do
it do
expect { update_severity }.to change { issuable.notes.where(author: user).count }.by(1)
it 'calls AddSeveritySystemNoteWorker' do
update_severity
expect(system_note_worker).to have_received(:perform_async).with(issuable.id, user.id)
end
end
......@@ -27,7 +34,9 @@ RSpec.describe IncidentManagement::Incidents::UpdateSeverityService do
end
it 'does not add a system note' do
expect { update_severity }.not_to change { issuable.notes.count }
update_severity
expect(system_note_worker).not_to have_received(:perform_async)
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::AddSeveritySystemNoteWorker do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:incident) { create(:incident, project: project) }
let_it_be(:issuable_severity) { create(:issuable_severity, issue: incident, severity: :medium) }
describe '#perform' do
let(:incident_id) { incident.id }
let(:user_id) { user.id }
subject(:perform) { described_class.new.perform(incident_id, user_id) }
shared_examples 'does not add a system note' do
it 'does not change incident notes count' do
expect { perform }.not_to change { incident.notes.count }
end
end
context 'when incident and user exist' do
it 'creates a system note' do
expect { perform }.to change { incident.notes.where(author: user).count }.by(1)
end
end
context 'when incident does not exist' do
let(:incident_id) { -1 }
it_behaves_like 'does not add a system note'
end
context 'when incident_id is nil' do
let(:incident_id) { nil }
it_behaves_like 'does not add a system note'
end
context 'when issue is not an incident' do
let_it_be(:issue) { create(:issue, project: project) }
let(:incident_id) { issue.id }
it_behaves_like 'does not add a system note'
end
context 'when user does not exist' do
let(:user_id) { -1 }
it_behaves_like 'does not add a system note'
end
context 'when user_id is nil' do
let(:user_id) { nil }
it_behaves_like 'does not add a system note'
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