debian-mirror-gitlab/spec/requests/projects/incident_management/pagerduty_incidents_spec.rb

37 lines
1.3 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'PagerDuty webhook' do
let_it_be(:project) { create(:project) }
describe 'POST /incidents/pagerduty' do
let(:payload) { Gitlab::Json.parse(fixture_file('pager_duty/webhook_incident_trigger.json')) }
let(:webhook_processor_class) { ::IncidentManagement::PagerDuty::ProcessWebhookService }
let(:webhook_processor) { instance_double(webhook_processor_class) }
def make_request
headers = { 'Content-Type' => 'application/json' }
2020-10-24 23:57:45 +05:30
post project_incidents_integrations_pagerduty_url(project, token: 'VALID-TOKEN'), params: payload.to_json, headers: headers
2020-07-28 23:09:34 +05:30
end
before do
allow(webhook_processor_class).to receive(:new).and_return(webhook_processor)
allow(webhook_processor).to receive(:execute).and_return(ServiceResponse.success(http_status: :accepted))
end
it 'calls PagerDuty webhook processor with correct parameters' do
make_request
2021-03-08 18:12:59 +05:30
expect(webhook_processor_class).to have_received(:new).with(project, payload)
2020-07-28 23:09:34 +05:30
expect(webhook_processor).to have_received(:execute).with('VALID-TOKEN')
end
it 'responds with 202 Accepted' do
make_request
expect(response).to have_gitlab_http_status(:accepted)
end
end
end