summaryrefslogtreecommitdiff
path: root/spec/presenters/alert_management/alert_presenter_spec.rb
blob: 394007a802fcc8c47656ff8916cc52ac23462a31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe AlertManagement::AlertPresenter do
  let_it_be(:project) { create(:project) }

  let_it_be(:generic_payload) do
    {
      'title' => 'Alert title',
      'start_time' => '2020-04-27T10:10:22.265949279Z',
      'custom' => { 'param' => 73 },
      'runbook' => 'https://runbook.com'
    }
  end

  let_it_be(:alert) do
    create(:alert_management_alert, :with_description, :with_host, :with_service, :with_monitoring_tool, project: project, payload: generic_payload)
  end

  let(:alert_url) { "http://localhost/#{project.full_path}/-/alert_management/#{alert.iid}/details" }

  subject(:presenter) { described_class.new(alert) }

  describe '#issue_description' do
    let(:markdown_line_break) { '  ' }

    it 'returns an alert issue description' do
      expect(presenter.issue_description).to eq(
        <<~MARKDOWN.chomp
          #### Summary

          **Start time:** #{presenter.start_time}#{markdown_line_break}
          **Severity:** #{presenter.severity}#{markdown_line_break}
          **Service:** #{alert.service}#{markdown_line_break}
          **Monitoring tool:** #{alert.monitoring_tool}#{markdown_line_break}
          **Hosts:** #{alert.hosts.join(' ')}#{markdown_line_break}
          **Description:** #{alert.description}#{markdown_line_break}
          **GitLab alert:** #{alert_url}

          #### Alert Details

          **custom.param:** 73#{markdown_line_break}
          **runbook:** https://runbook.com
        MARKDOWN
      )
    end
  end

  describe '#metrics_dashboard_url' do
    it 'is not defined' do
      expect(presenter.metrics_dashboard_url).to be_nil
    end
  end

  describe '#runbook' do
    it 'shows the runbook from the payload' do
      expect(presenter.runbook).to eq('https://runbook.com')
    end
  end

  describe '#details_url' do
    it 'returns the details URL' do
      expect(presenter.details_url).to match(%r{#{project.web_url}/-/alert_management/#{alert.iid}/details})
    end
  end
end