summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/services/alert_management/alert_processing/incident_creation_shared_examples.rb
blob: 6becc3dc071731a365e68e044f8a7d5fb50a5fa7 (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
# frozen_string_literal: true

# Expects usage of 'incident management settings enabled' context.
#
# This shared_example includes the following option:
# - with_issue: includes a test for when the defined `alert` has an associated issue
#
# This shared_example requires the following variables:
# - `alert`, required if :with_issue is true
RSpec.shared_examples 'processes incident issues if enabled' do |with_issue: false|
  include_examples 'processes incident issues', with_issue: with_issue

  context 'with incident setting disabled' do
    let(:create_issue) { false }

    it_behaves_like 'does not process incident issues'
  end
end

RSpec.shared_examples 'processes incident issues' do |with_issue: false|
  before do
    allow_next_instance_of(AlertManagement::Alert) do |alert|
      allow(alert).to receive(:execute_integrations)
    end
  end

  specify do
    expect(IncidentManagement::ProcessAlertWorkerV2)
      .to receive(:perform_async)
      .with(kind_of(Integer))

    Sidekiq::Testing.inline! do
      expect(subject).to be_success
    end
  end

  context 'with issue', if: with_issue do
    before do
      alert.update!(issue: create(:issue, project: project))
    end

    it_behaves_like 'does not process incident issues'
  end
end

RSpec.shared_examples 'does not process incident issues' do
  specify do
    expect(IncidentManagement::ProcessAlertWorkerV2).not_to receive(:perform_async)

    subject
  end
end