diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /spec/services/incident_management/issuable_escalation_statuses/after_update_service_spec.rb | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'spec/services/incident_management/issuable_escalation_statuses/after_update_service_spec.rb')
-rw-r--r-- | spec/services/incident_management/issuable_escalation_statuses/after_update_service_spec.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/services/incident_management/issuable_escalation_statuses/after_update_service_spec.rb b/spec/services/incident_management/issuable_escalation_statuses/after_update_service_spec.rb new file mode 100644 index 00000000000..e9db6ba8d28 --- /dev/null +++ b/spec/services/incident_management/issuable_escalation_statuses/after_update_service_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe IncidentManagement::IssuableEscalationStatuses::AfterUpdateService do + let_it_be(:current_user) { create(:user) } + let_it_be(:escalation_status, reload: true) { create(:incident_management_issuable_escalation_status, :triggered) } + let_it_be(:issue, reload: true) { escalation_status.issue } + let_it_be(:project) { issue.project } + let_it_be(:alert) { create(:alert_management_alert, issue: issue, project: project) } + + let(:status_event) { :acknowledge } + let(:update_params) { { incident_management_issuable_escalation_status_attributes: { status_event: status_event } } } + let(:service) { IncidentManagement::IssuableEscalationStatuses::AfterUpdateService.new(issue, current_user) } + + subject(:result) do + issue.update!(update_params) + service.execute + end + + before do + issue.project.add_developer(current_user) + end + + shared_examples 'does not attempt to update the alert' do + specify do + expect(::AlertManagement::Alerts::UpdateService).not_to receive(:new) + + expect(result).to be_success + end + end + + context 'with status attributes' do + it 'updates the alert with the new alert status' do + expect(::AlertManagement::Alerts::UpdateService).to receive(:new).once.and_call_original + expect(described_class).to receive(:new).once.and_call_original + + expect { result }.to change { escalation_status.reload.acknowledged? }.to(true) + .and change { alert.reload.acknowledged? }.to(true) + end + + context 'when incident is not associated with an alert' do + before do + alert.destroy! + end + + it_behaves_like 'does not attempt to update the alert' + end + + context 'when new status matches the current status' do + let(:status_event) { :trigger } + + it_behaves_like 'does not attempt to update the alert' + end + end +end |