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
cc7f0482
Commit
cc7f0482
authored
Aug 24, 2020
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to create test cases
Allow to create issues with test case type
parent
e8dcdf17
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
159 additions
and
3 deletions
+159
-3
app/models/issue.rb
app/models/issue.rb
+2
-1
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
+6
-0
ee/app/services/quality_management/test_cases/create_service.rb
.../services/quality_management/test_cases/create_service.rb
+50
-0
ee/spec/services/quality_management/test_cases/create_service_spec.rb
...ices/quality_management/test_cases/create_service_spec.rb
+86
-0
locale/gitlab.pot
locale/gitlab.pot
+3
-0
spec/factories/issues.rb
spec/factories/issues.rb
+4
-0
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+3
-2
No files found.
app/models/issue.rb
View file @
cc7f0482
...
...
@@ -73,7 +73,8 @@ class Issue < ApplicationRecord
enum
issue_type:
{
issue:
0
,
incident:
1
incident:
1
,
test_case:
2
## EE-only
}
alias_attribute
:parent_ids
,
:project_id
...
...
doc/api/graphql/reference/gitlab_schema.graphql
View file @
cc7f0482
...
...
@@ -8002,6 +8002,11 @@ enum IssueType {
Issue
issue
type
"""
ISSUE
"""
Test
Case
issue
type
"""
TEST_CASE
}
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
cc7f0482
...
...
@@ -22086,6 +22086,12 @@
"description": "Incident issue type",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "TEST_CASE",
"description": "Test Case issue type",
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
ee/app/services/quality_management/test_cases/create_service.rb
0 → 100644
View file @
cc7f0482
# frozen_string_literal: true
module
QualityManagement
module
TestCases
class
CreateService
<
BaseService
ISSUE_TYPE
=
'test_case'
def
initialize
(
project
,
current_user
,
title
:,
description
:,
label_ids:
[])
super
(
project
,
current_user
)
@title
=
title
@description
=
description
@label_ids
=
label_ids
end
def
execute
return
error
(
_
(
'Test cases are not available for this project'
))
unless
can_create_test_cases?
issue
=
Issues
::
CreateService
.
new
(
project
,
current_user
,
issue_type:
ISSUE_TYPE
,
title:
title
,
description:
description
,
label_ids:
label_ids
).
execute
return
error
(
issue
.
errors
.
full_messages
.
to_sentence
,
issue
)
unless
issue
.
valid?
success
(
issue
)
end
private
attr_reader
:title
,
:description
,
:label_ids
def
success
(
issue
)
ServiceResponse
.
success
(
payload:
{
issue:
issue
})
end
def
error
(
message
,
issue
=
nil
)
ServiceResponse
.
error
(
payload:
{
issue:
issue
},
message:
message
)
end
def
can_create_test_cases?
project
.
feature_available?
(
:quality_management
)
&&
Feature
.
enabled?
(
:quality_test_cases
,
project
)
end
end
end
end
ee/spec/services/quality_management/test_cases/create_service_spec.rb
0 → 100644
View file @
cc7f0482
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
QualityManagement
::
TestCases
::
CreateService
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be_with_refind
(
:project
)
{
create
(
:project
,
:empty_repo
)
}
let
(
:description
)
{
'test case description'
}
let_it_be
(
:label
)
{
create
(
:label
,
project:
project
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
title:
title
,
description:
description
,
label_ids:
[
label
.
id
])
}
describe
'#execute'
do
before_all
do
project
.
add_reporter
(
user
)
end
context
'when test has title and description'
do
let
(
:title
)
{
'test case title'
}
let
(
:new_issue
)
{
Issue
.
last!
}
context
'when quality management license is not available'
do
it
'responds with errors'
do
expect
(
service
.
execute
).
to
be_error
expect
(
service
.
execute
.
message
).
to
eq
(
"Test cases are not available for this project"
)
end
end
context
'when quality_management license is available'
do
before
do
stub_licensed_features
(
quality_management:
true
)
end
it
'responds with success'
do
expect
(
service
.
execute
).
to
be_success
end
it
'creates an test case issue'
do
expect
{
service
.
execute
}.
to
change
(
Issue
,
:count
).
by
(
1
)
end
it
'created issue has correct attributes'
do
service
.
execute
aggregate_failures
do
expect
(
new_issue
.
title
).
to
eq
(
title
)
expect
(
new_issue
.
description
).
to
eq
(
description
)
expect
(
new_issue
.
author
).
to
eq
(
user
)
expect
(
new_issue
.
issue_type
).
to
eq
(
'test_case'
)
expect
(
new_issue
.
labels
.
map
(
&
:title
)).
to
eq
([
label
.
title
])
end
end
context
'when quality_test_cases feature flag is disabled'
do
before
do
stub_feature_flags
(
quality_test_cases:
false
)
end
it
'responds with errors'
do
expect
(
service
.
execute
).
to
be_error
expect
(
service
.
execute
.
message
).
to
eq
(
"Test cases are not available for this project"
)
end
end
end
end
context
'when test case has no title'
do
let
(
:title
)
{
''
}
before
do
stub_licensed_features
(
quality_management:
true
)
end
it
'does not create an issue'
do
expect
{
service
.
execute
}.
not_to
change
(
Issue
,
:count
)
end
it
'responds with errors'
do
expect
(
service
.
execute
).
to
be_error
expect
(
service
.
execute
.
message
).
to
eq
(
"Title can't be blank"
)
end
it
'result payload contains an Issue object'
do
expect
(
service
.
execute
.
payload
[
:issue
]).
to
be_kind_of
(
Issue
)
end
end
end
end
locale/gitlab.pot
View file @
cc7f0482
...
...
@@ -24311,6 +24311,9 @@ msgstr ""
msgid "Test Cases"
msgstr ""
msgid "Test cases are not available for this project"
msgstr ""
msgid "Test coverage parsing"
msgstr ""
...
...
spec/factories/issues.rb
View file @
cc7f0482
...
...
@@ -52,5 +52,9 @@ FactoryBot.define do
factory
:incident
do
issue_type
{
:incident
}
end
factory
:quality_test_case
do
issue_type
{
:test_case
}
end
end
end
spec/models/issue_spec.rb
View file @
cc7f0482
...
...
@@ -133,6 +133,7 @@ RSpec.describe Issue do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let_it_be
(
:incident
)
{
create
(
:incident
,
project:
project
)
}
let_it_be
(
:test_case
)
{
create
(
:quality_test_case
,
project:
project
)
}
it
'gives issues with the given issue type'
do
expect
(
described_class
.
with_issue_type
(
'issue'
))
...
...
@@ -140,8 +141,8 @@ RSpec.describe Issue do
end
it
'gives issues with the given issue type'
do
expect
(
described_class
.
with_issue_type
(
%w(issue incident)
))
.
to
contain_exactly
(
issue
,
incident
)
expect
(
described_class
.
with_issue_type
(
%w(issue incident
test_case
)
))
.
to
contain_exactly
(
issue
,
incident
,
test_case
)
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