alert_presenter_spec.rb 1.79 KB
Newer Older
1 2 3 4 5 6
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe AlertManagement::AlertPresenter do
  let_it_be(:project) { create(:project) }
Sean Arnold's avatar
Sean Arnold committed
7

Sean Arnold's avatar
Sean Arnold committed
8
  let_it_be(:generic_payload) do
9 10 11
    {
      'title' => 'Alert title',
      'start_time' => '2020-04-27T10:10:22.265949279Z',
12 13
      'custom' => { 'param' => 73 },
      'runbook' => 'https://runbook.com'
14 15
    }
  end
Sean Arnold's avatar
Sean Arnold committed
16

17
  let_it_be(:alert) do
Sean Arnold's avatar
Sean Arnold committed
18
    create(:alert_management_alert, :with_description, :with_host, :with_service, :with_monitoring_tool, project: project, payload: generic_payload)
19
  end
20

Sean Arnold's avatar
Sean Arnold committed
21
  let(:alert_url) { "http://localhost/#{project.full_path}/-/alert_management/#{alert.iid}/details" }
22

23
  subject(:presenter) { described_class.new(alert) }
24 25 26 27

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

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

33 34 35 36
          **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}
37
          **Hosts:** #{alert.hosts.join(' ')}#{markdown_line_break}
38 39
          **Description:** #{alert.description}#{markdown_line_break}
          **GitLab alert:** #{alert_url}
40

41
          #### Alert Details
42

43 44
          **custom.param:** 73#{markdown_line_break}
          **runbook:** https://runbook.com
45 46
        MARKDOWN
      )
47 48
    end
  end
49 50 51 52 53 54

  describe '#metrics_dashboard_url' do
    it 'is not defined' do
      expect(presenter.metrics_dashboard_url).to be_nil
    end
  end
55 56 57 58 59 60

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