diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-21 12:09:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-21 12:09:07 +0000 |
commit | 2a040e2655fe0a99df61ad0a7bd0c27e68af0c38 (patch) | |
tree | a245cd0d6dd10f185e2fd098e371adc1ea03b72b /spec/services/projects | |
parent | a53d2c37c4934f564caa94543dd4cf5af1703e2d (diff) | |
download | gitlab-ce-2a040e2655fe0a99df61ad0a7bd0c27e68af0c38.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/projects')
-rw-r--r-- | spec/services/projects/alerting/notify_service_spec.rb | 71 |
1 files changed, 57 insertions, 14 deletions
diff --git a/spec/services/projects/alerting/notify_service_spec.rb b/spec/services/projects/alerting/notify_service_spec.rb index 925d323584e..289d812f498 100644 --- a/spec/services/projects/alerting/notify_service_spec.rb +++ b/spec/services/projects/alerting/notify_service_spec.rb @@ -25,7 +25,31 @@ describe Projects::Alerting::NotifyService do end end - shared_examples 'does not process incident issues' do |http_status:| + shared_examples 'sends notification email' do + let(:notification_service) { spy } + + it 'sends a notification for firing alerts only' do + expect(NotificationService) + .to receive(:new) + .and_return(notification_service) + + expect(notification_service) + .to receive_message_chain(:async, :prometheus_alerts_fired) + + expect(subject.status).to eq(:success) + end + end + + shared_examples 'does not process incident issues' do + it 'does not process issues' do + expect(IncidentManagement::ProcessAlertWorker) + .not_to receive(:perform_async) + + expect(subject.status).to eq(:success) + end + end + + shared_examples 'does not process incident issues due to error' do |http_status:| it 'does not process issues' do expect(IncidentManagement::ProcessAlertWorker) .not_to receive(:perform_async) @@ -54,31 +78,50 @@ describe Projects::Alerting::NotifyService do context 'with valid token' do let(:token) { alerts_service.token } + let(:incident_management_setting) { double(send_email?: email_enabled, create_issue?: issue_enabled) } + let(:email_enabled) { false } + let(:issue_enabled) { false } + + before do + allow(service) + .to receive(:incident_management_setting) + .and_return(incident_management_setting) + end + + it_behaves_like 'does not process incident issues' + + context 'issue enabled' do + let(:issue_enabled) { true } - context 'with a valid payload' do it_behaves_like 'processes incident issues', 1 - end - context 'with an invalid payload' do - before do - allow(Gitlab::Alerting::NotificationPayloadParser) - .to receive(:call) - .and_raise(Gitlab::Alerting::NotificationPayloadParser::BadPayloadError) + context 'with an invalid payload' do + before do + allow(Gitlab::Alerting::NotificationPayloadParser) + .to receive(:call) + .and_raise(Gitlab::Alerting::NotificationPayloadParser::BadPayloadError) + end + + it_behaves_like 'does not process incident issues due to error', http_status: 400 end + end + + context 'with emails turned on' do + let(:email_enabled) { true } - it_behaves_like 'does not process incident issues', http_status: 400 + it_behaves_like 'sends notification email' end end context 'with invalid token' do - it_behaves_like 'does not process incident issues', http_status: 401 + it_behaves_like 'does not process incident issues due to error', http_status: 401 end - end - context 'with deactivated Alerts Service' do - let!(:alerts_service) { create(:alerts_service, :inactive, project: project) } + context 'with deactivated Alerts Service' do + let!(:alerts_service) { create(:alerts_service, :inactive, project: project) } - it_behaves_like 'does not process incident issues', http_status: 403 + it_behaves_like 'does not process incident issues due to error', http_status: 403 + end end end end |