diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/services/incident_management/timeline_events | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/services/incident_management/timeline_events')
3 files changed, 54 insertions, 5 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 38ce15e74f1..133a644f243 100644 --- a/spec/services/incident_management/timeline_events/create_service_spec.rb +++ b/spec/services/incident_management/timeline_events/create_service_spec.rb @@ -18,6 +18,7 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do } end + let(:editable) { false } let(:current_user) { user_with_permissions } let(:service) { described_class.new(incident, current_user, args) } @@ -32,6 +33,8 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do expect(execute).to be_error expect(execute.message).to eq(message) end + + it_behaves_like 'does not track incident management event', :incident_management_timeline_event_created end shared_examples 'success response' do @@ -45,7 +48,10 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do expect(result.project).to eq(project) expect(result.note).to eq(args[:note]) expect(result.promoted_from_note).to eq(comment) + expect(result.editable).to eq(editable) end + + it_behaves_like 'an incident management tracked event', :incident_management_timeline_event_created end subject(:execute) { service.execute } @@ -90,6 +96,30 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do end end + context 'with editable param' do + let(:args) do + { + note: 'note', + occurred_at: Time.current, + action: 'new comment', + promoted_from_note: comment, + editable: editable + } + end + + context 'when editable is true' do + let(:editable) { true } + + it_behaves_like 'success response' + end + + context 'when editable is false' do + let(:editable) { false } + + it_behaves_like 'success response' + end + end + it 'successfully creates a database record', :aggregate_failures do expect { execute }.to change { ::IncidentManagement::TimelineEvent.count }.by(1) end diff --git a/spec/services/incident_management/timeline_events/destroy_service_spec.rb b/spec/services/incident_management/timeline_events/destroy_service_spec.rb index 01daee2b749..09026f87116 100644 --- a/spec/services/incident_management/timeline_events/destroy_service_spec.rb +++ b/spec/services/incident_management/timeline_events/destroy_service_spec.rb @@ -24,6 +24,8 @@ RSpec.describe IncidentManagement::TimelineEvents::DestroyService do expect(execute).to be_error expect(execute.message).to eq(message) end + + it_behaves_like 'does not track incident management event', :incident_management_timeline_event_deleted end subject(:execute) { service.execute } @@ -49,12 +51,16 @@ RSpec.describe IncidentManagement::TimelineEvents::DestroyService do it_behaves_like 'error response', 'Note cannot be removed' end - it 'successfully returns the timeline event', :aggregate_failures do - expect(execute).to be_success + context 'success response' do + it 'successfully returns the timeline event', :aggregate_failures do + expect(execute).to be_success + + result = execute.payload[:timeline_event] + expect(result).to be_a(::IncidentManagement::TimelineEvent) + expect(result.id).to eq(timeline_event.id) + end - result = execute.payload[:timeline_event] - expect(result).to be_a(::IncidentManagement::TimelineEvent) - expect(result.id).to eq(timeline_event.id) + it_behaves_like 'an incident management tracked event', :incident_management_timeline_event_deleted end context 'when incident_timeline feature flag is enabled' do 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 8bc0e5ce0ed..3da533fb2a6 100644 --- a/spec/services/incident_management/timeline_events/update_service_spec.rb +++ b/spec/services/incident_management/timeline_events/update_service_spec.rb @@ -10,6 +10,7 @@ RSpec.describe IncidentManagement::TimelineEvents::UpdateService do let!(:timeline_event) { create(:incident_management_timeline_event, project: project, incident: incident) } let(:occurred_at) { 1.minute.ago } let(:params) { { note: 'Updated note', occurred_at: occurred_at } } + let(:current_user) { user } before do stub_feature_flags(incident_timeline: project) @@ -21,6 +22,8 @@ RSpec.describe IncidentManagement::TimelineEvents::UpdateService do expect(execute).to be_success expect(execute.payload).to eq(timeline_event: timeline_event.reload) end + + it_behaves_like 'an incident management tracked event', :incident_management_timeline_event_edited end shared_examples 'error response' do |message| @@ -28,6 +31,8 @@ RSpec.describe IncidentManagement::TimelineEvents::UpdateService do expect(execute).to be_error expect(execute.message).to eq(message) end + + it_behaves_like 'does not track incident management event', :incident_management_timeline_event_edited end shared_examples 'passing the correct was_changed value' do |was_changed| @@ -135,6 +140,14 @@ RSpec.describe IncidentManagement::TimelineEvents::UpdateService do execute end end + + context 'when timeline event is non-editable' do + let!(:timeline_event) do + create(:incident_management_timeline_event, :non_editable, project: project, incident: incident) + end + + it_behaves_like 'error response', 'You cannot edit this timeline event.' + end end context 'when user does not have permissions' do |