2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
describe Autocomplete::MoveToProjectFinder do
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:user) { create(:user) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:no_access_project) { create(:project) }
|
|
|
|
let(:guest_project) { create(:project) }
|
2019-10-12 21:52:04 +05:30
|
|
|
let(:reporter_project) { create(:project, name: 'name') }
|
|
|
|
let(:developer_project) { create(:project, name: 'name2') }
|
|
|
|
let(:maintainer_project) { create(:project, name: 'name3') }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
context 'filter' do
|
|
|
|
it 'does not return projects under Gitlab::Access::REPORTER' do
|
2018-03-17 18:26:18 +05:30
|
|
|
guest_project.add_guest(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
|
|
|
expect(finder.execute).to be_empty
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'returns projects equal or above Gitlab::Access::REPORTER ordered by name' do
|
2018-03-17 18:26:18 +05:30
|
|
|
reporter_project.add_reporter(user)
|
|
|
|
developer_project.add_developer(user)
|
2018-11-18 11:00:15 +05:30
|
|
|
maintainer_project.add_maintainer(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(finder.execute.to_a).to eq([reporter_project, developer_project, maintainer_project])
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include the source project' do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_reporter(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
|
|
|
expect(finder.execute.to_a).to be_empty
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return archived projects' do
|
2018-03-17 18:26:18 +05:30
|
|
|
reporter_project.add_reporter(user)
|
2018-11-18 11:00:15 +05:30
|
|
|
::Projects::UpdateService.new(reporter_project, user, archived: true).execute
|
2017-09-10 17:25:29 +05:30
|
|
|
other_reporter_project = create(:project)
|
2018-03-17 18:26:18 +05:30
|
|
|
other_reporter_project.add_reporter(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
|
|
|
expect(finder.execute.to_a).to eq([other_reporter_project])
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return projects for which issues are disabled' do
|
2018-03-17 18:26:18 +05:30
|
|
|
reporter_project.add_reporter(user)
|
2018-11-18 11:00:15 +05:30
|
|
|
reporter_project.update(issues_enabled: false)
|
2017-09-10 17:25:29 +05:30
|
|
|
other_reporter_project = create(:project)
|
2018-03-17 18:26:18 +05:30
|
|
|
other_reporter_project.add_reporter(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
|
|
|
expect(finder.execute.to_a).to eq([other_reporter_project])
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'returns a page of projects ordered by name' do
|
|
|
|
stub_const('Autocomplete::MoveToProjectFinder::LIMIT', 2)
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
projects = create_list(:project, 3) do |project|
|
2018-11-20 20:47:30 +05:30
|
|
|
project.add_developer(user)
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
page = finder.execute.to_a
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expected_projects = projects.sort_by(&:name).first(2)
|
|
|
|
expect(page.length).to eq(2)
|
|
|
|
expect(page).to eq(expected_projects)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
context 'search' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'returns projects matching a search query' do
|
2019-10-12 21:52:04 +05:30
|
|
|
foo_project = create(:project, name: 'foo')
|
2018-11-18 11:00:15 +05:30
|
|
|
foo_project.add_maintainer(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
wadus_project = create(:project, name: 'wadus')
|
2018-11-18 11:00:15 +05:30
|
|
|
wadus_project.add_maintainer(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
expect(described_class.new(user, project_id: project.id).execute.to_a)
|
2019-10-12 21:52:04 +05:30
|
|
|
.to eq([foo_project, wadus_project])
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
expect(described_class.new(user, project_id: project.id, search: 'wadus').execute.to_a)
|
|
|
|
.to eq([wadus_project])
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|