1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'searching groups', :with_license, feature_category: :groups_and_projects do
include GraphqlHelpers
using RSpec::Parameterized::TableSyntax
let_it_be(:user) { create(:user) }
let_it_be(:public_group) { create(:group, :public, name: 'Group A') }
let_it_be(:private_group) { create(:group, :private, name: 'Group B') }
let(:current_user) { user }
let(:fields) do
<<~FIELDS
nodes {
#{all_graphql_fields_for('Group', excluded: %w[runners ciQueueingHistory])}
}
FIELDS
end
let(:query) do
<<~QUERY
query {
groups {
#{fields}
}
}
QUERY
end
subject { post_graphql(query, current_user: user) }
describe "Query groups(search)" do
let(:groups) { graphql_data_at(:groups, :nodes) }
let(:names) { groups.map { |group| group["name"] } } # rubocop: disable Rails/Pluck
it_behaves_like 'a working graphql query' do
before do
subject
end
end
it 'includes public groups' do
subject
expect(names).to eq([public_group.name])
end
it 'includes accessible private groups ordered by name' do
private_group.add_maintainer(user)
subject
expect(names).to eq([public_group.name, private_group.name])
end
context 'with `search` argument' do
let_it_be(:other_group) { create(:group, name: 'other-group') }
let(:query) do
<<~QUERY
query {
groups(search: "oth") {
#{fields}
}
}
QUERY
end
it 'filters groups by name' do
subject
expect(names).to contain_exactly(other_group.name)
end
end
end
describe 'group sorting' do
let_it_be(:public_group2) { create(:group, :public, name: 'Group C') }
let_it_be(:public_group3) { create(:group, :public, name: 'Group D') }
let_it_be(:all_groups) { [public_group, public_group2, public_group3] }
let_it_be(:first_param) { 2 }
let_it_be(:data_path) { [:groups] }
where(:field, :direction, :sorted_groups) do
'id' | 'asc' | lazy { all_groups.sort_by(&:id) }
'id' | 'desc' | lazy { all_groups.sort_by(&:id).reverse }
'name' | 'asc' | lazy { all_groups.sort_by(&:name) }
'name' | 'desc' | lazy { all_groups.sort_by(&:name).reverse }
'path' | 'asc' | lazy { all_groups.sort_by(&:path) }
'path' | 'desc' | lazy { all_groups.sort_by(&:path).reverse }
end
with_them do
it_behaves_like 'sorted paginated query' do
let(:sort_param) { "#{field}_#{direction}" }
let(:all_records) { sorted_groups.map { |p| global_id_of(p).to_s } }
end
end
def pagination_query(params)
graphql_query_for(
'', {},
query_nodes(:groups, :id, include_pagination_info: true, args: params)
)
end
end
end
|