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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
1b52e42f
Commit
1b52e42f
authored
May 15, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add files argument to snippets create mutation
parent
1e87c00a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
11 deletions
+78
-11
app/graphql/mutations/snippets/create.rb
app/graphql/mutations/snippets/create.rb
+9
-0
changelogs/unreleased/fj-add-files-param-snippet-create-mutation.yml
...unreleased/fj-add-files-param-snippet-create-mutation.yml
+5
-0
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+5
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+18
-0
spec/requests/api/graphql/mutations/snippets/create_spec.rb
spec/requests/api/graphql/mutations/snippets/create_spec.rb
+41
-11
No files found.
app/graphql/mutations/snippets/create.rb
View file @
1b52e42f
...
...
@@ -36,6 +36,10 @@ module Mutations
required:
false
,
description:
'The project full path the snippet is associated with'
argument
:uploaded_files
,
[
GraphQL
::
STRING_TYPE
],
required:
false
,
description:
'The paths to files uploaded in the snippet description'
def
resolve
(
args
)
project_path
=
args
.
delete
(
:project_path
)
...
...
@@ -45,9 +49,14 @@ module Mutations
raise_resource_not_available_error!
end
# We need to rename `uploaded_files` into `files` because
# it's the expected key param
args
[
:files
]
=
args
.
delete
(
:uploaded_files
)
service_response
=
::
Snippets
::
CreateService
.
new
(
project
,
context
[
:current_user
],
args
).
execute
snippet
=
service_response
.
payload
[
:snippet
]
{
...
...
changelogs/unreleased/fj-add-files-param-snippet-create-mutation.yml
0 → 100644
View file @
1b52e42f
---
title
:
Add files param to snippet create mutation
merge_request
:
32309
author
:
type
:
changed
doc/api/graphql/reference/gitlab_schema.graphql
View file @
1b52e42f
...
...
@@ -1334,6 +1334,11 @@ input CreateSnippetInput {
"""
title
:
String
!
"""
The
paths
to
files
uploaded
in
the
snippet
description
"""
uploadedFiles
:
[
String
!]
"""
The
visibility
level
of
the
snippet
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
1b52e42f
...
...
@@ -3608,6 +3608,24 @@
},
"defaultValue": null
},
{
"name": "uploadedFiles",
"description": "The paths to files uploaded in the snippet description",
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
},
"defaultValue": null
},
{
"name": "clientMutationId",
"description": "A unique identifier for the client performing the mutation.",
spec/requests/api/graphql/mutations/snippets/create_spec.rb
View file @
1b52e42f
...
...
@@ -13,6 +13,7 @@ describe 'Creating a Snippet' do
let
(
:file_name
)
{
'Initial file_name'
}
let
(
:visibility_level
)
{
'public'
}
let
(
:project_path
)
{
nil
}
let
(
:uploaded_files
)
{
nil
}
let
(
:mutation
)
do
variables
=
{
...
...
@@ -21,7 +22,8 @@ describe 'Creating a Snippet' do
visibility_level:
visibility_level
,
file_name:
file_name
,
title:
title
,
project_path:
project_path
project_path:
project_path
,
uploaded_files:
uploaded_files
}
graphql_mutation
(
:create_snippet
,
variables
)
...
...
@@ -31,6 +33,8 @@ describe 'Creating a Snippet' do
graphql_mutation_response
(
:create_snippet
)
end
subject
{
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
}
context
'when the user does not have permission'
do
let
(
:current_user
)
{
nil
}
...
...
@@ -39,7 +43,7 @@ describe 'Creating a Snippet' do
it
'does not create the Snippet'
do
expect
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
subject
end
.
not_to
change
{
Snippet
.
count
}
end
...
...
@@ -48,7 +52,7 @@ describe 'Creating a Snippet' do
it
'does not create the snippet when the user is not authorized'
do
expect
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
subject
end
.
not_to
change
{
Snippet
.
count
}
end
end
...
...
@@ -60,12 +64,12 @@ describe 'Creating a Snippet' do
context
'with PersonalSnippet'
do
it
'creates the Snippet'
do
expect
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
subject
end
.
to
change
{
Snippet
.
count
}.
by
(
1
)
end
it
'returns the created Snippet'
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
subject
expect
(
mutation_response
[
'snippet'
][
'blob'
][
'richData'
]).
to
be_nil
expect
(
mutation_response
[
'snippet'
][
'blob'
][
'plainData'
]).
to
match
(
content
)
...
...
@@ -86,12 +90,12 @@ describe 'Creating a Snippet' do
it
'creates the Snippet'
do
expect
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
subject
end
.
to
change
{
Snippet
.
count
}.
by
(
1
)
end
it
'returns the created Snippet'
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
subject
expect
(
mutation_response
[
'snippet'
][
'blob'
][
'richData'
]).
to
be_nil
expect
(
mutation_response
[
'snippet'
][
'blob'
][
'plainData'
]).
to
match
(
content
)
...
...
@@ -106,7 +110,7 @@ describe 'Creating a Snippet' do
let
(
:project_path
)
{
'foobar'
}
it
'returns an an error'
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
subject
errors
=
json_response
[
'errors'
]
expect
(
errors
.
first
[
'message'
]).
to
eq
(
Gitlab
::
Graphql
::
Authorize
::
AuthorizeResource
::
RESOURCE_ACCESS_ERROR
)
...
...
@@ -117,7 +121,7 @@ describe 'Creating a Snippet' do
it
'returns an an error'
do
project
.
project_feature
.
update_attribute
(
:snippets_access_level
,
ProjectFeature
::
DISABLED
)
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
subject
errors
=
json_response
[
'errors'
]
expect
(
errors
.
first
[
'message'
]).
to
eq
(
Gitlab
::
Graphql
::
Authorize
::
AuthorizeResource
::
RESOURCE_ACCESS_ERROR
)
...
...
@@ -132,15 +136,41 @@ describe 'Creating a Snippet' do
it
'does not create the Snippet'
do
expect
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
subject
end
.
not_to
change
{
Snippet
.
count
}
end
it
'does not return Snippet'
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
subject
expect
(
mutation_response
[
'snippet'
]).
to
be_nil
end
end
context
'when there uploaded files'
do
shared_examples
'expected files argument'
do
|
file_value
,
expected_value
|
let
(
:uploaded_files
)
{
file_value
}
it
do
expect
(
::
Snippets
::
CreateService
).
to
receive
(
:new
).
with
(
nil
,
user
,
hash_including
(
files:
expected_value
))
subject
end
end
it_behaves_like
'expected files argument'
,
nil
,
nil
it_behaves_like
'expected files argument'
,
%w(foo bar)
,
%w(foo bar)
it_behaves_like
'expected files argument'
,
'foo'
,
%w(foo)
context
'when files has an invalid value'
do
let
(
:uploaded_files
)
{
[
1
]
}
it
'returns an error'
do
subject
expect
(
json_response
[
'errors'
]).
to
be
end
end
end
end
end
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