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-07-23 15:09:23 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-23 15:09:23 +0300
commitd9b0b3243e3cd71a08ff5d4035b7882cc7a5a35f (patch)
treea0389a930f457771ad4c40037def0d32f7323611 /spec/services/incident_management
parentdefde9698e1d87e7d8c09e487ed75675d1d67323 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/incident_management')
-rw-r--r--spec/services/incident_management/create_issue_service_spec.rb27
-rw-r--r--spec/services/incident_management/incidents/create_service_spec.rb67
2 files changed, 80 insertions, 14 deletions
diff --git a/spec/services/incident_management/create_issue_service_spec.rb b/spec/services/incident_management/create_issue_service_spec.rb
index dab9a149458..60b3a513a67 100644
--- a/spec/services/incident_management/create_issue_service_spec.rb
+++ b/spec/services/incident_management/create_issue_service_spec.rb
@@ -25,10 +25,10 @@ RSpec.describe IncidentManagement::CreateIssueService do
create(:project_incident_management_setting, project: project)
end
- subject { service.execute }
+ subject(:execute) { service.execute }
context 'when create_issue enabled' do
- let(:issue) { subject[:issue] }
+ let(:issue) { execute.payload[:issue] }
before do
setting.update!(create_issue: true)
@@ -36,7 +36,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
context 'without issue_template_content' do
it 'creates an issue with alert summary only' do
- expect(subject).to include(status: :success)
+ expect(execute).to be_success
expect(issue.author).to eq(user)
expect(issue.title).to eq(alert_title)
@@ -61,7 +61,8 @@ RSpec.describe IncidentManagement::CreateIssueService do
.to receive(:log_error)
.with(error_message(issue_error))
- expect(subject).to include(status: :error, message: issue_error)
+ expect(execute).to be_error
+ expect(execute.message).to eq(issue_error)
end
end
@@ -70,7 +71,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
let(:template_content) { 'some content' }
it 'creates an issue appending issue template' do
- expect(subject).to include(status: :success)
+ expect(execute).to be_success
expect(issue.description).to include(alert_presenter.issue_summary_markdown)
expect(separator_count(issue.description)).to eq(1)
@@ -95,7 +96,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
end
it 'creates an issue interpreting quick actions' do
- expect(subject).to include(status: :success)
+ expect(execute).to be_success
expect(issue.description).to include(plain_text)
expect(issue.due_date).to be_present
@@ -128,7 +129,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
end
it 'includes both templates' do
- expect(subject).to include(status: :success)
+ expect(execute).to be_success
expect(issue.description).to include(alert_presenter.issue_summary_markdown)
expect(issue.description).to include(template_content)
@@ -162,7 +163,7 @@ RSpec.describe IncidentManagement::CreateIssueService do
it 'creates an issue' do
query_title = "#{gitlab_alert.title} #{gitlab_alert.computed_operator} #{gitlab_alert.threshold}"
- expect(subject).to include(status: :success)
+ expect(execute).to be_success
expect(issue.author).to eq(user)
expect(issue.title).to eq(alert_presenter.full_title)
@@ -181,7 +182,8 @@ RSpec.describe IncidentManagement::CreateIssueService do
.to receive(:log_error)
.with(error_message('invalid alert'))
- expect(subject).to eq(status: :error, message: 'invalid alert')
+ expect(execute).to be_error
+ expect(execute.message).to eq('invalid alert')
end
end
@@ -197,10 +199,6 @@ RSpec.describe IncidentManagement::CreateIssueService do
it_behaves_like 'invalid alert'
end
end
-
- describe "label `incident`" do
- it_behaves_like 'create alert issue sets issue labels'
- end
end
context 'when create_issue disabled' do
@@ -213,7 +211,8 @@ RSpec.describe IncidentManagement::CreateIssueService do
.to receive(:log_error)
.with(error_message('setting disabled'))
- expect(subject).to eq(status: :error, message: 'setting disabled')
+ expect(execute).to be_error
+ expect(execute.message).to eq('setting disabled')
end
end
diff --git a/spec/services/incident_management/incidents/create_service_spec.rb b/spec/services/incident_management/incidents/create_service_spec.rb
new file mode 100644
index 00000000000..1857dd6a2fd
--- /dev/null
+++ b/spec/services/incident_management/incidents/create_service_spec.rb
@@ -0,0 +1,67 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe IncidentManagement::Incidents::CreateService do
+ let_it_be(:project) { create(:project) }
+ let_it_be(:user) { User.alert_bot }
+ let(:description) { 'Incident description' }
+
+ describe '#execute' do
+ subject(:create_incident) { described_class.new(project, user, title: title, description: description).execute }
+
+ context 'when incident has title and description' do
+ let(:title) { 'Incident title' }
+ let(:new_issue) { Issue.last! }
+ let(:label_title) { IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES[:title] }
+
+ it 'responds with success' do
+ expect(create_incident).to be_success
+ end
+
+ it 'creates an incident issue' do
+ expect { create_incident }.to change(Issue, :count).by(1)
+ end
+
+ it 'created issue has correct attributes' do
+ create_incident
+
+ expect(new_issue.title).to eq(title)
+ expect(new_issue.description).to eq(description)
+ expect(new_issue.author).to eq(user)
+ expect(new_issue.labels.map(&:title)).to eq([label_title])
+ end
+
+ context 'when incident label does not exists' do
+ it 'creates incident label' do
+ expect { create_incident }.to change { project.labels.where(title: label_title).count }.by(1)
+ end
+ end
+
+ context 'when incident label already exists' do
+ let!(:label) { create(:label, project: project, title: label_title) }
+
+ it 'does not create new labels' do
+ expect { create_incident }.not_to change(Label, :count)
+ end
+ end
+ end
+
+ context 'when incident has no title' do
+ let(:title) { '' }
+
+ it 'does not create an issue' do
+ expect { create_incident }.not_to change(Issue, :count)
+ end
+
+ it 'responds with errors' do
+ expect(create_incident).to be_error
+ expect(create_incident.message).to eq("Title can't be blank")
+ end
+
+ it 'result payload contains an Issue object' do
+ expect(create_incident.payload[:issue]).to be_kind_of(Issue)
+ end
+ end
+ end
+end