debian-mirror-gitlab/spec/requests/api/graphql/namespace/projects_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

117 lines
3.2 KiB
Ruby
Raw Normal View History

2019-09-04 21:01:54 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'getting projects', feature_category: :projects do
2019-09-04 21:01:54 +05:30
include GraphqlHelpers
let(:group) { create(:group) }
let!(:project) { create(:project, namespace: subject) }
let(:nested_group) { create(:group, parent: group) }
let!(:nested_project) { create(:project, group: nested_group) }
let!(:public_project) { create(:project, :public, namespace: subject) }
let(:user) { create(:user) }
let(:include_subgroups) { true }
subject { group }
let(:query) do
graphql_query_for(
'namespace',
{ 'fullPath' => subject.full_path },
<<~QUERY
projects(includeSubgroups: #{include_subgroups}) {
edges {
node {
2021-04-17 20:07:23 +05:30
#{all_graphql_fields_for('Project', max_depth: 1)}
2019-09-04 21:01:54 +05:30
}
}
}
QUERY
)
end
before do
group.add_owner(user)
end
shared_examples 'a graphql namespace' do
it_behaves_like 'a working graphql query' do
before do
post_graphql(query, current_user: user)
end
end
it "includes the packages size if the user can read the statistics" do
post_graphql(query, current_user: user)
count = if include_subgroups
subject.all_projects.count
else
subject.projects.count
end
expect(graphql_data['namespace']['projects']['edges'].size).to eq(count)
end
context 'with no user' do
it 'finds only public projects' do
post_graphql(query, current_user: nil)
expect(graphql_data['namespace']).to be_nil
end
end
end
it_behaves_like 'a graphql namespace'
context 'when the namespace is a user' do
subject { user.namespace }
2019-12-21 20:55:43 +05:30
2019-09-04 21:01:54 +05:30
let(:include_subgroups) { false }
it_behaves_like 'a graphql namespace'
end
context 'when not including subgroups' do
let(:include_subgroups) { false }
it_behaves_like 'a graphql namespace'
end
2020-11-24 15:15:51 +05:30
describe 'sorting and pagination' do
2021-02-22 17:27:13 +05:30
let_it_be(:ns) { create(:group) }
let_it_be(:current_user) { create(:user) }
let_it_be(:project_1) { create(:project, name: 'Project', path: 'project', namespace: ns) }
let_it_be(:project_2) { create(:project, name: 'Test Project', path: 'test-project', namespace: ns) }
let_it_be(:project_3) { create(:project, name: 'Test', path: 'test', namespace: ns) }
let_it_be(:project_4) { create(:project, name: 'Test Project Other', path: 'other-test-project', namespace: ns) }
2020-11-24 15:15:51 +05:30
let(:data_path) { [:namespace, :projects] }
2021-02-22 17:27:13 +05:30
let(:ns_args) { { full_path: ns.full_path } }
let(:search) { 'test' }
before do
ns.add_owner(current_user)
2020-11-24 15:15:51 +05:30
end
2021-02-22 17:27:13 +05:30
def pagination_query(params)
arguments = params.merge(include_subgroups: include_subgroups, search: search)
graphql_query_for(:namespace, ns_args, query_graphql_field(:projects, arguments, <<~GQL))
#{page_info}
nodes { name }
GQL
2020-11-24 15:15:51 +05:30
end
context 'when sorting by similarity' do
it_behaves_like 'sorted paginated query' do
2021-11-18 22:05:49 +05:30
let(:node_path) { %w[name] }
let(:sort_param) { :SIMILARITY }
let(:first_param) { 2 }
let(:all_records) { [project_3.name, project_2.name, project_4.name] }
2020-11-24 15:15:51 +05:30
end
end
end
2019-09-04 21:01:54 +05:30
end