diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-03 18:08:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-03 18:08:05 +0300 |
commit | 3dcdea950204629bfcdcc9c0db250adab3b5c1ff (patch) | |
tree | a793950dae379d86284de61350ea12a70b49f8d7 /spec/workers/incident_management | |
parent | 607646ef528729ebb30e593bce0a0447304fccc7 (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 | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/spec/workers/incident_management/process_alert_worker_spec.rb b/spec/workers/incident_management/process_alert_worker_spec.rb index 08acee264f8..81e55083629 100644 --- a/spec/workers/incident_management/process_alert_worker_spec.rb +++ b/spec/workers/incident_management/process_alert_worker_spec.rb @@ -7,40 +7,39 @@ describe IncidentManagement::ProcessAlertWorker do describe '#perform' do let(:alert_management_alert_id) { nil } - let(:alert_payload) { { alert: 'payload' } } - let(:new_issue) { create(:issue, project: project) } - let(:create_issue_service) { instance_double(IncidentManagement::CreateIssueService, execute: new_issue) } + let(:alert_payload) do + { + 'annotations' => { 'title' => 'title' }, + 'startsAt' => Time.now.rfc3339 + } + end + + let(:created_issue) { Issue.last } subject { described_class.new.perform(project.id, alert_payload, alert_management_alert_id) } before do allow(IncidentManagement::CreateIssueService) .to receive(:new).with(project, alert_payload) - .and_return(create_issue_service) + .and_call_original end - it 'calls create issue service' do - expect(Project).to receive(:find_by_id).and_call_original - + it 'creates an issue' do expect(IncidentManagement::CreateIssueService) .to receive(:new).with(project, alert_payload) - .and_return(create_issue_service) - expect(create_issue_service).to receive(:execute) - - subject + expect { subject }.to change { Issue.count }.by(1) end context 'with invalid project' do - let(:invalid_project_id) { 0 } + let(:invalid_project_id) { non_existing_record_id } subject { described_class.new.perform(invalid_project_id, alert_payload) } it 'does not create issues' do - expect(Project).to receive(:find_by_id).and_call_original expect(IncidentManagement::CreateIssueService).not_to receive(:new) - subject + expect { subject }.not_to change { Issue.count } end end @@ -59,7 +58,9 @@ describe IncidentManagement::ProcessAlertWorker do context 'when alert can be updated' do it 'updates AlertManagement::Alert#issue_id' do - expect { subject }.to change { alert.reload.issue_id }.to(new_issue.id) + subject + + expect(alert.reload.issue_id).to eq(created_issue.id) end it 'does not write a warning to log' do @@ -76,12 +77,12 @@ describe IncidentManagement::ProcessAlertWorker do expect { subject }.not_to change { alert.reload.issue_id } end - it 'writes a worning to log' do + it 'logs a warning' do subject expect(Gitlab::AppLogger).to have_received(:warn).with( message: 'Cannot link an Issue with Alert', - issue_id: new_issue.id, + issue_id: created_issue.id, alert_id: alert_management_alert_id, alert_errors: { hosts: ['hosts array is over 255 chars'] } ) |