Commit 6e48a8e0 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch...

Merge branch '263249-project_finder_similarity_sort-enable-project-search-by-similarity-remove-flag' into 'master'

Remove project_finder_similarity_sort feature flag

See merge request gitlab-org/gitlab!64361
parents 636fd258 dda10f5a
...@@ -55,7 +55,7 @@ class ProjectsFinder < UnionFinder ...@@ -55,7 +55,7 @@ class ProjectsFinder < UnionFinder
collection = Project.wrap_with_cte(collection) if use_cte collection = Project.wrap_with_cte(collection) if use_cte
collection = filter_projects(collection) collection = filter_projects(collection)
if params[:sort] == 'similarity' && params[:search] && Feature.enabled?(:project_finder_similarity_sort, current_user) if params[:sort] == 'similarity' && params[:search]
collection.sorted_by_similarity_desc(params[:search]) collection.sorted_by_similarity_desc(params[:search])
else else
sort(collection) sort(collection)
......
---
name: project_finder_similarity_sort
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/43136
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/263249
milestone: '13.5'
type: development
group: group::threat insights
default_enabled: false
...@@ -31,10 +31,6 @@ RSpec.describe ProjectsFinder do ...@@ -31,10 +31,6 @@ RSpec.describe ProjectsFinder do
let(:use_cte) { true } let(:use_cte) { true }
let(:finder) { described_class.new(params: params.merge(use_cte: use_cte), current_user: current_user, project_ids_relation: project_ids_relation) } let(:finder) { described_class.new(params: params.merge(use_cte: use_cte), current_user: current_user, project_ids_relation: project_ids_relation) }
before do
stub_feature_flags(project_finder_similarity_sort: false)
end
subject { finder.execute } subject { finder.execute }
shared_examples 'ProjectFinder#execute examples' do shared_examples 'ProjectFinder#execute examples' do
...@@ -368,32 +364,28 @@ RSpec.describe ProjectsFinder do ...@@ -368,32 +364,28 @@ RSpec.describe ProjectsFinder do
end end
describe 'sorting' do describe 'sorting' do
let_it_be(:more_projects) do
[
create(:project, :internal, group: group, name: 'projA', path: 'projA'),
create(:project, :internal, group: group, name: 'projABC', path: 'projABC'),
create(:project, :internal, group: group, name: 'projAB', path: 'projAB')
]
end
context 'when sorting by a field' do context 'when sorting by a field' do
let(:params) { { sort: 'name_asc' } } let(:params) { { sort: 'name_asc' } }
it { is_expected.to eq([internal_project, public_project]) } it { is_expected.to eq(([internal_project, public_project] + more_projects).sort_by { |p| p[:name] }) }
end end
context 'when sorting by similarity' do context 'when sorting by similarity' do
let(:params) { { sort: 'similarity', search: 'pro' } } let(:params) { { sort: 'similarity', search: 'pro' } }
let_it_be(:internal_project2) do it { is_expected.to eq([more_projects[0], more_projects[2], more_projects[1]]) }
create(:project, :internal, group: group, name: 'projA', path: 'projA') end
end
let_it_be(:internal_project3) do
create(:project, :internal, group: group, name: 'projABC', path: 'projABC')
end
let_it_be(:internal_project4) do
create(:project, :internal, group: group, name: 'projAB', path: 'projAB')
end
before do
stub_feature_flags(project_finder_similarity_sort: current_user)
end
it { is_expected.to eq([internal_project2, internal_project4, internal_project3]) } context 'when no sort is provided' do
it { is_expected.to eq(([internal_project, public_project] + more_projects).sort_by { |p| p[:id] }.reverse) }
end end
end end
......
...@@ -27,10 +27,6 @@ RSpec.describe Resolvers::ProjectsResolver do ...@@ -27,10 +27,6 @@ RSpec.describe Resolvers::ProjectsResolver do
private_group.add_developer(user) private_group.add_developer(user)
end end
before do
stub_feature_flags(project_finder_similarity_sort: false)
end
context 'when user is not logged in' do context 'when user is not logged in' do
let(:current_user) { nil } let(:current_user) { nil }
...@@ -83,6 +79,7 @@ RSpec.describe Resolvers::ProjectsResolver do ...@@ -83,6 +79,7 @@ RSpec.describe Resolvers::ProjectsResolver do
context 'when user is logged in' do context 'when user is logged in' do
let(:current_user) { user } let(:current_user) { user }
let(:visible_projecs) { [project, other_project, group_project, private_project, private_group_project] }
context 'when no filters are applied' do context 'when no filters are applied' do
it 'returns all visible projects for the user' do it 'returns all visible projects for the user' do
...@@ -129,21 +126,24 @@ RSpec.describe Resolvers::ProjectsResolver do ...@@ -129,21 +126,24 @@ RSpec.describe Resolvers::ProjectsResolver do
end end
end end
context 'when sort is similarity' do context 'when sorting' do
let_it_be(:named_project1) { create(:project, :public, name: 'projAB', path: 'projAB') } let_it_be(:named_project1) { create(:project, :public, name: 'projAB', path: 'projAB') }
let_it_be(:named_project2) { create(:project, :public, name: 'projABC', path: 'projABC') } let_it_be(:named_project2) { create(:project, :public, name: 'projABC', path: 'projABC') }
let_it_be(:named_project3) { create(:project, :public, name: 'projA', path: 'projA') } let_it_be(:named_project3) { create(:project, :public, name: 'projA', path: 'projA') }
let_it_be(:named_projects) { [named_project1, named_project2, named_project3] }
let(:filters) { { search: 'projA', sort: 'similarity' } } context 'when sorting by similarity' do
let(:filters) { { search: 'projA', sort: 'similarity' } }
it 'returns projects in order of similarity to search' do
stub_feature_flags(project_finder_similarity_sort: current_user)
is_expected.to eq([named_project3, named_project1, named_project2]) it 'returns projects in order of similarity to search' do
is_expected.to eq([named_project3, named_project1, named_project2])
end
end end
it 'returns projects in any order if flag is off' do context 'when no sort is provided' do
is_expected.to match_array([named_project3, named_project1, named_project2]) it 'returns projects in descending order by id' do
is_expected.to match_array((visible_projecs + named_projects).sort_by { |p| p[:id]}.reverse )
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment