debian-mirror-gitlab/spec/lib/pager_duty/webhook_payload_parser_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
2.6 KiB
Ruby
Raw Permalink Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
2021-04-17 20:07:23 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe PagerDuty::WebhookPayloadParser do
describe '.call' do
let(:fixture_file) do
File.read(File.join(File.dirname(__FILE__), '../../fixtures/pager_duty/webhook_incident_trigger.json'))
end
2021-01-03 14:25:43 +05:30
let(:triggered_event) do
{
2023-03-04 22:38:38 +05:30
'event' => 'incident.triggered',
2021-01-03 14:25:43 +05:30
'incident' => {
2023-03-04 22:38:38 +05:30
'url' => 'https://gitlab-1.pagerduty.com/incidents/Q1XZUF87W1HB5A',
'incident_number' => 2,
'title' => '[FILTERED]',
2021-01-03 14:25:43 +05:30
'status' => 'triggered',
2023-03-04 22:38:38 +05:30
'created_at' => '2022-11-30T08:46:19Z',
2021-01-03 14:25:43 +05:30
'urgency' => 'high',
2023-03-04 22:38:38 +05:30
'incident_key' => '[FILTERED]',
'assignees' =>
[
{
'summary' => 'Rajendra Kadam',
'url' => 'https://gitlab-1.pagerduty.com/users/PIN0B5C'
}
],
'impacted_service' =>
{
'summary' => 'Test service',
'url' => 'https://gitlab-1.pagerduty.com/services/PK6IKMT'
}
2021-01-03 14:25:43 +05:30
}
}
end
2020-07-28 23:09:34 +05:30
subject(:parse) { described_class.call(payload) }
context 'when payload is a correct PagerDuty payload' do
let(:payload) { Gitlab::Json.parse(fixture_file) }
it 'returns parsed payload' do
2023-03-04 22:38:38 +05:30
is_expected.to eq(triggered_event)
2020-07-28 23:09:34 +05:30
end
context 'when assignments summary and html_url are blank' do
before do
2023-03-04 22:38:38 +05:30
payload['event']['data']['assignees'] = [{ 'summary' => '', 'html_url' => '' }]
2020-07-28 23:09:34 +05:30
end
it 'returns parsed payload with blank assignees' do
2023-03-04 22:38:38 +05:30
assignees = parse['incident'].slice('assignees')
2020-07-28 23:09:34 +05:30
2023-03-04 22:38:38 +05:30
expect(assignees).to eq({ 'assignees' => [] })
2020-07-28 23:09:34 +05:30
end
end
context 'when impacted_services summary and html_url are blank' do
before do
2023-03-04 22:38:38 +05:30
payload['event']['data']['service'] = { 'summary' => '', 'html_url' => '' }
2020-07-28 23:09:34 +05:30
end
2023-03-04 22:38:38 +05:30
it 'returns parsed payload with blank impacted service' do
assignees = parse['incident'].slice('impacted_service')
2020-07-28 23:09:34 +05:30
2023-03-04 22:38:38 +05:30
expect(assignees).to eq({ 'impacted_service' => {} })
2020-07-28 23:09:34 +05:30
end
end
end
2021-01-03 14:25:43 +05:30
context 'when payload schema is invalid' do
2023-03-04 22:38:38 +05:30
let(:payload) { { 'event' => 'incident.triggered' } }
2020-07-28 23:09:34 +05:30
2023-03-04 22:38:38 +05:30
it 'returns payload with blank incident' do
is_expected.to eq({})
2021-01-03 14:25:43 +05:30
end
end
2023-03-04 22:38:38 +05:30
context 'when event is unknown' do
let(:payload) do
valid_payload = Gitlab::Json.parse(fixture_file)
valid_payload['event'] = 'incident.unknown'
2021-01-03 14:25:43 +05:30
end
2023-03-04 22:38:38 +05:30
it 'returns empty payload' do
is_expected.to be_empty
2020-07-28 23:09:34 +05:30
end
end
end
end