diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/gitlab/incident_management/pager_duty | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/gitlab/incident_management/pager_duty')
-rw-r--r-- | spec/lib/gitlab/incident_management/pager_duty/incident_issue_description_spec.rb | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/spec/lib/gitlab/incident_management/pager_duty/incident_issue_description_spec.rb b/spec/lib/gitlab/incident_management/pager_duty/incident_issue_description_spec.rb new file mode 100644 index 00000000000..9a55e21d031 --- /dev/null +++ b/spec/lib/gitlab/incident_management/pager_duty/incident_issue_description_spec.rb @@ -0,0 +1,97 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require 'timecop' + +RSpec.describe Gitlab::IncidentManagement::PagerDuty::IncidentIssueDescription do + describe '#to_s' do + let(:markdown_line_break) { ' ' } + let(:created_at) { '2017-09-26T15:14:36Z' } + let(:assignees) do + [{ 'summary' => 'Laura Haley', 'url' => 'https://webdemo.pagerduty.com/users/P553OPV' }] + end + let(:impacted_services) do + [{ 'summary' => 'Production XDB Cluster', 'url' => 'https://webdemo.pagerduty.com/services/PN49J75' }] + end + let(:incident_payload) do + { + 'url' => 'https://webdemo.pagerduty.com/incidents/PRORDTY', + 'incident_number' => 33, + 'title' => 'My new incident', + 'status' => 'triggered', + 'created_at' => created_at, + 'urgency' => 'high', + 'incident_key' => 'SOME-KEY', + 'assignees' => assignees, + 'impacted_services' => impacted_services + } + end + + subject(:to_s) { described_class.new(incident_payload).to_s } + + it 'returns description' do + expect(to_s).to eq( + <<~MARKDOWN.chomp + **Incident:** [My new incident](https://webdemo.pagerduty.com/incidents/PRORDTY)#{markdown_line_break} + **Incident number:** 33#{markdown_line_break} + **Urgency:** high#{markdown_line_break} + **Status:** triggered#{markdown_line_break} + **Incident key:** SOME-KEY#{markdown_line_break} + **Created at:** 26 September 2017, 3:14PM (UTC)#{markdown_line_break} + **Assignees:** [Laura Haley](https://webdemo.pagerduty.com/users/P553OPV)#{markdown_line_break} + **Impacted services:** [Production XDB Cluster](https://webdemo.pagerduty.com/services/PN49J75) + MARKDOWN + ) + end + + context 'when created_at is missing' do + let(:created_at) { nil } + + it 'description contains current time in UTC' do + Timecop.freeze do + now = Time.current.utc.strftime('%d %B %Y, %-l:%M%p (%Z)') + + expect(to_s).to include( + <<~MARKDOWN.chomp + **Created at:** #{now}#{markdown_line_break} + MARKDOWN + ) + end + end + end + + context 'when there are several assignees' do + let(:assignees) do + [ + { 'summary' => 'Laura Haley', 'url' => 'https://laura.pagerduty.com' }, + { 'summary' => 'John Doe', 'url' => 'https://john.pagerduty.com' } + ] + end + + it 'assignees is a list of links' do + expect(to_s).to include( + <<~MARKDOWN.chomp + **Assignees:** [Laura Haley](https://laura.pagerduty.com), [John Doe](https://john.pagerduty.com)#{markdown_line_break} + MARKDOWN + ) + end + end + + context 'when there are several impacted services' do + let(:impacted_services) do + [ + { 'summary' => 'XDB Cluster', 'url' => 'https://xdb.pagerduty.com' }, + { 'summary' => 'BRB Cluster', 'url' => 'https://brb.pagerduty.com' } + ] + end + + it 'impacted services is a list of links' do + expect(to_s).to include( + <<~MARKDOWN.chomp + **Impacted services:** [XDB Cluster](https://xdb.pagerduty.com), [BRB Cluster](https://brb.pagerduty.com) + MARKDOWN + ) + end + end + end +end |