diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 18:40:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 18:40:28 +0300 |
commit | b595cb0c1dec83de5bdee18284abe86614bed33b (patch) | |
tree | 8c3d4540f193c5ff98019352f554e921b3a41a72 /spec/services/incident_management/timeline_events | |
parent | 2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff) |
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'spec/services/incident_management/timeline_events')
-rw-r--r-- | spec/services/incident_management/timeline_events/create_service_spec.rb | 101 | ||||
-rw-r--r-- | spec/services/incident_management/timeline_events/update_service_spec.rb | 6 |
2 files changed, 105 insertions, 2 deletions
diff --git a/spec/services/incident_management/timeline_events/create_service_spec.rb b/spec/services/incident_management/timeline_events/create_service_spec.rb index 133a644f243..a4e928b98f4 100644 --- a/spec/services/incident_management/timeline_events/create_service_spec.rb +++ b/spec/services/incident_management/timeline_events/create_service_spec.rb @@ -132,6 +132,40 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do it 'creates a system note' do expect { execute }.to change { incident.notes.reload.count }.by(1) end + + context 'with auto_created param' do + let(:args) do + { + note: 'note', + occurred_at: Time.current, + action: 'new comment', + promoted_from_note: comment, + auto_created: auto_created + } + end + + context 'when auto_created is true' do + let(:auto_created) { true } + + it 'does not create a system note' do + expect { execute }.not_to change { incident.notes.reload.count } + end + + context 'when user does not have permissions' do + let(:current_user) { user_without_permissions } + + it_behaves_like 'success response' + end + end + + context 'when auto_created is false' do + let(:auto_created) { false } + + it 'creates a system note' do + expect { execute }.to change { incident.notes.reload.count }.by(1) + end + end + end end context 'when incident_timeline feature flag is disabled' do @@ -144,4 +178,71 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do end end end + + describe 'automatically created timeline events' do + shared_examples 'successfully created timeline event' do + it 'creates a timeline event', :aggregate_failures do + expect(execute).to be_success + + result = execute.payload[:timeline_event] + expect(result).to be_a(::IncidentManagement::TimelineEvent) + expect(result.author).to eq(current_user) + expect(result.incident).to eq(incident) + expect(result.project).to eq(project) + expect(result.note).to eq(expected_note) + expect(result.editable).to eq(false) + expect(result.action).to eq(expected_action) + end + + it_behaves_like 'an incident management tracked event', :incident_management_timeline_event_created + + it 'successfully creates a database record', :aggregate_failures do + expect { execute }.to change { ::IncidentManagement::TimelineEvent.count }.by(1) + end + + it 'does not create a system note' do + expect { execute }.not_to change { incident.notes.reload.count } + end + end + + describe '.create_incident' do + subject(:execute) { described_class.create_incident(incident, current_user) } + + let(:expected_note) { "@#{current_user.username} created the incident" } + let(:expected_action) { 'issues' } + + it_behaves_like 'successfully created timeline event' + end + + describe '.reopen_incident' do + subject(:execute) { described_class.reopen_incident(incident, current_user) } + + let(:expected_note) { "@#{current_user.username} reopened the incident" } + let(:expected_action) { 'issues' } + + it_behaves_like 'successfully created timeline event' + end + + describe '.resolve_incident' do + subject(:execute) { described_class.resolve_incident(incident, current_user) } + + let(:expected_note) { "@#{current_user.username} resolved the incident" } + let(:expected_action) { 'status' } + + it_behaves_like 'successfully created timeline event' + end + + describe '.change_incident_status' do + subject(:execute) { described_class.change_incident_status(incident, current_user, escalation_status) } + + let(:escalation_status) do + instance_double('IncidentManagement::IssuableEscalationStatus', status_name: 'acknowledged') + end + + let(:expected_note) { "@#{current_user.username} changed the incident status to **Acknowledged**" } + let(:expected_action) { 'status' } + + it_behaves_like 'successfully created timeline event' + end + end end diff --git a/spec/services/incident_management/timeline_events/update_service_spec.rb b/spec/services/incident_management/timeline_events/update_service_spec.rb index 3da533fb2a6..728f2fa3e9d 100644 --- a/spec/services/incident_management/timeline_events/update_service_spec.rb +++ b/spec/services/incident_management/timeline_events/update_service_spec.rb @@ -146,7 +146,8 @@ RSpec.describe IncidentManagement::TimelineEvents::UpdateService do create(:incident_management_timeline_event, :non_editable, project: project, incident: incident) end - it_behaves_like 'error response', 'You cannot edit this timeline event.' + it_behaves_like 'error response', + 'You have insufficient permissions to manage timeline events for this incident' end end @@ -155,7 +156,8 @@ RSpec.describe IncidentManagement::TimelineEvents::UpdateService do project.add_reporter(user) end - it_behaves_like 'error response', 'You have insufficient permissions to manage timeline events for this incident' + it_behaves_like 'error response', + 'You have insufficient permissions to manage timeline events for this incident' end end end |