Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/incident_management/timeline_events')
-rw-r--r--spec/services/incident_management/timeline_events/create_service_spec.rb18
-rw-r--r--spec/services/incident_management/timeline_events/destroy_service_spec.rb9
-rw-r--r--spec/services/incident_management/timeline_events/update_service_spec.rb168
3 files changed, 190 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 b10862a78b5..a3810879c65 100644
--- a/spec/services/incident_management/timeline_events/create_service_spec.rb
+++ b/spec/services/incident_management/timeline_events/create_service_spec.rb
@@ -55,6 +55,15 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do
end
it_behaves_like 'an incident management tracked event', :incident_management_timeline_event_created
+
+ it_behaves_like 'Snowplow event tracking with RedisHLL context' do
+ let(:feature_flag_name) { :route_hll_to_snowplow_phase2 }
+ let(:namespace) { project.namespace.reload }
+ let(:category) { described_class.to_s }
+ let(:user) { current_user }
+ let(:action) { 'incident_management_timeline_event_created' }
+ let(:label) { 'redis_hll_counters.incident_management.incident_management_total_unique_counts_monthly' }
+ end
end
subject(:execute) { service.execute }
@@ -276,6 +285,15 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do
it_behaves_like 'an incident management tracked event', :incident_management_timeline_event_created
+ it_behaves_like 'Snowplow event tracking with RedisHLL context' do
+ let(:feature_flag_name) { :route_hll_to_snowplow_phase2 }
+ let(:namespace) { project.namespace.reload }
+ let(:category) { described_class.to_s }
+ let(:user) { current_user }
+ let(:action) { 'incident_management_timeline_event_created' }
+ let(:label) { 'redis_hll_counters.incident_management.incident_management_total_unique_counts_monthly' }
+ 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 e1b258960ae..f90ff72a2bf 100644
--- a/spec/services/incident_management/timeline_events/destroy_service_spec.rb
+++ b/spec/services/incident_management/timeline_events/destroy_service_spec.rb
@@ -65,6 +65,15 @@ RSpec.describe IncidentManagement::TimelineEvents::DestroyService do
end
it_behaves_like 'an incident management tracked event', :incident_management_timeline_event_deleted
+
+ it_behaves_like 'Snowplow event tracking with RedisHLL context' do
+ let(:feature_flag_name) { :route_hll_to_snowplow_phase2 }
+ let(:namespace) { project.namespace.reload }
+ let(:category) { described_class.to_s }
+ let(:user) { current_user }
+ let(:action) { 'incident_management_timeline_event_deleted' }
+ let(:label) { 'redis_hll_counters.incident_management.incident_management_total_unique_counts_monthly' }
+ end
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 2373a73e108..ff802109715 100644
--- a/spec/services/incident_management/timeline_events/update_service_spec.rb
+++ b/spec/services/incident_management/timeline_events/update_service_spec.rb
@@ -2,10 +2,20 @@
require 'spec_helper'
-RSpec.describe IncidentManagement::TimelineEvents::UpdateService do
+RSpec.describe IncidentManagement::TimelineEvents::UpdateService, feature_category: :incident_management do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:incident) { create(:incident, project: project) }
+ let_it_be(:tag1) { create(:incident_management_timeline_event_tag, project: project, name: 'Tag 1') }
+ let_it_be(:tag2) { create(:incident_management_timeline_event_tag, project: project, name: 'Tag 2') }
+ let_it_be(:tag3) { create(:incident_management_timeline_event_tag, project: project, name: 'Tag 3') }
+
+ let!(:tag_link1) do
+ create(:incident_management_timeline_event_tag_link,
+ timeline_event: timeline_event,
+ timeline_event_tag: tag3
+ )
+ end
let!(:timeline_event) { create(:incident_management_timeline_event, project: project, incident: incident) }
let(:occurred_at) { 1.minute.ago }
@@ -13,6 +23,24 @@ RSpec.describe IncidentManagement::TimelineEvents::UpdateService do
let(:current_user) { user }
describe '#execute' do
+ shared_examples 'successful tag response' do
+ it_behaves_like 'successful response'
+
+ it 'adds the new tag' do
+ expect { execute }.to change { timeline_event.timeline_event_tags.count }.by(1)
+ end
+
+ it 'adds the new tag link' do
+ expect { execute }.to change { IncidentManagement::TimelineEventTagLink.count }.by(1)
+ end
+
+ it 'returns the new tag in response' do
+ timeline_event = execute.payload[:timeline_event]
+
+ expect(timeline_event.timeline_event_tags.pluck_names).to contain_exactly(tag1.name, tag3.name)
+ end
+ end
+
shared_examples 'successful response' do
it 'responds with success', :aggregate_failures do
expect(execute).to be_success
@@ -20,6 +48,14 @@ RSpec.describe IncidentManagement::TimelineEvents::UpdateService do
end
it_behaves_like 'an incident management tracked event', :incident_management_timeline_event_edited
+
+ it_behaves_like 'Snowplow event tracking with RedisHLL context' do
+ let(:feature_flag_name) { :route_hll_to_snowplow_phase2 }
+ let(:namespace) { project.namespace.reload }
+ let(:category) { described_class.to_s }
+ let(:action) { 'incident_management_timeline_event_edited' }
+ let(:label) { 'redis_hll_counters.incident_management.incident_management_total_unique_counts_monthly' }
+ end
end
shared_examples 'error response' do |message|
@@ -67,7 +103,7 @@ RSpec.describe IncidentManagement::TimelineEvents::UpdateService do
it_behaves_like 'passing the correct was_changed value', :occurred_at_and_note
context 'when note is nil' do
- let(:params) { { occurred_at: occurred_at } }
+ let(:params) { { occurred_at: occurred_at, timeline_event_tag_names: [tag3.name, tag2.name] } }
it_behaves_like 'successful response'
it_behaves_like 'passing the correct was_changed value', :occurred_at
@@ -79,18 +115,30 @@ RSpec.describe IncidentManagement::TimelineEvents::UpdateService do
it 'updates occurred_at' do
expect { execute }.to change { timeline_event.occurred_at }.to(params[:occurred_at])
end
+
+ it 'updates the tags' do
+ expect { execute }.to change { timeline_event.timeline_event_tags.count }.by(1)
+ end
end
context 'when note is blank' do
- let(:params) { { note: '', occurred_at: occurred_at } }
+ let(:params) { { note: '', occurred_at: occurred_at, timeline_event_tag_names: [tag3.name, tag2.name] } }
it_behaves_like 'error response', "Timeline text can't be blank"
+
+ it 'does not add the tags as it rollsback the transaction' do
+ expect { execute }.not_to change { timeline_event.timeline_event_tags.count }
+ end
end
context 'when note is more than 280 characters long' do
- let(:params) { { note: 'n' * 281, occurred_at: occurred_at } }
+ let(:params) { { note: 'n' * 281, occurred_at: occurred_at, timeline_event_tag_names: [tag3.name, tag2.name] } }
it_behaves_like 'error response', 'Timeline text is too long (maximum is 280 characters)'
+
+ it 'does not add the tags as it rollsback the transaction' do
+ expect { execute }.not_to change { timeline_event.timeline_event_tags.count }
+ end
end
context 'when occurred_at is nil' do
@@ -109,9 +157,13 @@ RSpec.describe IncidentManagement::TimelineEvents::UpdateService do
end
context 'when occurred_at is blank' do
- let(:params) { { note: 'Updated note', occurred_at: '' } }
+ let(:params) { { note: 'Updated note', occurred_at: '', timeline_event_tag_names: [tag3.name, tag2.name] } }
it_behaves_like 'error response', "Occurred at can't be blank"
+
+ it 'does not add the tags as it rollsback the transaction' do
+ expect { execute }.not_to change { timeline_event.timeline_event_tags.count }
+ end
end
context 'when both occurred_at and note is nil' do
@@ -142,6 +194,112 @@ RSpec.describe IncidentManagement::TimelineEvents::UpdateService do
it_behaves_like 'error response',
'You have insufficient permissions to manage timeline events for this incident'
end
+
+ context 'when timeline event tags are passed' do
+ context 'when predefined tags are passed' do
+ let(:params) do
+ {
+ note: 'Updated note',
+ occurred_at: occurred_at,
+ timeline_event_tag_names: ['start time', 'end time']
+ }
+ end
+
+ it 'returns the new tag in response' do
+ timeline_event = execute.payload[:timeline_event]
+
+ expect(timeline_event.timeline_event_tags.pluck_names).to contain_exactly('Start time', 'End time')
+ end
+
+ it 'creates the predefined tags on the project' do
+ execute
+
+ expect(project.incident_management_timeline_event_tags.pluck_names).to include('Start time', 'End time')
+ end
+ end
+
+ context 'when they exist' do
+ let(:params) do
+ {
+ note: 'Updated note',
+ occurred_at: occurred_at,
+ timeline_event_tag_names: [tag3.name, tag1.name]
+ }
+ end
+
+ it_behaves_like 'successful tag response'
+
+ context 'when tag name is of random case' do
+ let(:params) do
+ {
+ note: 'Updated note',
+ occurred_at: occurred_at,
+ timeline_event_tag_names: ['tAg 3', 'TaG 1']
+ }
+ end
+
+ it_behaves_like 'successful tag response'
+ end
+
+ context 'when tag is removed' do
+ let(:params) { { note: 'Updated note', occurred_at: occurred_at, timeline_event_tag_names: [tag2.name] } }
+
+ it_behaves_like 'successful response'
+
+ it 'adds the new tag and removes the old tag' do
+ # Since it adds a tag (+1) and removes old tag (-1) so next change in count in 0
+ expect { execute }.to change { timeline_event.timeline_event_tags.count }.by(0)
+ end
+
+ it 'adds the new tag link and removes the old tag link' do
+ # Since it adds a tag link (+1) and removes old tag link (-1) so next change in count in 0
+ expect { execute }.to change { IncidentManagement::TimelineEventTagLink.count }.by(0)
+ end
+
+ it 'returns the new tag and does not contain the old tag in response' do
+ timeline_event = execute.payload[:timeline_event]
+
+ expect(timeline_event.timeline_event_tags.pluck_names).to contain_exactly(tag2.name)
+ end
+ end
+
+ context 'when all assigned tags are removed' do
+ let(:params) { { note: 'Updated note', occurred_at: occurred_at, timeline_event_tag_names: [] } }
+
+ it_behaves_like 'successful response'
+
+ it 'removes all the assigned tags' do
+ expect { execute }.to change { timeline_event.timeline_event_tags.count }.by(-1)
+ end
+
+ it 'removes all the assigned tag links' do
+ expect { execute }.to change { IncidentManagement::TimelineEventTagLink.count }.by(-1)
+ end
+
+ it 'does not contain any tags in response' do
+ timeline_event = execute.payload[:timeline_event]
+
+ expect(timeline_event.timeline_event_tags.pluck_names).to be_empty
+ end
+ end
+ end
+
+ context 'when they do not exist' do
+ let(:params) do
+ {
+ note: 'Updated note 2',
+ occurred_at: occurred_at,
+ timeline_event_tag_names: ['non existing tag']
+ }
+ end
+
+ it_behaves_like 'error response', "Following tags don't exist: [\"non existing tag\"]"
+
+ it 'does not update the note' do
+ expect { execute }.not_to change { timeline_event.reload.note }
+ end
+ end
+ end
end
context 'when user does not have permissions' do