diff options
Diffstat (limited to 'spec/services/incident_management')
4 files changed, 54 insertions, 13 deletions
diff --git a/spec/services/incident_management/issuable_escalation_statuses/prepare_update_service_spec.rb b/spec/services/incident_management/issuable_escalation_statuses/prepare_update_service_spec.rb index 25164df40ca..6c99631fcb0 100644 --- a/spec/services/incident_management/issuable_escalation_statuses/prepare_update_service_spec.rb +++ b/spec/services/incident_management/issuable_escalation_statuses/prepare_update_service_spec.rb @@ -42,14 +42,6 @@ RSpec.describe IncidentManagement::IssuableEscalationStatuses::PrepareUpdateServ it_behaves_like 'successful response', { status_event: :acknowledge } - context 'when feature flag is disabled' do - before do - stub_feature_flags(incident_escalations: false) - end - - it_behaves_like 'availability error response' - end - context 'when user is anonymous' do let(:current_user) { nil } 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 |