diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-29 03:08:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-29 03:08:58 +0300 |
commit | 5631ece67fad35d85fc87d08b76345a44062da2a (patch) | |
tree | 5a956d7dfea3f785887d5d3525b16ea1765d334f /spec/workers/incident_management | |
parent | 416e7f953873240da18150fe1984201b7d96e1fe (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/incident_management')
-rw-r--r-- | spec/workers/incident_management/process_alert_worker_spec.rb | 64 |
1 files changed, 26 insertions, 38 deletions
diff --git a/spec/workers/incident_management/process_alert_worker_spec.rb b/spec/workers/incident_management/process_alert_worker_spec.rb index ff138dd6885..75696d15ab8 100644 --- a/spec/workers/incident_management/process_alert_worker_spec.rb +++ b/spec/workers/incident_management/process_alert_worker_spec.rb @@ -7,35 +7,31 @@ RSpec.describe IncidentManagement::ProcessAlertWorker do let_it_be(:settings) { create(:project_incident_management_setting, project: project, create_issue: true) } describe '#perform' do - let(:alert_management_alert_id) { nil } - let(:alert_payload) do - { - 'annotations' => { 'title' => 'title' }, - 'startsAt' => Time.now.rfc3339 - } - end - - let(:created_issue) { Issue.last } + let_it_be(:started_at) { Time.now.rfc3339 } + let_it_be(:payload) { { 'title' => 'title', 'start_time' => started_at } } + let_it_be(:parsed_payload) { Gitlab::Alerting::NotificationPayloadParser.call(payload, project) } + let_it_be(:alert) { create(:alert_management_alert, project: project, payload: payload, started_at: started_at) } + let(:created_issue) { Issue.last! } - subject { described_class.new.perform(project.id, alert_payload, alert_management_alert_id) } + subject { described_class.new.perform(nil, nil, alert.id) } before do allow(IncidentManagement::CreateIssueService) - .to receive(:new).with(project, alert_payload) + .to receive(:new).with(alert.project, parsed_payload) .and_call_original end it 'creates an issue' do expect(IncidentManagement::CreateIssueService) - .to receive(:new).with(project, alert_payload) + .to receive(:new).with(alert.project, parsed_payload) expect { subject }.to change { Issue.count }.by(1) end - context 'with invalid project' do - let(:invalid_project_id) { non_existing_record_id } + context 'with invalid alert' do + let(:invalid_alert_id) { non_existing_record_id } - subject { described_class.new.perform(invalid_project_id, alert_payload) } + subject { described_class.new.perform(nil, nil, invalid_alert_id) } it 'does not create issues' do expect(IncidentManagement::CreateIssueService).not_to receive(:new) @@ -44,16 +40,8 @@ RSpec.describe IncidentManagement::ProcessAlertWorker do end end - context 'when alert_management_alert_id is present' do - let!(:alert) { create(:alert_management_alert, project: project) } - let(:alert_management_alert_id) { alert.id } - + context 'with valid alert' do before do - allow(AlertManagement::Alert) - .to receive(:find_by_id) - .with(alert_management_alert_id) - .and_return(alert) - allow(Gitlab::AppLogger).to receive(:warn).and_call_original end @@ -69,24 +57,24 @@ RSpec.describe IncidentManagement::ProcessAlertWorker do expect(Gitlab::AppLogger).not_to have_received(:warn) end - end - context 'when alert cannot be updated' do - let(:alert) { create(:alert_management_alert, :with_validation_errors, project: project) } + context 'when alert cannot be updated' do + let_it_be(:alert) { create(:alert_management_alert, :with_validation_errors, project: project, payload: payload) } - it 'updates AlertManagement::Alert#issue_id' do - expect { subject }.not_to change { alert.reload.issue_id } - end + it 'updates AlertManagement::Alert#issue_id' do + expect { subject }.not_to change { alert.reload.issue_id } + end - it 'logs a warning' do - subject + it 'logs a warning' do + subject - expect(Gitlab::AppLogger).to have_received(:warn).with( - message: 'Cannot link an Issue with Alert', - issue_id: created_issue.id, - alert_id: alert_management_alert_id, - alert_errors: { hosts: ['hosts array is over 255 chars'] } - ) + expect(Gitlab::AppLogger).to have_received(:warn).with( + message: 'Cannot link an Issue with Alert', + issue_id: created_issue.id, + alert_id: alert.id, + alert_errors: { hosts: ['hosts array is over 255 chars'] } + ) + end end end end |