diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /spec/lib/pager_duty/webhook_payload_parser_spec.rb | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'spec/lib/pager_duty/webhook_payload_parser_spec.rb')
-rw-r--r-- | spec/lib/pager_duty/webhook_payload_parser_spec.rb | 90 |
1 files changed, 35 insertions, 55 deletions
diff --git a/spec/lib/pager_duty/webhook_payload_parser_spec.rb b/spec/lib/pager_duty/webhook_payload_parser_spec.rb index 647f19e3d3a..1606d03c746 100644 --- a/spec/lib/pager_duty/webhook_payload_parser_spec.rb +++ b/spec/lib/pager_duty/webhook_payload_parser_spec.rb @@ -10,23 +10,27 @@ RSpec.describe PagerDuty::WebhookPayloadParser do let(:triggered_event) do { - 'event' => 'incident.trigger', + 'event' => 'incident.triggered', 'incident' => { - 'url' => 'https://webdemo.pagerduty.com/incidents/PRORDTY', - 'incident_number' => 33, - 'title' => 'My new incident', + 'url' => 'https://gitlab-1.pagerduty.com/incidents/Q1XZUF87W1HB5A', + 'incident_number' => 2, + 'title' => '[FILTERED]', 'status' => 'triggered', - 'created_at' => '2017-09-26T15:14:36Z', + 'created_at' => '2022-11-30T08:46:19Z', 'urgency' => 'high', - 'incident_key' => nil, - 'assignees' => [{ - 'summary' => 'Laura Haley', - 'url' => 'https://webdemo.pagerduty.com/users/P553OPV' - }], - 'impacted_services' => [{ - 'summary' => 'Production XDB Cluster', - 'url' => 'https://webdemo.pagerduty.com/services/PN49J75' - }] + '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' + } } } end @@ -37,74 +41,50 @@ RSpec.describe PagerDuty::WebhookPayloadParser do let(:payload) { Gitlab::Json.parse(fixture_file) } it 'returns parsed payload' do - is_expected.to eq([triggered_event]) + is_expected.to eq(triggered_event) end context 'when assignments summary and html_url are blank' do before do - payload['messages'].each do |m| - m['incident']['assignments'] = [{ 'assignee' => { 'summary' => '', 'html_url' => '' } }] - end + payload['event']['data']['assignees'] = [{ 'summary' => '', 'html_url' => '' }] end it 'returns parsed payload with blank assignees' do - assignees = parse.map { |events| events['incident'].slice('assignees') } + assignees = parse['incident'].slice('assignees') - expect(assignees).to eq([{ 'assignees' => [] }]) + expect(assignees).to eq({ 'assignees' => [] }) end end context 'when impacted_services summary and html_url are blank' do before do - payload['messages'].each do |m| - m['incident']['impacted_services'] = [{ 'summary' => '', 'html_url' => '' }] - end + payload['event']['data']['service'] = { 'summary' => '', 'html_url' => '' } end - it 'returns parsed payload with blank assignees' do - assignees = parse.map { |events| events['incident'].slice('impacted_services') } + it 'returns parsed payload with blank impacted service' do + assignees = parse['incident'].slice('impacted_service') - expect(assignees).to eq([{ 'impacted_services' => [] }]) + expect(assignees).to eq({ 'impacted_service' => {} }) end end end context 'when payload schema is invalid' do - let(:payload) { { 'messages' => [{ 'event' => 'incident.trigger' }] } } + let(:payload) { { 'event' => 'incident.triggered' } } - it 'returns payload with blank incidents' do - is_expected.to eq([]) + it 'returns payload with blank incident' do + is_expected.to eq({}) end end - context 'when payload consists of two messages' do - context 'when one of the messages has no incident data' do - let(:payload) do - valid_payload = Gitlab::Json.parse(fixture_file) - event = { 'event' => 'incident.trigger' } - valid_payload['messages'] = valid_payload['messages'].append(event) - valid_payload - end - - it 'returns parsed payload with valid events only' do - is_expected.to eq([triggered_event]) - end + context 'when event is unknown' do + let(:payload) do + valid_payload = Gitlab::Json.parse(fixture_file) + valid_payload['event'] = 'incident.unknown' end - context 'when one of the messages has unknown event' do - let(:payload) do - valid_payload = Gitlab::Json.parse(fixture_file) - event = { 'event' => 'incident.unknown', 'incident' => valid_payload['messages'].first['incident'] } - valid_payload['messages'] = valid_payload['messages'].append(event) - valid_payload - end - - it 'returns parsed payload' do - unknown_event = triggered_event.dup - unknown_event['event'] = 'incident.unknown' - - is_expected.to contain_exactly(triggered_event, unknown_event) - end + it 'returns empty payload' do + is_expected.to be_empty end end end |