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')
-rw-r--r--spec/services/incident_management/timeline_event_tags/create_service_spec.rb71
-rw-r--r--spec/services/incident_management/timeline_events/create_service_spec.rb107
-rw-r--r--spec/services/incident_management/timeline_events/update_service_spec.rb6
3 files changed, 184 insertions, 0 deletions
diff --git a/spec/services/incident_management/timeline_event_tags/create_service_spec.rb b/spec/services/incident_management/timeline_event_tags/create_service_spec.rb
new file mode 100644
index 00000000000..c1b993ce3d9
--- /dev/null
+++ b/spec/services/incident_management/timeline_event_tags/create_service_spec.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe IncidentManagement::TimelineEventTags::CreateService do
+ let_it_be(:user_with_permissions) { create(:user) }
+ let_it_be(:user_without_permissions) { create(:user) }
+ let_it_be_with_reload(:project) { create(:project) }
+
+ let(:current_user) { user_with_permissions }
+ let(:args) { { 'name': 'Test tag 1', 'project_path': project.full_path } }
+
+ let(:service) { described_class.new(project, current_user, args) }
+
+ before do
+ project.add_maintainer(user_with_permissions)
+ project.add_developer(user_without_permissions)
+ end
+
+ describe '#execute' do
+ shared_examples 'error response' do |message|
+ it 'has an informative message' do
+ expect(execute).to be_error
+ expect(execute.message).to eq(message)
+ end
+ end
+
+ shared_examples 'success response' do
+ it 'has timeline event tag' do
+ expect(execute).to be_success
+
+ result = execute.payload[:timeline_event_tag]
+ expect(result).to be_a(::IncidentManagement::TimelineEventTag)
+ expect(result.name).to eq(args[:name])
+ expect(result.project).to eq(project)
+ end
+ end
+
+ subject(:execute) { service.execute }
+
+ context 'when current user is nil' do
+ let(:current_user) { nil }
+
+ it_behaves_like 'error response',
+ 'You have insufficient permissions to manage timeline event tags for this project'
+ end
+
+ context 'when user does not have permissions to create tags' do
+ let(:current_user) { user_without_permissions }
+
+ it_behaves_like 'error response',
+ 'You have insufficient permissions to manage timeline event tags for this project'
+ end
+
+ context 'when error occurs during creation' do
+ let(:args) { {} }
+
+ it_behaves_like 'error response', "Name can't be blank and Name is invalid"
+ end
+
+ context 'when user has permissions' do
+ it_behaves_like 'success response'
+
+ it 'creates database record' do
+ expect { execute }.to change {
+ ::IncidentManagement::TimelineEventTag.where(project_id: project.id).count
+ }.by(1)
+ end
+ end
+ end
+end
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 a7f448c825f..b10862a78b5 100644
--- a/spec/services/incident_management/timeline_events/create_service_spec.rb
+++ b/spec/services/incident_management/timeline_events/create_service_spec.rb
@@ -8,6 +8,9 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do
let_it_be(:project) { create(:project) }
let_it_be_with_refind(:incident) { create(:incident, project: project) }
let_it_be(:comment) { create(:note, project: project, noteable: incident) }
+ let_it_be(:timeline_event_tag) do
+ create(:incident_management_timeline_event_tag, name: 'Test tag 1', project: project)
+ end
let(:args) do
{
@@ -134,6 +137,67 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do
end
end
+ context 'when timeline event tag names are passed' do
+ let(:args) do
+ {
+ note: 'note',
+ occurred_at: Time.current,
+ action: 'new comment',
+ promoted_from_note: comment,
+ timeline_event_tag_names: ['Test tag 1']
+ }
+ end
+
+ it_behaves_like 'success response'
+
+ it 'matches the tag name' do
+ result = execute.payload[:timeline_event]
+ expect(result.timeline_event_tags.first).to eq(timeline_event_tag)
+ end
+
+ context 'when predefined tags are passed' do
+ let(:args) do
+ {
+ note: 'note',
+ occurred_at: Time.current,
+ action: 'new comment',
+ promoted_from_note: comment,
+ timeline_event_tag_names: ['start time', 'end time']
+ }
+ end
+
+ it_behaves_like 'success response'
+
+ it 'matches the two tags on the event and creates on project' do
+ result = execute.payload[:timeline_event]
+
+ expect(result.timeline_event_tags.count).to eq(2)
+ expect(result.timeline_event_tags.by_names(['Start time', 'End time']).pluck_names)
+ .to match_array(['Start time', 'End time'])
+ expect(project.incident_management_timeline_event_tags.pluck_names)
+ .to include('Start time', 'End time')
+ end
+ end
+
+ context 'when invalid tag names are passed' do
+ let(:args) do
+ {
+ note: 'note',
+ occurred_at: Time.current,
+ action: 'new comment',
+ promoted_from_note: comment,
+ timeline_event_tag_names: ['some other time']
+ }
+ end
+
+ it_behaves_like 'error response', "Following tags don't exist: [\"some other time\"]"
+
+ it 'does not create timeline event' do
+ expect { execute }.not_to change(IncidentManagement::TimelineEvent, :count)
+ end
+ end
+ end
+
context 'with editable param' do
let(:args) do
{
@@ -161,6 +225,38 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do
it 'successfully creates a database record', :aggregate_failures do
expect { execute }.to change { ::IncidentManagement::TimelineEvent.count }.by(1)
end
+
+ context 'when note is more than 280 characters long' do
+ let(:args) do
+ {
+ note: 'a' * 281,
+ occurred_at: Time.current,
+ action: 'new comment',
+ promoted_from_note: comment,
+ auto_created: auto_created
+ }
+ end
+
+ let(:auto_created) { false }
+
+ context 'when was not promoted from note' do
+ let(:comment) { nil }
+
+ context 'when auto_created is true' do
+ let(:auto_created) { true }
+
+ it_behaves_like 'success response'
+ end
+
+ context 'when auto_created is false' do
+ it_behaves_like 'error response', 'Timeline text is too long (maximum is 280 characters)'
+ end
+ end
+
+ context 'when promoted from note' do
+ it_behaves_like 'success response'
+ end
+ end
end
describe 'automatically created timeline events' do
@@ -229,6 +325,17 @@ RSpec.describe IncidentManagement::TimelineEvents::CreateService do
it_behaves_like 'successfully created timeline event'
end
+ describe '.change_severity' do
+ subject(:execute) { described_class.change_severity(incident, current_user) }
+
+ let_it_be(:severity) { create(:issuable_severity, severity: :critical, issue: incident) }
+
+ let(:expected_note) { "@#{current_user.username} changed the incident severity to **Critical - S1**" }
+ let(:expected_action) { 'severity' }
+
+ it_behaves_like 'successfully created timeline event'
+ end
+
describe '.change_labels' do
subject(:execute) do
described_class.change_labels(incident, current_user, added_labels: added, removed_labels: removed)
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 5d8518cf2ef..2373a73e108 100644
--- a/spec/services/incident_management/timeline_events/update_service_spec.rb
+++ b/spec/services/incident_management/timeline_events/update_service_spec.rb
@@ -87,6 +87,12 @@ RSpec.describe IncidentManagement::TimelineEvents::UpdateService do
it_behaves_like 'error response', "Timeline text can't be blank"
end
+ context 'when note is more than 280 characters long' do
+ let(:params) { { note: 'n' * 281, occurred_at: occurred_at } }
+
+ it_behaves_like 'error response', 'Timeline text is too long (maximum is 280 characters)'
+ end
+
context 'when occurred_at is nil' do
let(:params) { { note: 'Updated note' } }