summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-23 12:09:23 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-23 12:09:23 +0000
commitd9b0b3243e3cd71a08ff5d4035b7882cc7a5a35f (patch)
treea0389a930f457771ad4c40037def0d32f7323611 /spec
parentdefde9698e1d87e7d8c09e487ed75675d1d67323 (diff)
downloadgitlab-ce-d9b0b3243e3cd71a08ff5d4035b7882cc7a5a35f.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/diffs/store/actions_spec.js19
-rw-r--r--spec/lib/gitlab/import_export/group/tree_restorer_spec.rb2
-rw-r--r--spec/services/alert_management/create_alert_issue_service_spec.rb2
-rw-r--r--spec/services/incident_management/create_issue_service_spec.rb27
-rw-r--r--spec/services/incident_management/incidents/create_service_spec.rb67
-rw-r--r--spec/support/shared_examples/create_alert_issue_shared_examples.rb19
6 files changed, 98 insertions, 38 deletions
diff --git a/spec/frontend/diffs/store/actions_spec.js b/spec/frontend/diffs/store/actions_spec.js
index fc5e39357ca..c433690d3a7 100644
--- a/spec/frontend/diffs/store/actions_spec.js
+++ b/spec/frontend/diffs/store/actions_spec.js
@@ -1594,24 +1594,39 @@ describe('DiffsStoreActions', () => {
describe('setCurrentDiffFileIdFromNote', () => {
it('commits UPDATE_CURRENT_DIFF_FILE_ID', () => {
const commit = jest.fn();
+ const state = { diffFiles: [{ file_hash: '123' }] };
const rootGetters = {
getDiscussion: () => ({ diff_file: { file_hash: '123' } }),
notesById: { '1': { discussion_id: '2' } },
};
- setCurrentDiffFileIdFromNote({ commit, rootGetters }, '1');
+ setCurrentDiffFileIdFromNote({ commit, state, rootGetters }, '1');
expect(commit).toHaveBeenCalledWith(types.UPDATE_CURRENT_DIFF_FILE_ID, '123');
});
it('does not commit UPDATE_CURRENT_DIFF_FILE_ID when discussion has no diff_file', () => {
const commit = jest.fn();
+ const state = { diffFiles: [{ file_hash: '123' }] };
const rootGetters = {
getDiscussion: () => ({ id: '1' }),
notesById: { '1': { discussion_id: '2' } },
};
- setCurrentDiffFileIdFromNote({ commit, rootGetters }, '1');
+ setCurrentDiffFileIdFromNote({ commit, state, rootGetters }, '1');
+
+ expect(commit).not.toHaveBeenCalled();
+ });
+
+ it('does not commit UPDATE_CURRENT_DIFF_FILE_ID when diff file does not exist', () => {
+ const commit = jest.fn();
+ const state = { diffFiles: [{ file_hash: '123' }] };
+ const rootGetters = {
+ getDiscussion: () => ({ diff_file: { file_hash: '124' } }),
+ notesById: { '1': { discussion_id: '2' } },
+ };
+
+ setCurrentDiffFileIdFromNote({ commit, state, rootGetters }, '1');
expect(commit).not.toHaveBeenCalled();
});
diff --git a/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb b/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb
index 6cc16ee9cbb..2eb983cc050 100644
--- a/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb
@@ -172,7 +172,7 @@ RSpec.describe Gitlab::ImportExport::Group::TreeRestorer do
let(:filepath) { "group_exports/visibility_levels/#{visibility_level}" }
it "imports all subgroups as #{visibility_level}" do
- expect(group.children.map(&:visibility_level)).to eq(expected_visibilities)
+ expect(group.children.map(&:visibility_level)).to match_array(expected_visibilities)
end
end
end
diff --git a/spec/services/alert_management/create_alert_issue_service_spec.rb b/spec/services/alert_management/create_alert_issue_service_spec.rb
index a8f2b4ee09c..cf24188a738 100644
--- a/spec/services/alert_management/create_alert_issue_service_spec.rb
+++ b/spec/services/alert_management/create_alert_issue_service_spec.rb
@@ -88,7 +88,6 @@ RSpec.describe AlertManagement::CreateAlertIssueService do
it_behaves_like 'creating an alert issue'
it_behaves_like 'setting an issue attributes'
- it_behaves_like 'create alert issue sets issue labels'
end
context 'when the alert is generic' do
@@ -97,7 +96,6 @@ RSpec.describe AlertManagement::CreateAlertIssueService do
it_behaves_like 'creating an alert issue'
it_behaves_like 'setting an issue attributes'
- it_behaves_like 'create alert issue sets issue labels'
end
context 'when issue cannot be created' do
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
diff --git a/spec/support/shared_examples/create_alert_issue_shared_examples.rb b/spec/support/shared_examples/create_alert_issue_shared_examples.rb
deleted file mode 100644
index a2aa76b0ad6..00000000000
--- a/spec/support/shared_examples/create_alert_issue_shared_examples.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-RSpec.shared_examples 'create alert issue sets issue labels' do
- let(:title) { IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES[:title] }
- let!(:label) { create(:label, project: project, title: title) }
- let(:label_service) { instance_double(IncidentManagement::CreateIncidentLabelService, execute: label_service_response) }
-
- before do
- allow(IncidentManagement::CreateIncidentLabelService).to receive(:new).with(project, user).and_return(label_service)
- end
-
- context 'when create incident label responds with success' do
- let(:label_service_response) { ServiceResponse.success(payload: { label: label }) }
-
- it 'adds label to issue' do
- expect(issue.labels).to eq([label])
- end
- end
-end