2019-10-16 05:07:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe Autocomplete::MoveToProjectFinder do
|
2020-03-23 08:09:47 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:no_access_project) { create(:project) }
|
|
|
|
let(:guest_project) { create(:project) }
|
2019-07-22 07:44:20 -04:00
|
|
|
let(:reporter_project) { create(:project, name: 'name') }
|
|
|
|
let(:developer_project) { create(:project, name: 'name2') }
|
|
|
|
let(:maintainer_project) { create(:project, name: 'name3') }
|
2016-08-05 09:29:20 -04:00
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
context 'filter' do
|
|
|
|
it 'does not return projects under Gitlab::Access::REPORTER' do
|
2017-12-22 03:18:28 -05:00
|
|
|
guest_project.add_guest(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
|
|
|
expect(finder.execute).to be_empty
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
2020-08-12 14:10:05 -04:00
|
|
|
it 'returns projects equal or above Gitlab::Access::REPORTER' do
|
2017-12-22 03:18:28 -05:00
|
|
|
reporter_project.add_reporter(user)
|
|
|
|
developer_project.add_developer(user)
|
2018-07-11 10:36:08 -04:00
|
|
|
maintainer_project.add_maintainer(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
2020-08-12 14:10:05 -04:00
|
|
|
expect(finder.execute.to_a).to contain_exactly(reporter_project, developer_project, maintainer_project)
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include the source project' do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_reporter(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
|
|
|
expect(finder.execute.to_a).to be_empty
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return archived projects' do
|
2017-12-22 03:18:28 -05:00
|
|
|
reporter_project.add_reporter(user)
|
2018-08-02 15:39:46 -04:00
|
|
|
::Projects::UpdateService.new(reporter_project, user, archived: true).execute
|
2017-08-02 15:55:11 -04:00
|
|
|
other_reporter_project = create(:project)
|
2017-12-22 03:18:28 -05:00
|
|
|
other_reporter_project.add_reporter(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
|
|
|
expect(finder.execute.to_a).to eq([other_reporter_project])
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return projects for which issues are disabled' do
|
2017-12-22 03:18:28 -05:00
|
|
|
reporter_project.add_reporter(user)
|
2020-08-04 17:09:56 -04:00
|
|
|
reporter_project.update!(issues_enabled: false)
|
2017-08-02 15:55:11 -04:00
|
|
|
other_reporter_project = create(:project)
|
2017-12-22 03:18:28 -05:00
|
|
|
other_reporter_project.add_reporter(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
|
|
|
|
expect(finder.execute.to_a).to eq([other_reporter_project])
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
it 'returns a page of projects ordered by star count' do
|
2019-07-22 07:44:20 -04:00
|
|
|
stub_const('Autocomplete::MoveToProjectFinder::LIMIT', 2)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
projects = [
|
|
|
|
create(:project, namespace: user.namespace, star_count: 1),
|
|
|
|
create(:project, namespace: user.namespace, star_count: 5),
|
|
|
|
create(:project, namespace: user.namespace)
|
|
|
|
]
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
finder = described_class.new(user, project_id: project.id)
|
|
|
|
page = finder.execute.to_a
|
|
|
|
|
2019-07-22 07:44:20 -04:00
|
|
|
expect(page.length).to eq(2)
|
2020-04-21 11:21:10 -04:00
|
|
|
expect(page).to eq([projects[1], projects[0]])
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2018-07-30 11:45:49 -04:00
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
context 'search' do
|
2016-08-05 09:29:20 -04:00
|
|
|
it 'returns projects matching a search query' do
|
2019-07-22 07:44:20 -04:00
|
|
|
foo_project = create(:project, name: 'foo')
|
2018-07-11 10:36:08 -04:00
|
|
|
foo_project.add_maintainer(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2017-08-02 15:55:11 -04:00
|
|
|
wadus_project = create(:project, name: 'wadus')
|
2018-07-11 10:36:08 -04:00
|
|
|
wadus_project.add_maintainer(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
expect(described_class.new(user, project_id: project.id).execute.to_a)
|
2020-08-12 14:10:05 -04:00
|
|
|
.to contain_exactly(foo_project, wadus_project)
|
2018-07-30 11:45:49 -04:00
|
|
|
|
|
|
|
expect(described_class.new(user, project_id: project.id, search: 'wadus').execute.to_a)
|
2020-08-12 14:10:05 -04:00
|
|
|
.to contain_exactly(wadus_project)
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2020-03-23 08:09:47 -04:00
|
|
|
|
|
|
|
it 'allows searching by parent namespace' do
|
|
|
|
group = create(:group)
|
|
|
|
other_project = create(:project, group: group)
|
|
|
|
other_project.add_maintainer(user)
|
|
|
|
|
|
|
|
expect(described_class.new(user, project_id: project.id, search: group.name).execute.to_a)
|
|
|
|
.to contain_exactly(other_project)
|
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|