diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/services/incident_management/pager_duty/process_webhook_service_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/services/incident_management/pager_duty/process_webhook_service_spec.rb')
-rw-r--r-- | spec/services/incident_management/pager_duty/process_webhook_service_spec.rb | 127 |
1 files changed, 53 insertions, 74 deletions
diff --git a/spec/services/incident_management/pager_duty/process_webhook_service_spec.rb b/spec/services/incident_management/pager_duty/process_webhook_service_spec.rb index 11ce8388427..4c8aebe5fe2 100644 --- a/spec/services/incident_management/pager_duty/process_webhook_service_spec.rb +++ b/spec/services/incident_management/pager_duty/process_webhook_service_spec.rb @@ -19,92 +19,68 @@ RSpec.describe IncidentManagement::PagerDuty::ProcessWebhookService do subject(:execute) { described_class.new(project, nil, webhook_payload).execute(token) } - context 'when pagerduty_webhook feature is enabled' do - before do - stub_feature_flags(pagerduty_webhook: project) - end - - context 'when PagerDuty webhook setting is active' do - let_it_be(:incident_management_setting) { create(:project_incident_management_setting, project: project, pagerduty_active: true) } - - context 'when token is valid' do - let(:token) { incident_management_setting.pagerduty_token } + context 'when PagerDuty webhook setting is active' do + let_it_be(:incident_management_setting) { create(:project_incident_management_setting, project: project, pagerduty_active: true) } - context 'when webhook payload has acceptable size' do - it 'responds with Accepted' do - result = execute + context 'when token is valid' do + let(:token) { incident_management_setting.pagerduty_token } - expect(result).to be_success - expect(result.http_status).to eq(:accepted) - end - - it 'processes issues' do - incident_payload = ::PagerDuty::WebhookPayloadParser.call(webhook_payload).first['incident'] - - expect(::IncidentManagement::PagerDuty::ProcessIncidentWorker) - .to receive(:perform_async) - .with(project.id, incident_payload) - .once + context 'when webhook payload has acceptable size' do + it 'responds with Accepted' do + result = execute - execute - end + expect(result).to be_success + expect(result.http_status).to eq(:accepted) end - context 'when webhook payload is too big' do - let(:deep_size) { instance_double(Gitlab::Utils::DeepSize, valid?: false) } - - before do - allow(Gitlab::Utils::DeepSize) - .to receive(:new) - .with(webhook_payload, max_size: described_class::PAGER_DUTY_PAYLOAD_SIZE_LIMIT) - .and_return(deep_size) - end + it 'processes issues' do + incident_payload = ::PagerDuty::WebhookPayloadParser.call(webhook_payload).first['incident'] - it 'responds with Bad Request' do - result = execute + expect(::IncidentManagement::PagerDuty::ProcessIncidentWorker) + .to receive(:perform_async) + .with(project.id, incident_payload) + .once - expect(result).to be_error - expect(result.http_status).to eq(:bad_request) - end - - it_behaves_like 'does not process incidents' + execute end + end - context 'when webhook payload is blank' do - let(:webhook_payload) { nil } + context 'when webhook payload is too big' do + let(:deep_size) { instance_double(Gitlab::Utils::DeepSize, valid?: false) } - it 'responds with Accepted' do - result = execute + before do + allow(Gitlab::Utils::DeepSize) + .to receive(:new) + .with(webhook_payload, max_size: described_class::PAGER_DUTY_PAYLOAD_SIZE_LIMIT) + .and_return(deep_size) + end - expect(result).to be_success - expect(result.http_status).to eq(:accepted) - end + it 'responds with Bad Request' do + result = execute - it_behaves_like 'does not process incidents' + expect(result).to be_error + expect(result.http_status).to eq(:bad_request) end + + it_behaves_like 'does not process incidents' end - context 'when token is invalid' do - let(:token) { 'invalid-token' } + context 'when webhook payload is blank' do + let(:webhook_payload) { nil } - it 'responds with Unauthorized' do + it 'responds with Accepted' do result = execute - expect(result).to be_error - expect(result.http_status).to eq(:unauthorized) + expect(result).to be_success + expect(result.http_status).to eq(:accepted) end it_behaves_like 'does not process incidents' end end - context 'when both tokens are nil' do - let_it_be(:incident_management_setting) { create(:project_incident_management_setting, project: project, pagerduty_active: false) } - let(:token) { nil } - - before do - incident_management_setting.update_column(:pagerduty_active, true) - end + context 'when token is invalid' do + let(:token) { 'invalid-token' } it 'responds with Unauthorized' do result = execute @@ -115,25 +91,28 @@ RSpec.describe IncidentManagement::PagerDuty::ProcessWebhookService do it_behaves_like 'does not process incidents' end + end - context 'when PagerDuty webhook setting is not active' do - let_it_be(:incident_management_setting) { create(:project_incident_management_setting, project: project, pagerduty_active: false) } + context 'when both tokens are nil' do + let_it_be(:incident_management_setting) { create(:project_incident_management_setting, project: project, pagerduty_active: false) } + let(:token) { nil } - it 'responds with Forbidden' do - result = execute + before do + incident_management_setting.update_column(:pagerduty_active, true) + end - expect(result).to be_error - expect(result.http_status).to eq(:forbidden) - end + it 'responds with Unauthorized' do + result = execute - it_behaves_like 'does not process incidents' + expect(result).to be_error + expect(result.http_status).to eq(:unauthorized) end + + it_behaves_like 'does not process incidents' end - context 'when pagerduty_webhook feature is disabled' do - before do - stub_feature_flags(pagerduty_webhook: false) - end + context 'when PagerDuty webhook setting is not active' do + let_it_be(:incident_management_setting) { create(:project_incident_management_setting, project: project, pagerduty_active: false) } it 'responds with Forbidden' do result = execute |