diff options
Diffstat (limited to 'spec/services/alert_management/alerts/update_service_spec.rb')
-rw-r--r-- | spec/services/alert_management/alerts/update_service_spec.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/services/alert_management/alerts/update_service_spec.rb b/spec/services/alert_management/alerts/update_service_spec.rb index 4b47efca9ed..35697ac79a0 100644 --- a/spec/services/alert_management/alerts/update_service_spec.rb +++ b/spec/services/alert_management/alerts/update_service_spec.rb @@ -235,6 +235,59 @@ RSpec.describe AlertManagement::Alerts::UpdateService do it_behaves_like 'adds a system note' end + + context 'with an associated issue' do + let_it_be(:issue, reload: true) { create(:issue, project: project) } + + before do + alert.update!(issue: issue) + end + + shared_examples 'does not sync with the incident status' do + specify do + expect(::Issues::UpdateService).not_to receive(:new) + expect { response }.to change { alert.acknowledged? }.to(true) + end + end + + it_behaves_like 'does not sync with the incident status' + + context 'when the issue is an incident' do + before do + issue.update!(issue_type: Issue.issue_types[:incident]) + end + + it_behaves_like 'does not sync with the incident status' + + context 'when the incident has an escalation status' do + let_it_be(:escalation_status, reload: true) { create(:incident_management_issuable_escalation_status, issue: issue) } + + it 'updates the incident escalation status with the new alert status' do + expect(::Issues::UpdateService).to receive(:new).once.and_call_original + expect(described_class).to receive(:new).once.and_call_original + + expect { response }.to change { escalation_status.reload.acknowledged? }.to(true) + .and change { alert.reload.acknowledged? }.to(true) + end + + context 'when the statuses match' do + before do + escalation_status.update!(status_event: :acknowledge) + end + + it_behaves_like 'does not sync with the incident status' + end + + context 'when feature flag is disabled' do + before do + stub_feature_flags(incident_escalations: false) + end + + it_behaves_like 'does not sync with the incident status' + end + end + end + end end end end |