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
2ab3bc6b
Commit
2ab3bc6b
authored
Oct 01, 2019
by
Tetiana Chupryna
Committed by
James Lopez
Oct 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tests for license entities
License report doesn't have info about dep url
parent
a4f6d929
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
291 additions
and
122 deletions
+291
-122
ee/app/serializers/dependency_list_entity.rb
ee/app/serializers/dependency_list_entity.rb
+3
-36
ee/app/serializers/license_entity.rb
ee/app/serializers/license_entity.rb
+11
-0
ee/app/serializers/licenses_list_entity.rb
ee/app/serializers/licenses_list_entity.rb
+13
-0
ee/app/serializers/licenses_list_serializer.rb
ee/app/serializers/licenses_list_serializer.rb
+7
-0
ee/app/serializers/report_list_entity.rb
ee/app/serializers/report_list_entity.rb
+47
-0
ee/spec/fixtures/api/schemas/dependency_list.json
ee/spec/fixtures/api/schemas/dependency_list.json
+1
-3
ee/spec/fixtures/api/schemas/licenses_list.json
ee/spec/fixtures/api/schemas/licenses_list.json
+40
-0
ee/spec/fixtures/api/schemas/report_list.json
ee/spec/fixtures/api/schemas/report_list.json
+19
-0
ee/spec/serializers/dependency_list_entity_spec.rb
ee/spec/serializers/dependency_list_entity_spec.rb
+4
-83
ee/spec/serializers/license_entity_spec.rb
ee/spec/serializers/license_entity_spec.rb
+21
-0
ee/spec/serializers/licenses_list_entity_spec.rb
ee/spec/serializers/licenses_list_entity_spec.rb
+13
-0
ee/spec/serializers/licenses_list_serializer_spec.rb
ee/spec/serializers/licenses_list_serializer_spec.rb
+24
-0
ee/spec/support/shared_examples/serializers/report_status_shared_examples.rb
...red_examples/serializers/report_status_shared_examples.rb
+88
-0
No files found.
ee/app/serializers/dependency_list_entity.rb
View file @
2ab3bc6b
# frozen_string_literal: true
class
DependencyListEntity
<
Grape
::
Entity
include
RequestAwareEntity
class
DependencyListEntity
<
ReportListEntity
present_collection
true
,
:dependencies
expose
:dependencies
,
using:
DependencyEntity
expose
:report
do
expose
:status
do
|
list
,
options
|
status
(
list
[
:dependencies
],
options
[
:build
])
end
expose
:job_path
,
if:
->
(
_
,
options
)
{
options
[
:build
]
&&
can_read_job_path?
}
do
|
_
,
options
|
project_build_path
(
project
,
options
[
:build
].
id
)
end
expose
:generated_at
,
if:
->
(
_
,
options
)
{
options
[
:build
]
&&
can_read_job_path?
}
do
|
_
,
options
|
options
[
:build
].
finished_at
end
end
private
def
can_read_job_path?
can?
(
request
.
user
,
:read_pipeline
,
project
)
end
def
project
request
.
project
end
def
status
(
dependencies
,
build
)
if
build
&
.
success?
if
dependencies
.
any?
:ok
else
:no_dependencies
end
elsif
build
&
.
failed?
:job_failed
else
:job_not_set_up
end
def
items_name
:dependencies
end
end
ee/app/serializers/license_entity.rb
0 → 100644
View file @
2ab3bc6b
# frozen_string_literal: true
class
LicenseEntity
<
Grape
::
Entity
class
ComponentEntity
<
Grape
::
Entity
expose
:name
end
expose
:name
expose
:url
expose
:dependencies
,
using:
ComponentEntity
,
as: :components
end
ee/app/serializers/licenses_list_entity.rb
0 → 100644
View file @
2ab3bc6b
# frozen_string_literal: true
class
LicensesListEntity
<
ReportListEntity
present_collection
true
,
:licenses
expose
:licenses
,
using:
LicenseEntity
private
def
items_name
:licenses
end
end
ee/app/serializers/licenses_list_serializer.rb
0 → 100644
View file @
2ab3bc6b
# frozen_string_literal: true
class
LicensesListSerializer
<
BaseSerializer
include
WithPagination
entity
LicensesListEntity
end
ee/app/serializers/report_list_entity.rb
0 → 100644
View file @
2ab3bc6b
# frozen_string_literal: true
class
ReportListEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:report
do
expose
:status
do
|
list
,
options
|
status
(
list
[
items_name
],
options
[
:build
])
end
expose
:job_path
,
if:
->
(
_
,
options
)
{
options
[
:build
]
&&
can_read_job_path?
}
do
|
_
,
options
|
project_build_path
(
project
,
options
[
:build
].
id
)
end
expose
:generated_at
,
if:
->
(
_
,
options
)
{
options
[
:build
]
&&
can_read_job_path?
}
do
|
_
,
options
|
options
[
:build
].
finished_at
end
end
private
def
can_read_job_path?
can?
(
request
.
user
,
:read_pipeline
,
project
)
end
def
items_name
raise
NotImplementedError
end
def
project
request
.
project
end
def
status
(
dependencies
,
build
)
if
build
&
.
success?
if
dependencies
.
any?
:ok
else
"no_
#{
items_name
}
"
.
to_sym
end
elsif
build
&
.
failed?
:job_failed
else
:job_not_set_up
end
end
end
ee/spec/fixtures/api/schemas/dependency_list.json
View file @
2ab3bc6b
...
...
@@ -12,9 +12,7 @@
}
},
"report"
:
{
"status"
:
{
"type"
:
"string"
},
"job_path"
:
{
"type"
:
"string"
},
"generated_at"
:
{
"type"
:
"string"
}
"$ref"
:
"./report_list.json"
}
},
"additionalProperties"
:
false
...
...
ee/spec/fixtures/api/schemas/licenses_list.json
0 → 100644
View file @
2ab3bc6b
{
"type"
:
"object"
,
"required"
:
[
"licenses"
,
"report"
],
"properties"
:
{
"licenses"
:
{
"type"
:
"array"
,
"items"
:
{
"type"
:
"object"
,
"required"
:
[
"name"
,
"url"
,
"components"
],
"properties"
:
{
"name"
:
{
"type"
:
"string"
},
"url"
:
{
"type"
:
"string"
},
"components"
:
{
"type"
:
"array"
,
"properties"
:
{
"name"
:
{
"type"
:
"string"
}
}
}
}
}
},
"report"
:
{
"$ref"
:
"./report_list.json"
}
},
"additionalProperties"
:
false
}
ee/spec/fixtures/api/schemas/report_list.json
0 → 100644
View file @
2ab3bc6b
{
"type"
:
"object"
,
"required"
:
[
"status"
,
"job_path"
,
"generated_at"
],
"properties"
:
{
"status"
:
{
"type"
:
"string"
},
"job_path"
:
{
"type"
:
"string"
},
"generated_at"
:
{
"type"
:
"string"
}
}
}
ee/spec/serializers/dependency_list_entity_spec.rb
View file @
2ab3bc6b
...
...
@@ -3,88 +3,9 @@
require
'spec_helper'
describe
DependencyListEntity
do
describe
'#as_json'
do
let
(
:entity
)
do
described_class
.
represent
(
dependencies
,
build:
ci_build
,
request:
request
)
end
let
(
:request
)
{
double
(
'request'
)
}
set
(
:project
)
{
create
(
:project
,
:repository
,
:private
)
}
set
(
:developer
)
{
create
(
:user
)
}
subject
{
entity
.
as_json
}
before
do
project
.
add_developer
(
developer
)
allow
(
request
).
to
receive
(
:project
).
and_return
(
project
)
allow
(
request
).
to
receive
(
:user
).
and_return
(
user
)
end
context
'with success build'
do
let
(
:user
)
{
developer
}
let
(
:ci_build
)
{
create
(
:ee_ci_build
,
:success
)
}
context
'with provided dependencies'
do
let
(
:dependencies
)
{
[
build
(
:dependency
)]
}
it
'has array of dependencies with status ok'
do
job_path
=
"/
#{
project
.
full_path
}
/builds/
#{
ci_build
.
id
}
"
expect
(
subject
[
:dependencies
][
0
][
:name
]).
to
eq
(
'nokogiri'
)
expect
(
subject
[
:report
][
:status
]).
to
eq
(
:ok
)
expect
(
subject
[
:report
][
:job_path
]).
to
eq
(
job_path
)
expect
(
subject
[
:report
][
:generated_at
]).
to
eq
(
ci_build
.
finished_at
)
end
end
context
'with no dependencies'
do
let
(
:user
)
{
developer
}
let
(
:dependencies
)
{
[]
}
it
'has empty array of dependencies with status no_dependencies'
do
job_path
=
"/
#{
project
.
full_path
}
/builds/
#{
ci_build
.
id
}
"
expect
(
subject
[
:dependencies
].
length
).
to
eq
(
0
)
expect
(
subject
[
:report
][
:status
]).
to
eq
(
:no_dependencies
)
expect
(
subject
[
:report
][
:job_path
]).
to
eq
(
job_path
)
end
end
end
context
'with failed build'
do
let
(
:ci_build
)
{
create
(
:ee_ci_build
,
:failed
)
}
let
(
:dependencies
)
{
[]
}
context
'with authorized user'
do
let
(
:user
)
{
developer
}
it
'has job_path with status failed_job'
do
expect
(
subject
[
:report
][
:status
]).
to
eq
(
:job_failed
)
expect
(
subject
[
:report
]).
to
include
(
:job_path
)
end
end
context
'without authorized user'
do
let
(
:user
)
{
create
(
:user
)
}
it
'has only status failed_job'
do
expect
(
subject
[
:report
][
:status
]).
to
eq
(
:job_failed
)
expect
(
subject
[
:report
]).
not_to
include
(
:job_path
)
expect
(
subject
[
:report
]).
not_to
include
(
:generated_at
)
end
end
end
context
'with no build'
do
let
(
:user
)
{
developer
}
let
(
:ci_build
)
{
nil
}
let
(
:dependencies
)
{
[]
}
it
'has status job_not_set_up and no job_path'
do
expect
(
subject
[
:report
][
:status
]).
to
eq
(
:job_not_set_up
)
expect
(
subject
[
:report
][
:job_path
]).
not_to
be_present
expect
(
subject
[
:report
][
:generated_at
]).
not_to
be_present
end
end
it_behaves_like
'report list'
do
let
(
:name
)
{
:dependencies
}
let
(
:collection
)
{
[
build
(
:dependency
)]
}
let
(
:no_items_status
)
{
:no_dependencies
}
end
end
ee/spec/serializers/license_entity_spec.rb
0 → 100644
View file @
2ab3bc6b
# frozen_string_literal: true
require
'spec_helper'
describe
LicenseEntity
do
describe
'#as_json'
do
subject
{
described_class
.
represent
(
license
).
as_json
}
let
(
:license
)
{
build
(
:ci_reports_license_management_report
,
:mit
).
licenses
.
first
}
let
(
:assert_license
)
do
{
name:
'MIT'
,
url:
'https://opensource.org/licenses/mit'
,
components:
[{
name:
'rails'
}]
}
end
it
{
is_expected
.
to
eq
(
assert_license
)
}
end
end
ee/spec/serializers/licenses_list_entity_spec.rb
0 → 100644
View file @
2ab3bc6b
# frozen_string_literal: true
require
'spec_helper'
describe
LicensesListEntity
do
let
(
:report
)
{
build
(
:ci_reports_license_management_report
,
:mit
)
}
it_behaves_like
'report list'
do
let
(
:name
)
{
:licenses
}
let
(
:collection
)
{
report
.
licenses
}
let
(
:no_items_status
)
{
:no_licenses
}
end
end
ee/spec/serializers/licenses_list_serializer_spec.rb
0 → 100644
View file @
2ab3bc6b
# frozen_string_literal: true
require
'spec_helper'
describe
LicensesListSerializer
do
describe
'#to_json'
do
subject
do
described_class
.
new
(
project:
project
,
user:
user
)
.
represent
(
report
.
licenses
,
build:
ci_build
)
.
to_json
end
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:ci_build
)
{
create
(
:ee_ci_build
,
:success
)
}
let
(
:report
)
{
build
(
:ci_reports_license_management_report
,
:mit
)
}
before
do
project
.
add_guest
(
user
)
end
it
{
is_expected
.
to
match_schema
(
'licenses_list'
,
dir:
'ee'
)
}
end
end
ee/spec/support/shared_examples/serializers/report_status_shared_examples.rb
0 → 100644
View file @
2ab3bc6b
# frozen_string_literal: true
shared_examples
'report list'
do
describe
'#as_json'
do
let
(
:entity
)
do
described_class
.
represent
(
items
,
build:
ci_build
,
request:
request
)
end
let
(
:request
)
{
double
(
'request'
)
}
set
(
:project
)
{
create
(
:project
,
:repository
,
:private
)
}
set
(
:developer
)
{
create
(
:user
)
}
subject
{
entity
.
as_json
}
before
do
project
.
add_developer
(
developer
)
allow
(
request
).
to
receive
(
:project
).
and_return
(
project
)
allow
(
request
).
to
receive
(
:user
).
and_return
(
user
)
end
context
'with success build'
do
let
(
:user
)
{
developer
}
let
(
:ci_build
)
{
create
(
:ee_ci_build
,
:success
)
}
context
'with provided items'
do
let
(
:items
)
{
collection
}
it
'has array of items with status ok'
do
job_path
=
"/
#{
project
.
full_path
}
/builds/
#{
ci_build
.
id
}
"
expect
(
subject
[
name
]).
to
be_kind_of
(
Array
)
expect
(
subject
[
:report
][
:status
]).
to
eq
(
:ok
)
expect
(
subject
[
:report
][
:job_path
]).
to
eq
(
job_path
)
expect
(
subject
[
:report
][
:generated_at
]).
to
eq
(
ci_build
.
finished_at
)
end
end
context
'with no items'
do
let
(
:user
)
{
developer
}
let
(
:items
)
{
[]
}
it
'has empty array of items with status no_items'
do
job_path
=
"/
#{
project
.
full_path
}
/builds/
#{
ci_build
.
id
}
"
expect
(
subject
[
name
].
length
).
to
eq
(
0
)
expect
(
subject
[
:report
][
:status
]).
to
eq
(
no_items_status
)
expect
(
subject
[
:report
][
:job_path
]).
to
eq
(
job_path
)
end
end
end
context
'with failed build'
do
let
(
:ci_build
)
{
create
(
:ee_ci_build
,
:failed
)
}
let
(
:items
)
{
[]
}
context
'with authorized user'
do
let
(
:user
)
{
developer
}
it
'has job_path with status failed_job'
do
expect
(
subject
[
:report
][
:status
]).
to
eq
(
:job_failed
)
expect
(
subject
[
:report
]).
to
include
(
:job_path
)
end
end
context
'without authorized user'
do
let
(
:user
)
{
create
(
:user
)
}
it
'has only status failed_job'
do
expect
(
subject
[
:report
][
:status
]).
to
eq
(
:job_failed
)
expect
(
subject
[
:report
]).
not_to
include
(
:job_path
)
expect
(
subject
[
:report
]).
not_to
include
(
:generated_at
)
end
end
end
context
'with no build'
do
let
(
:user
)
{
developer
}
let
(
:ci_build
)
{
nil
}
let
(
:items
)
{
[]
}
it
'has status job_not_set_up and no job_path'
do
expect
(
subject
[
:report
][
:status
]).
to
eq
(
:job_not_set_up
)
expect
(
subject
[
:report
][
:job_path
]).
not_to
be_present
expect
(
subject
[
:report
][
:generated_at
]).
not_to
be_present
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