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
edafda79
Commit
edafda79
authored
Sep 09, 2020
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to create test cases on GraphQL
Add GraphQL mutation to create test cases
parent
30c193a0
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
405 additions
and
1 deletion
+405
-1
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+51
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+171
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+10
-0
ee/app/graphql/ee/types/mutation_type.rb
ee/app/graphql/ee/types/mutation_type.rb
+1
-0
ee/app/graphql/mutations/quality_management/test_cases/create.rb
...graphql/mutations/quality_management/test_cases/create.rb
+60
-0
ee/app/services/quality_management/test_cases/create_service.rb
.../services/quality_management/test_cases/create_service.rb
+1
-1
ee/changelogs/unreleased/issue_233479_add_graphql_create_mutation.yml
...s/unreleased/issue_233479_add_graphql_create_mutation.yml
+5
-0
ee/spec/requests/api/graphql/mutations/quality_management/test_cases/create_spec.rb
...ql/mutations/quality_management/test_cases/create_spec.rb
+106
-0
No files found.
doc/api/graphql/reference/gitlab_schema.graphql
View file @
edafda79
...
...
@@ -3004,6 +3004,56 @@ type CreateSnippetPayload {
snippet
:
Snippet
}
"""
Autogenerated input type of CreateTestCase
"""
input
CreateTestCaseInput
{
"""
A
unique
identifier
for
the
client
performing
the
mutation
.
"""
clientMutationId
:
String
"""
The
test
case
description
"""
description
:
String
"""
The
IDs
of
labels
to
be
added
to
the
test
case
.
"""
labelIds
:
[
ID
!]
"""
The
project
full
path
to
create
the
test
case
"""
projectPath
:
ID
!
"""
The
test
case
title
"""
title
:
String
!
}
"""
Autogenerated return type of CreateTestCase
"""
type
CreateTestCasePayload
{
"""
A
unique
identifier
for
the
client
performing
the
mutation
.
"""
clientMutationId
:
String
"""
Errors
encountered
during
execution
of
the
mutation
.
"""
errors
:
[
String
!]!
"""
The
test
case
created
"""
testCase
:
Issue
}
interface
CurrentUserTodos
{
"""
Todos
for
the
current
user
...
...
@@ -10672,6 +10722,7 @@ type Mutation {
createNote
(
input
:
CreateNoteInput
!):
CreateNotePayload
createRequirement
(
input
:
CreateRequirementInput
!):
CreateRequirementPayload
createSnippet
(
input
:
CreateSnippetInput
!):
CreateSnippetPayload
createTestCase
(
input
:
CreateTestCaseInput
!):
CreateTestCasePayload
dastOnDemandScanCreate
(
input
:
DastOnDemandScanCreateInput
!):
DastOnDemandScanCreatePayload
dastScannerProfileCreate
(
input
:
DastScannerProfileCreateInput
!):
DastScannerProfileCreatePayload
dastScannerProfileDelete
(
input
:
DastScannerProfileDeleteInput
!):
DastScannerProfileDeletePayload
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
edafda79
...
...
@@ -8150,6 +8150,150 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "CreateTestCaseInput",
"description": "Autogenerated input type of CreateTestCase",
"fields": null,
"inputFields": [
{
"name": "title",
"description": "The test case title",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "description",
"description": "The test case description",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "labelIds",
"description": "The IDs of labels to be added to the test case.",
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
}
},
"defaultValue": null
},
{
"name": "projectPath",
"description": "The project full path to create the test case",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "clientMutationId",
"description": "A unique identifier for the client performing the mutation.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "CreateTestCasePayload",
"description": "Autogenerated return type of CreateTestCase",
"fields": [
{
"name": "clientMutationId",
"description": "A unique identifier for the client performing the mutation.",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "errors",
"description": "Errors encountered during execution of the mutation.",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "testCase",
"description": "The test case created",
"args": [
],
"type": {
"kind": "OBJECT",
"name": "Issue",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INTERFACE",
"name": "CurrentUserTodos",
...
...
@@ -30360,6 +30504,33 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createTestCase",
"description": null,
"args": [
{
"name": "input",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "CreateTestCaseInput",
"ofType": null
}
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "CreateTestCasePayload",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "dastOnDemandScanCreate",
"description": null,
doc/api/graphql/reference/index.md
View file @
edafda79
...
...
@@ -511,6 +511,16 @@ Autogenerated return type of CreateSnippet
|
`errors`
| String! => Array | Errors encountered during execution of the mutation. |
|
`snippet`
| Snippet | The snippet after mutation |
### CreateTestCasePayload
Autogenerated return type of CreateTestCase
| Field | Type | Description |
| ----- | ---- | ----------- |
|
`clientMutationId`
| String | A unique identifier for the client performing the mutation. |
|
`errors`
| String! => Array | Errors encountered during execution of the mutation. |
|
`testCase`
| Issue | The test case created |
### DastOnDemandScanCreatePayload
Autogenerated return type of DastOnDemandScanCreate
...
...
ee/app/graphql/ee/types/mutation_type.rb
View file @
edafda79
...
...
@@ -37,6 +37,7 @@ module EE
mount_mutation
::
Mutations
::
DastScannerProfiles
::
Delete
mount_mutation
::
Mutations
::
Security
::
CiConfiguration
::
ConfigureSast
mount_mutation
::
Mutations
::
Namespaces
::
IncreaseStorageTemporarily
mount_mutation
::
Mutations
::
QualityManagement
::
TestCases
::
Create
end
end
end
...
...
ee/app/graphql/mutations/quality_management/test_cases/create.rb
0 → 100644
View file @
edafda79
# frozen_string_literal: true
module
Mutations
module
QualityManagement
module
TestCases
class
Create
<
BaseMutation
include
ResolvesProject
graphql_name
'CreateTestCase'
authorize
:admin_issue
argument
:title
,
GraphQL
::
STRING_TYPE
,
required:
true
,
description:
'The test case title'
argument
:description
,
GraphQL
::
STRING_TYPE
,
required:
false
,
description:
'The test case description'
argument
:label_ids
,
[
GraphQL
::
ID_TYPE
],
required:
false
,
description:
'The IDs of labels to be added to the test case.'
argument
:project_path
,
GraphQL
::
ID_TYPE
,
required:
true
,
description:
'The project full path to create the test case'
field
:test_case
,
Types
::
IssueType
,
null:
true
,
description:
'The test case created'
def
resolve
(
args
)
project_path
=
args
.
delete
(
:project_path
)
project
=
authorized_find!
(
full_path:
project_path
)
result
=
::
QualityManagement
::
TestCases
::
CreateService
.
new
(
project
,
context
[
:current_user
],
**
args
).
execute
test_case
=
result
.
payload
[
:issue
]
{
test_case:
test_case
&
.
persisted?
?
test_case
:
nil
,
errors:
Array
.
wrap
(
result
.
message
)
}
end
private
def
find_object
(
full_path
:)
resolve_project
(
full_path:
full_path
)
end
end
end
end
end
ee/app/services/quality_management/test_cases/create_service.rb
View file @
edafda79
...
...
@@ -5,7 +5,7 @@ module QualityManagement
class
CreateService
<
BaseService
ISSUE_TYPE
=
'test_case'
def
initialize
(
project
,
current_user
,
title
:,
description
:,
label_ids:
[])
def
initialize
(
project
,
current_user
,
title
:,
description:
nil
,
label_ids:
[])
super
(
project
,
current_user
)
@title
=
title
...
...
ee/changelogs/unreleased/issue_233479_add_graphql_create_mutation.yml
0 → 100644
View file @
edafda79
---
title
:
Add GraphQL mutation to create test cases
merge_request
:
41190
author
:
type
:
added
ee/spec/requests/api/graphql/mutations/quality_management/test_cases/create_spec.rb
0 → 100644
View file @
edafda79
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'Create test case'
do
include
GraphqlHelpers
let_it_be_with_refind
(
:project
)
{
create
(
:project
,
:private
)
}
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:label
)
{
create
(
:label
,
project:
project
)
}
let
(
:variables
)
{
{
project_path:
project
.
full_path
,
title:
'foo'
,
description:
'bar'
,
label_ids:
[
label
.
id
]
}
}
let
(
:mutation
)
do
graphql_mutation
(
:create_test_case
,
variables
)
do
<<~
QL
clientMutationId
errors
testCase {
title
description
labels {
edges {
node {
id
}
}
}
}
QL
end
end
def
mutation_response
graphql_mutation_response
(
:create_test_case
)
end
describe
'#resolve'
do
context
'when quality management feature is not available'
do
before
do
stub_licensed_features
(
quality_management:
false
)
end
it_behaves_like
'a mutation that returns top-level errors'
,
errors:
[
'The resource that you are attempting to access does not exist '
\
'or you don\'t have permission to perform this action'
]
context
'with authorized logged user'
,
:aggregate_failures
do
before_all
do
project
.
add_reporter
(
current_user
)
end
it_behaves_like
'a mutation that returns errors in the response'
,
errors:
[
"Test cases are not available for this project"
]
end
end
context
'when quality management feature is available'
do
before
do
stub_licensed_features
(
quality_management:
true
)
end
context
'when user can create test cases'
do
before_all
do
project
.
add_reporter
(
current_user
)
end
it
'creates new test case'
,
:aggregate_failures
do
expect
{
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
}.
to
change
{
Issue
.
count
}.
by
(
1
)
test_case
=
mutation_response
[
'testCase'
]
expect
(
test_case
).
not_to
be_nil
expect
(
test_case
[
'title'
]).
to
eq
(
'foo'
)
expect
(
test_case
[
'description'
]).
to
eq
(
'bar'
)
expect
(
test_case
[
'labels'
][
'edges'
][
0
][
"node"
][
"id"
]).
to
eq
(
label
.
to_global_id
.
to_s
)
expect
(
mutation_response
[
'errors'
]).
to
eq
([])
end
context
'with invalid arguments'
do
let
(
:variables
)
{
{
not_valid:
true
}
}
it_behaves_like
'an invalid argument to the mutation'
,
argument_name: :not_valid
end
context
'when quality_test_cases flag is disabled'
do
before
do
stub_feature_flags
(
quality_test_cases:
false
)
end
it_behaves_like
'a mutation that returns errors in the response'
,
errors:
[
"Test cases are not available for this project"
]
end
end
context
'when user cannot create test cases'
do
before_all
do
project
.
add_guest
(
current_user
)
end
it_behaves_like
'a mutation that returns top-level errors'
,
errors:
[
'The resource that you are attempting to access does not exist '
\
'or you don\'t have permission to perform this action'
]
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