Commit 6bd7e1b8 authored by Shinya Maeda's avatar Shinya Maeda

Add tests for Release Link API

Add tests for the API and add a couple of tests

Add

revert

revert
parent 124905e2
...@@ -14,6 +14,9 @@ module API ...@@ -14,6 +14,9 @@ module API
requires :id, type: String, desc: 'The ID of a project' requires :id, type: String, desc: 'The ID of a project'
end end
resource 'projects/:id', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do resource 'projects/:id', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
params do
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
end
resource 'releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do resource 'releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do
resource :assets do resource :assets do
desc 'Get a list of links of a release' do desc 'Get a list of links of a release' do
...@@ -26,20 +29,7 @@ module API ...@@ -26,20 +29,7 @@ module API
get 'links' do get 'links' do
authorize! :read_release, release authorize! :read_release, release
present paginate(release.links), with: Entities::Releases::Link present paginate(release.links.sorted), with: Entities::Releases::Link
end
desc 'Get a link detail of a release' do
detail 'This feature was introduced in GitLab 11.7.'
success Entities::Releases::Link
end
params do
requires :link_id, type: String, desc: 'The id of the link'
end
get 'links/:link_id' do
authorize! :read_release, release
present link, with: Entities::Releases::Link
end end
desc 'Create a link of a release' do desc 'Create a link of a release' do
...@@ -58,44 +48,55 @@ module API ...@@ -58,44 +48,55 @@ module API
if new_link.persisted? if new_link.persisted?
present new_link, with: Entities::Releases::Link present new_link, with: Entities::Releases::Link
else else
render_api_error!(result[:message], result[:http_status]) render_api_error!(new_link.errors.messages, 400)
end end
end end
desc 'Update a link of a release' do
detail 'This feature was introduced in GitLab 11.7.'
success Entities::Releases::Link
end
params do params do
requires :link_id, type: Integer, desc: 'The id of the link' requires :link_id, type: String, desc: 'The id of the link'
optional :name, type: String, desc: 'The name of the link'
optional :url, type: String, desc: 'The URL of the link'
at_least_one_of :name, :url
end end
put 'links/:link_id' do resource 'links/:link_id' do
authorize! :update_release, release desc 'Get a link detail of a release' do
detail 'This feature was introduced in GitLab 11.7.'
success Entities::Releases::Link
end
get do
authorize! :read_release, release
if link.update(declared_params(include_missing: false))
present link, with: Entities::Releases::Link present link, with: Entities::Releases::Link
else
render_api_error!(result[:message], result[:http_status])
end end
end
desc 'Delete a link of a release' do desc 'Update a link of a release' do
detail 'This feature was introduced in GitLab 11.7.' detail 'This feature was introduced in GitLab 11.7.'
success Entities::Releases::Link success Entities::Releases::Link
end end
params do params do
requires :link_id, type: Integer, desc: 'The id of the link' optional :name, type: String, desc: 'The name of the link'
end optional :url, type: String, desc: 'The URL of the link'
put 'links/:link_id' do at_least_one_of :name, :url
authorize! :destroy_release, release end
put do
authorize! :update_release, release
if link.update(declared_params(include_missing: false))
present link, with: Entities::Releases::Link
else
render_api_error!(link.errors.messages, 400)
end
end
if link.destroy desc 'Delete a link of a release' do
present link, with: Entities::Releases::Link detail 'This feature was introduced in GitLab 11.7.'
else success Entities::Releases::Link
render_api_error!(result[:message], result[:http_status]) end
delete do
authorize! :destroy_release, release
if link.destroy
present link, with: Entities::Releases::Link
else
render_api_error!(link.errors.messages, 400)
end
end end
end end
end end
...@@ -104,7 +105,7 @@ module API ...@@ -104,7 +105,7 @@ module API
helpers do helpers do
def release def release
@release ||= user_project.releases.find_by_tag(params[:tag_name]) @release ||= user_project.releases.find_by_tag!(params[:tag])
end end
def link def link
......
...@@ -15,15 +15,7 @@ ...@@ -15,15 +15,7 @@
}, },
"assets": { "assets": {
"count": { "type": "integer" }, "count": { "type": "integer" },
"links": { "links": { "$ref": "release/links.json" },
"type": "array",
"items": {
"id": "integer",
"name": "string",
"url": "string",
"external": "boolean"
}
},
"sources": { "sources": {
"type": "array", "type": "array",
"items": { "items": {
......
{
"type": "object",
"required": ["name", "url"],
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"url": { "type": "string" },
"external": { "type": "boolean" }
},
"additionalProperties": false
}
{
"type": "array",
"items": { "$ref": "link.json" }
}
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment