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>2023-06-14 00:09:09 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-06-14 00:09:09 +0300
commit04cc87ee46c1c0b6b4eb7df964b3115dd2578877 (patch)
tree2c64b0e21804fc0981a2142eb83a0b73d85fbcda /spec/services
parent4a064b8dc0bf350b1b3000698042b49113e758d1 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/notes/create_service_spec.rb13
-rw-r--r--spec/services/notes/quick_actions_service_spec.rb121
-rw-r--r--spec/services/pages/delete_service_spec.rb2
-rw-r--r--spec/services/pages/migrate_from_legacy_storage_service_spec.rb2
-rw-r--r--spec/services/projects/update_pages_service_spec.rb2
-rw-r--r--spec/services/quick_actions/interpret_service_spec.rb71
6 files changed, 160 insertions, 51 deletions
diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb
index 89114bf3fd0..22509885c92 100644
--- a/spec/services/notes/create_service_spec.rb
+++ b/spec/services/notes/create_service_spec.rb
@@ -567,6 +567,19 @@ RSpec.describe Notes::CreateService, feature_category: :team_planning do
note_text = %(/close)
described_class.new(project, user, opts.merge(note: note_text)).execute
end
+
+ it 'generates failed update error messages' do
+ note_text = %(/confidential)
+ service = double(:service)
+ issue.errors.add(:confidential, 'an error occurred')
+ allow(Issues::UpdateService).to receive(:new).and_return(service)
+ allow_next_instance_of(Issues::UpdateService) do |service_instance|
+ allow(service_instance).to receive(:execute).and_return(issue)
+ end
+
+ note = described_class.new(project, user, opts.merge(note: note_text)).execute
+ expect(note.errors[:commands_only]).to contain_exactly('Confidential an error occurred')
+ end
end
end
diff --git a/spec/services/notes/quick_actions_service_spec.rb b/spec/services/notes/quick_actions_service_spec.rb
index c65a077f907..cd3a4e8a395 100644
--- a/spec/services/notes/quick_actions_service_spec.rb
+++ b/spec/services/notes/quick_actions_service_spec.rb
@@ -248,6 +248,46 @@ RSpec.describe Notes::QuickActionsService, feature_category: :team_planning do
end
end
end
+
+ describe '/promote_to' do
+ shared_examples 'promotes work item' do |from:, to:|
+ it 'leaves the note empty' do
+ expect(execute(note)).to be_empty
+ end
+
+ it 'promotes to provided type' do
+ expect { execute(note) }.to change { noteable.work_item_type.base_type }.from(from).to(to)
+ end
+ end
+
+ context 'on a task' do
+ let_it_be_with_reload(:noteable) { create(:work_item, :task, project: project) }
+ let_it_be(:note_text) { '/promote_to Issue' }
+ let_it_be(:note) { create(:note, noteable: noteable, project: project, note: note_text) }
+
+ it_behaves_like 'promotes work item', from: 'task', to: 'issue'
+
+ context 'when type name is lower case' do
+ let_it_be(:note_text) { '/promote_to issue' }
+
+ it_behaves_like 'promotes work item', from: 'task', to: 'issue'
+ end
+ end
+
+ context 'on an issue' do
+ let_it_be_with_reload(:noteable) { create(:work_item, :issue, project: project) }
+ let_it_be(:note_text) { '/promote_to Incident' }
+ let_it_be(:note) { create(:note, noteable: noteable, project: project, note: note_text) }
+
+ it_behaves_like 'promotes work item', from: 'issue', to: 'incident'
+
+ context 'when type name is lower case' do
+ let_it_be(:note_text) { '/promote_to incident' }
+
+ it_behaves_like 'promotes work item', from: 'issue', to: 'incident'
+ end
+ end
+ end
end
describe '.supported?' do
@@ -380,6 +420,87 @@ RSpec.describe Notes::QuickActionsService, feature_category: :team_planning do
end
end
+ describe '#apply_updates' do
+ include_context 'note on noteable'
+
+ let_it_be(:issue) { create(:issue, project: project) }
+ let_it_be(:work_item, reload: true) { create(:work_item, :issue, project: project) }
+ let_it_be(:merge_request) { create(:merge_request, source_project: project) }
+ let_it_be(:issue_note) { create(:note_on_issue, project: project, noteable: issue) }
+ let_it_be(:work_item_note) { create(:note, project: project, noteable: work_item) }
+ let_it_be(:mr_note) { create(:note_on_merge_request, project: project, noteable: merge_request) }
+ let_it_be(:commit_note) { create(:note_on_commit, project: project) }
+ let(:update_params) { {} }
+
+ subject(:apply_updates) { described_class.new(project, maintainer).apply_updates(update_params, note) }
+
+ context 'with a note on an issue' do
+ let(:note) { issue_note }
+
+ it 'returns successful service response if update returned no errors' do
+ update_params[:confidential] = true
+ expect(apply_updates.success?).to be true
+ end
+
+ it 'returns service response with errors if update failed' do
+ update_params[:title] = ""
+ expect(apply_updates.success?).to be false
+ expect(apply_updates.message).to include("Title can't be blank")
+ end
+ end
+
+ context 'with a note on a merge request' do
+ let(:note) { mr_note }
+
+ it 'returns successful service response if update returned no errors' do
+ update_params[:title] = 'New title'
+ expect(apply_updates.success?).to be true
+ end
+
+ it 'returns service response with errors if update failed' do
+ update_params[:title] = ""
+ expect(apply_updates.success?).to be false
+ expect(apply_updates.message).to include("Title can't be blank")
+ end
+ end
+
+ context 'with a note on a work item' do
+ let(:note) { work_item_note }
+
+ before do
+ update_params[:confidential] = true
+ end
+
+ it 'returns successful service response if update returned no errors' do
+ expect(apply_updates.success?).to be true
+ end
+
+ it 'returns service response with errors if update failed' do
+ task = create(:work_item, :task, project: project)
+ create(:parent_link, work_item: task, work_item_parent: work_item)
+
+ expect(apply_updates.success?).to be false
+ expect(apply_updates.message)
+ .to include("A confidential work item cannot have a parent that already has non-confidential children.")
+ end
+ end
+
+ context 'with a note on a commit' do
+ let(:note) { commit_note }
+
+ it 'returns successful service response if update returned no errors' do
+ update_params[:tag_name] = 'test'
+ expect(apply_updates.success?).to be true
+ end
+
+ it 'returns service response with errors if update failed' do
+ update_params[:tag_name] = '-test'
+ expect(apply_updates.success?).to be false
+ expect(apply_updates.message).to include('Tag name invalid')
+ end
+ end
+ end
+
context 'CE restriction for issue assignees' do
describe '/assign' do
let(:project) { create(:project) }
diff --git a/spec/services/pages/delete_service_spec.rb b/spec/services/pages/delete_service_spec.rb
index 590378af22b..488f29f6b7e 100644
--- a/spec/services/pages/delete_service_spec.rb
+++ b/spec/services/pages/delete_service_spec.rb
@@ -25,7 +25,7 @@ RSpec.describe Pages::DeleteService, feature_category: :pages do
service.execute
expect(PagesDomain.find_by_id(domain.id)).to eq(nil)
- expect(PagesDomain.find_by_id(unrelated_domain.id)).to be
+ expect(PagesDomain.find_by_id(unrelated_domain.id)).to be_present
end
it 'schedules a destruction of pages deployments' do
diff --git a/spec/services/pages/migrate_from_legacy_storage_service_spec.rb b/spec/services/pages/migrate_from_legacy_storage_service_spec.rb
index 4348ce4a271..48690a035f5 100644
--- a/spec/services/pages/migrate_from_legacy_storage_service_spec.rb
+++ b/spec/services/pages/migrate_from_legacy_storage_service_spec.rb
@@ -58,7 +58,7 @@ RSpec.describe Pages::MigrateFromLegacyStorageService, feature_category: :pages
expect(project.pages_metadatum.reload.pages_deployment).to eq(nil)
expect(subject).to eq(migrated: 1, errored: 0)
- expect(project.pages_metadatum.reload.pages_deployment).to be
+ expect(project.pages_metadatum.reload.pages_deployment).to be_present
end
context 'when deployed already exists for the project' do
diff --git a/spec/services/projects/update_pages_service_spec.rb b/spec/services/projects/update_pages_service_spec.rb
index a97369c4b08..a113f3506e1 100644
--- a/spec/services/projects/update_pages_service_spec.rb
+++ b/spec/services/projects/update_pages_service_spec.rb
@@ -95,7 +95,7 @@ RSpec.describe Projects::UpdatePagesService, feature_category: :pages do
deployment = project.pages_deployments.last
expect(deployment.size).to eq(file.size)
- expect(deployment.file).to be
+ expect(deployment.file).to be_present
expect(deployment.file_count).to eq(3)
expect(deployment.file_sha256).to eq(artifacts_archive.file_sha256)
expect(project.pages_metadatum.reload.pages_deployment_id).to eq(deployment.id)
diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb
index 71bff37b956..bd09dae0a5a 100644
--- a/spec/services/quick_actions/interpret_service_spec.rb
+++ b/spec/services/quick_actions/interpret_service_spec.rb
@@ -2417,54 +2417,7 @@ RSpec.describe QuickActions::InterpretService, feature_category: :team_planning
end
end
- describe 'type command' do
- let_it_be(:project) { create(:project, :private) }
- let_it_be(:work_item) { create(:work_item, project: project) }
-
- let(:command) { '/type Task' }
-
- context 'when user has sufficient permissions to create new type' do
- before do
- allow(Ability).to receive(:allowed?).and_call_original
- allow(Ability).to receive(:allowed?).with(current_user, :create_task, work_item).and_return(true)
- end
-
- it 'populates :issue_type: and :work_item_type' do
- _, updates, message = service.execute(command, work_item)
-
- expect(message).to eq(_('Type changed successfully.'))
- expect(updates).to eq({ issue_type: 'task', work_item_type: WorkItems::Type.default_by_type(:task) })
- end
-
- it 'returns error with an invalid type' do
- _, updates, message = service.execute('/type foo', work_item)
-
- expect(message).to eq(_("Failed to convert this work item: Provided type is not supported."))
- expect(updates).to eq({})
- end
-
- it 'returns error with same type' do
- _, updates, message = service.execute('/type Issue', work_item)
-
- expect(message).to eq(_("Failed to convert this work item: Types are the same."))
- expect(updates).to eq({})
- end
- end
-
- context 'when user has insufficient permissions to create new type' do
- before do
- allow(Ability).to receive(:allowed?).and_call_original
- allow(Ability).to receive(:allowed?).with(current_user, :create_task, work_item).and_return(false)
- end
-
- it 'returns error' do
- _, updates, message = service.execute(command, work_item)
-
- expect(message).to eq(_("Failed to convert this work item: You have insufficient permissions."))
- expect(updates).to eq({})
- end
- end
- end
+ it_behaves_like 'quick actions that change work item type'
end
describe '#explain' do
@@ -2955,6 +2908,28 @@ RSpec.describe QuickActions::InterpretService, feature_category: :team_planning
end
end
end
+
+ describe 'promote_to command' do
+ let(:content) { '/promote_to issue' }
+
+ context 'when work item supports promotion' do
+ let_it_be(:task) { build(:work_item, :task, project: project) }
+
+ it 'includes the value' do
+ _, explanations = service.explain(content, task)
+ expect(explanations).to eq(['Promotes work item to issue.'])
+ end
+ end
+
+ context 'when work item does not support promotion' do
+ let_it_be(:incident) { build(:work_item, :incident, project: project) }
+
+ it 'does not include the value' do
+ _, explanations = service.explain(content, incident)
+ expect(explanations).to be_empty
+ end
+ end
+ end
end
describe '#available_commands' do