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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-24 21:09:03 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-24 21:09:03 +0300
commitc59765a50abd6a235220fd895f5de78038c243a8 (patch)
tree6cacf61d1746e2d54149c028ecd3f187128cd7da /spec/services/incident_management
parent4c5468b40825debc2b7bbe08b975dedd2f7f1523 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/incident_management')
-rw-r--r--spec/services/incident_management/create_incident_label_service_spec.rb82
-rw-r--r--spec/services/incident_management/create_issue_service_spec.rb75
2 files changed, 83 insertions, 74 deletions
diff --git a/spec/services/incident_management/create_incident_label_service_spec.rb b/spec/services/incident_management/create_incident_label_service_spec.rb
new file mode 100644
index 00000000000..f2274119be5
--- /dev/null
+++ b/spec/services/incident_management/create_incident_label_service_spec.rb
@@ -0,0 +1,82 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe IncidentManagement::CreateIncidentLabelService do
+ let_it_be(:project) { create(:project, :private) }
+ let_it_be(:user) { User.alert_bot }
+ let(:service) { described_class.new(project, user) }
+
+ subject(:execute) { service.execute }
+
+ describe 'execute' do
+ let(:title) { described_class::LABEL_PROPERTIES[:title] }
+ let(:color) { described_class::LABEL_PROPERTIES[:color] }
+ let(:description) { described_class::LABEL_PROPERTIES[:description] }
+
+ shared_examples 'existing label' do
+ it 'returns the existing label' do
+ expect { execute }.not_to change(Label, :count)
+
+ expect(execute).to be_success
+ expect(execute.payload).to eq(label: label)
+ end
+ end
+
+ shared_examples 'new label' do
+ it 'creates a new label' do
+ expect { execute }.to change(Label, :count).by(1)
+
+ label = project.reload.labels.last
+ expect(execute).to be_success
+ expect(execute.payload).to eq(label: label)
+ expect(label.title).to eq(title)
+ expect(label.color).to eq(color)
+ expect(label.description).to eq(description)
+ end
+ end
+
+ context 'with predefined project label' do
+ it_behaves_like 'existing label' do
+ let!(:label) { create(:label, project: project, title: title) }
+ end
+ end
+
+ context 'with predefined group label' do
+ let(:project) { create(:project, group: group) }
+ let(:group) { create(:group) }
+
+ it_behaves_like 'existing label' do
+ let!(:label) { create(:group_label, group: group, title: title) }
+ end
+ end
+
+ context 'without label' do
+ it_behaves_like 'new label'
+ end
+
+ context 'with duplicate labels', issue: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/65042' do
+ before do
+ # Replicate race condition to create duplicates
+ build(:label, project: project, title: title).save!(validate: false)
+ build(:label, project: project, title: title).save!(validate: false)
+ end
+
+ it 'create an issue without labels' do
+ # Verify we have duplicates
+ expect(project.labels.size).to eq(2)
+ expect(project.labels.map(&:title)).to all(eq(title))
+
+ message = <<~MESSAGE.chomp
+ Cannot create incident label "incident" \
+ for "#{project.full_name}": Title has already been taken.
+ MESSAGE
+
+ expect(service).to receive(:log_info).with(message)
+ expect(execute).to be_error
+ expect(execute.payload[:label]).to be_kind_of(Label)
+ expect(execute.message).to eq('Title has already been taken')
+ end
+ end
+ end
+end
diff --git a/spec/services/incident_management/create_issue_service_spec.rb b/spec/services/incident_management/create_issue_service_spec.rb
index b513b649a8b..dab9a149458 100644
--- a/spec/services/incident_management/create_issue_service_spec.rb
+++ b/spec/services/incident_management/create_issue_service_spec.rb
@@ -199,80 +199,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
end
describe "label `incident`" do
- let(:title) { 'incident' }
- let(:color) { '#CC0033' }
- let(:description) do
- <<~DESCRIPTION.chomp
- Denotes a disruption to IT services and \
- the associated issues require immediate attention
- DESCRIPTION
- end
-
- shared_examples 'existing label' do
- it 'adds the existing label' do
- expect { subject }.not_to change(Label, :count)
-
- expect(issue.labels).to eq([label])
- end
- end
-
- shared_examples 'new label' do
- it 'adds newly created label' do
- expect { subject }.to change(Label, :count).by(1)
-
- label = project.reload.labels.last
- expect(issue.labels).to eq([label])
- expect(label.title).to eq(title)
- expect(label.color).to eq(color)
- expect(label.description).to eq(description)
- end
- end
-
- context 'with predefined project label' do
- it_behaves_like 'existing label' do
- let!(:label) { create(:label, project: project, title: title) }
- end
- end
-
- context 'with predefined group label' do
- let(:project) { create(:project, group: group) }
- let(:group) { create(:group) }
-
- it_behaves_like 'existing label' do
- let!(:label) { create(:group_label, group: group, title: title) }
- end
- end
-
- context 'without label' do
- it_behaves_like 'new label'
- end
-
- context 'with duplicate labels', issue: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/65042' do
- before do
- # Replicate race condition to create duplicates
- build(:label, project: project, title: title).save!(validate: false)
- build(:label, project: project, title: title).save!(validate: false)
- end
-
- it 'create an issue without labels' do
- # Verify we have duplicates
- expect(project.labels.size).to eq(2)
- expect(project.labels.map(&:title)).to all(eq(title))
-
- message = <<~MESSAGE.chomp
- Cannot create incident issue with labels ["#{title}"] for \
- "#{project.full_name}": Labels is invalid.
- Retrying without labels.
- MESSAGE
-
- expect(service)
- .to receive(:log_info)
- .with(message)
-
- expect(subject).to include(status: :success)
- expect(issue.labels).to be_empty
- end
- end
+ it_behaves_like 'create alert issue sets issue labels'
end
end