Welcome to mirror list, hosted at ThFree Co, Russian Federation.

system_notes_shared_examples.rb « alert_processing « alert_management « services « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2d0815ba27cdc9a3f9937566a4acc8d448081812 (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
# frozen_string_literal: true

# This shared_example includes the following option:
# - notes: any of [:new_alert, :recovery_alert, :resolve_alert].
#          Represents which notes are expected to be created.
#
# This shared_example requires the following variables:
# - `source` (optional), the monitoring tool or integration name
#                        expected in the applicable system notes
RSpec.shared_examples 'creates expected system notes for alert' do |*notes|
  let(:expected_note_count) { expected_notes.length }
  let(:new_notes) { Note.last(expected_note_count).pluck(:note) }
  let(:expected_notes) do
    {
      new_alert: source,
      recovery_alert: source,
      resolve_alert: 'Resolved'
    }.slice(*notes)
  end

  it "for #{notes.join(', ')}" do
    expect { subject }.to change { Note.count }.by(expected_note_count)

    expected_notes.each_value.with_index do |value, index|
      expect(new_notes[index]).to include(value)
    end
  end
end

RSpec.shared_examples 'does not create a system note for alert' do
  specify do
    expect { subject }.not_to change { Note.count }
  end
end