blob: 3add5485fca2b6bc2144eb68edbb311e01753bfb (
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
|
# frozen_string_literal: true
# Expects usage of 'incident settings enabled' context.
#
# This shared_example requires the following variables:
# - `alert`, alert for which related incidents should be closed
# - `project`, project of the alert
RSpec.shared_examples 'closes related incident if enabled' do
context 'with incident' do
before do
alert.update!(issue: create(:incident, project: project))
end
specify do
expect { Sidekiq::Testing.inline! { subject } }
.to change { alert.issue.reload.closed? }.from(false).to(true)
.and change(ResourceStateEvent, :count).by(1)
end
end
context 'without incident' do
specify do
expect(::IncidentManagement::CloseIncidentWorker).not_to receive(:perform_async)
subject
end
end
context 'with incident setting disabled' do
let(:auto_close_incident) { false }
it_behaves_like 'does not close related incident'
end
end
RSpec.shared_examples 'does not close related incident' do
context 'with incident' do
before do
alert.update!(issue: create(:incident, project: project))
end
specify do
expect { Sidekiq::Testing.inline! { subject } }
.to not_change { alert.issue.reload.state }
.and not_change(ResourceStateEvent, :count)
end
end
context 'without incident' do
specify do
expect(::IncidentManagement::CloseIncidentWorker).not_to receive(:perform_async)
subject
end
end
end
|