Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
d693c3e5
Commit
d693c3e5
authored
5 years ago
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor group query spec
and removing unnecessary code
parent
f5c7c3b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
107 deletions
+28
-107
app/graphql/types/namespace_type.rb
app/graphql/types/namespace_type.rb
+4
-4
spec/requests/api/graphql/group_query_spec.rb
spec/requests/api/graphql/group_query_spec.rb
+24
-103
No files found.
app/graphql/types/namespace_type.rb
View file @
d693c3e5
...
...
@@ -5,15 +5,15 @@ module Types
graphql_name
'Namespace'
field
:id
,
GraphQL
::
ID_TYPE
,
null:
false
field
:name
,
GraphQL
::
STRING_TYPE
,
null:
false
field
:name
,
GraphQL
::
STRING_TYPE
,
null:
false
field
:path
,
GraphQL
::
STRING_TYPE
,
null:
false
field
:full_name
,
GraphQL
::
STRING_TYPE
,
null:
false
field
:full_path
,
GraphQL
::
ID_TYPE
,
null:
false
field
:description
,
GraphQL
::
STRING_TYPE
,
null:
true
field
:visibility
,
GraphQL
::
STRING_TYPE
,
null:
true
field
:lfs_enabled
,
GraphQL
::
BOOLEAN_TYPE
,
null:
true
,
method: :lfs_enabled?
field
:request_access_enabled
,
GraphQL
::
BOOLEAN_TYPE
,
null:
true
field
:full_path
,
GraphQL
::
ID_TYPE
,
null:
false
field
:full_name
,
GraphQL
::
STRING_TYPE
,
null:
false
end
end
This diff is collapsed.
Click to expand it.
spec/requests/api/graphql/group_query_spec.rb
View file @
d693c3e5
# frozen_string_literal: true
require
'spec_helper'
# Based on spec/requests/api/groups_spec.rb
...
...
@@ -6,95 +8,47 @@ describe 'getting group information' do
include
GraphqlHelpers
include
UploadHelpers
let
(
:user1
)
{
create
(
:user
,
can_create_group:
false
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let!
(
:group1
)
{
create
(
:group
,
avatar:
File
.
open
(
uploaded_image_temp_path
))
}
let!
(
:group2
)
{
create
(
:group
,
:private
)
}
# let!(:project1) { create(:project, namespace: group1) }
# let!(:project2) { create(:project, namespace: group2) }
# let!(:project3) { create(:project, namespace: group1, path: 'test', visibility_level: Gitlab::VisibilityLevel::PRIVATE) }
before
do
group1
.
add_owner
(
user1
)
group2
.
add_owner
(
user2
)
end
let
(
:user1
)
{
create
(
:user
,
can_create_group:
false
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:public_group
)
{
create
(
:group
,
:public
)
}
let
(
:private_group
)
{
create
(
:group
,
:private
)
}
# similar to the API "GET /groups/:id"
describe
"Query group(fullPath)"
do
# Given a group, create one project for each visibility level
#
# group - Group to add projects to
# share_with - If provided, each project will be shared with this Group
#
# Returns a Hash of visibility_level => Project pairs
def
add_projects_to_group
(
group
,
share_with:
nil
)
projects
=
{
public:
create
(
:project
,
:public
,
namespace:
group
),
internal:
create
(
:project
,
:internal
,
namespace:
group
),
private:
create
(
:project
,
:private
,
namespace:
group
)
}
if
share_with
create
(
:project_group_link
,
project:
projects
[
:public
],
group:
share_with
)
create
(
:project_group_link
,
project:
projects
[
:internal
],
group:
share_with
)
create
(
:project_group_link
,
project:
projects
[
:private
],
group:
share_with
)
end
projects
end
def
response_project_ids
(
json_response
,
key
)
json_response
[
key
].
map
do
|
project
|
project
[
'id'
].
to_i
end
end
def
group_query
(
group
)
graphql_query_for
(
'group'
,
'fullPath'
=>
group
.
full_path
)
end
it_behaves_like
'a working graphql query'
do
before
do
post_graphql
(
group_query
(
group1
))
post_graphql
(
group_query
(
public_group
))
end
end
context
'when unauthenticated'
do
it
'returns nil for a private group'
do
post_graphql
(
group_query
(
group2
))
post_graphql
(
group_query
(
private_group
))
expect
(
graphql_data
[
'group'
]).
to
be_nil
end
it
'returns a public group'
do
post_graphql
(
group_query
(
group1
))
post_graphql
(
group_query
(
public_group
))
expect
(
graphql_data
[
'group'
]).
not_to
be_nil
end
# it 'returns only public projects in the group' do
# public_group = create(:group, :public)
# projects = add_projects_to_group(public_group)
#
# get api("/groups/#{public_group.id}")
#
# expect(response_project_ids(json_response, 'projects'))
# .to contain_exactly(projects[:public].id)
# end
# it 'returns only public projects shared with the group' do
# public_group = create(:group, :public)
# projects = add_projects_to_group(public_group, share_with: group1)
#
# get api("/groups/#{group1.id}")
#
# expect(response_project_ids(json_response, 'shared_projects'))
# .to contain_exactly(projects[:public].id)
# end
end
context
"when authenticated as user"
do
let!
(
:group1
)
{
create
(
:group
,
avatar:
File
.
open
(
uploaded_image_temp_path
))
}
let!
(
:group2
)
{
create
(
:group
,
:private
)
}
before
do
group1
.
add_owner
(
user1
)
group2
.
add_owner
(
user2
)
end
it
"returns one of user1's groups"
do
project
=
create
(
:project
,
namespace:
group2
,
path:
'Foo'
)
create
(
:project_group_link
,
project:
project
,
group:
group1
)
...
...
@@ -113,57 +67,24 @@ describe 'getting group information' do
expect
(
graphql_data
[
'group'
][
'fullName'
]).
to
eq
(
group1
.
full_name
)
expect
(
graphql_data
[
'group'
][
'fullPath'
]).
to
eq
(
group1
.
full_path
)
expect
(
graphql_data
[
'group'
][
'parentId'
]).
to
eq
(
group1
.
parent_id
)
# expect(graphql_data['group']['projects']).to be_an Array
# expect(graphql_data['group']['projects'].length).to eq(2)
# expect(graphql_data['group']['sharedProjects']).to be_an Array
# expect(graphql_data['group']['sharedProjects'].length).to eq(1)
# expect(graphql_data['group']['sharedProjects'][0]['id']).to eq(project.id)
end
# it "returns one of user1's groups without projects when with_projects option is set to false" do
# project = create(:project, namespace: group2, path: 'Foo')
# create(:project_group_link, project: project, group: group1)
#
# get api("/groups/#{group1.id}", user1), params: { with_projects: false }
#
# expect(response).to have_gitlab_http_status(200)
# expect(json_response['projects']).to be_nil
# expect(json_response['shared_projects']).to be_nil
# end
it
"does not return a non existing group"
do
query
=
graphql_query_for
(
'group'
,
'fullPath'
=>
'1328'
)
post_graphql
(
query
,
current_user:
user1
)
expect
(
graphql_data
[
'group'
]).
to
be_nil
end
it
"does not return a group not attached to user1"
do
post_graphql
(
group_query
(
group2
),
current_user:
user1
)
private_group
.
add_owner
(
user2
)
post_graphql
(
group_query
(
private_group
),
current_user:
user1
)
expect
(
graphql_data
[
'group'
]).
to
be_nil
end
# it 'returns only public and internal projects in the group' do
# public_group = create(:group, :public)
# projects = add_projects_to_group(public_group)
#
# get api("/groups/#{public_group.id}", user2)
#
# expect(response_project_ids(json_response, 'projects'))
# .to contain_exactly(projects[:public].id, projects[:internal].id)
# end
# it 'returns only public and internal projects shared with the group' do
# public_group = create(:group, :public)
# projects = add_projects_to_group(public_group, share_with: group1)
#
# get api("/groups/#{group1.id}", user2)
#
# expect(response_project_ids(json_response, 'shared_projects'))
# .to contain_exactly(projects[:public].id, projects[:internal].id)
# end
it
'avoids N+1 queries'
do
post_graphql
(
group_query
(
group1
),
current_user:
admin
)
...
...
@@ -181,9 +102,9 @@ describe 'getting group information' do
context
"when authenticated as admin"
do
it
"returns any existing group"
do
post_graphql
(
group_query
(
group2
),
current_user:
admin
)
post_graphql
(
group_query
(
private_group
),
current_user:
admin
)
expect
(
graphql_data
[
'group'
][
'name'
]).
to
eq
(
group2
.
name
)
expect
(
graphql_data
[
'group'
][
'name'
]).
to
eq
(
private_group
.
name
)
end
it
"does not return a non existing group"
do
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment