Commit ab8a23ed authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add more validations and update specs for maven package feature

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 0d07bdfb
# frozen_string_literal: true
class Packages::MavenPackageFinder class Packages::MavenPackageFinder
attr_reader :project, :path attr_reader :project, :path
......
...@@ -3,4 +3,7 @@ class Packages::MavenMetadatum < ActiveRecord::Base ...@@ -3,4 +3,7 @@ class Packages::MavenMetadatum < ActiveRecord::Base
belongs_to :package belongs_to :package
validates :package, presence: true validates :package, presence: true
validates :path, presence: true
validates :app_group, presence: true
validates :app_name, presence: true
end end
...@@ -5,4 +5,5 @@ class Packages::Package < ActiveRecord::Base ...@@ -5,4 +5,5 @@ class Packages::Package < ActiveRecord::Base
has_one :maven_metadatum has_one :maven_metadatum
validates :project, presence: true validates :project, presence: true
validates :name, presence: true
end end
# frozen_string_literal: true
class Packages::CreatePackageFileService class Packages::CreatePackageFileService
attr_reader :package, :params attr_reader :package, :params
......
...@@ -43,8 +43,9 @@ FactoryBot.define do ...@@ -43,8 +43,9 @@ FactoryBot.define do
factory :maven_metadatum, class: Packages::MavenMetadatum do factory :maven_metadatum, class: Packages::MavenMetadatum do
package package
app_group 'my/company/app' path 'my/company/app/my-app/1.0-SNAPSHOT'
app_group 'my.company.app'
app_name 'my-app' app_name 'my-app'
app_version '1-0-SNAPSHOT' app_version '1.0-SNAPSHOT'
end end
end end
...@@ -13,7 +13,7 @@ describe API::MavenPackages do ...@@ -13,7 +13,7 @@ describe API::MavenPackages do
project.add_developer(user) project.add_developer(user)
end end
describe 'GET /api/v4/projects/:id/packages/maven/*app_group/:app_name/:app_version/:file_name' do describe 'GET /api/v4/projects/:id/packages/maven/*path/:file_name' do
let(:package) { create(:maven_package, project: project) } let(:package) { create(:maven_package, project: project) }
let(:maven_metadatum) { package.maven_metadatum } let(:maven_metadatum) { package.maven_metadatum }
let(:package_file_xml) { package.package_files.find_by(file_type: 'xml') } let(:package_file_xml) { package.package_files.find_by(file_type: 'xml') }
...@@ -64,8 +64,7 @@ describe API::MavenPackages do ...@@ -64,8 +64,7 @@ describe API::MavenPackages do
def download_file(file_name, params = {}, request_headers = headers) def download_file(file_name, params = {}, request_headers = headers)
get api("/projects/#{project.id}/packages/maven/" \ get api("/projects/#{project.id}/packages/maven/" \
"#{maven_metadatum.app_group}/#{maven_metadatum.app_name}/" \ "#{maven_metadatum.path}/#{file_name}"), params, request_headers
"#{maven_metadatum.app_version}/#{file_name}"), params, request_headers
end end
def download_file_with_token(file_name, params = {}, request_headers = headers_with_token) def download_file_with_token(file_name, params = {}, request_headers = headers_with_token)
...@@ -73,7 +72,7 @@ describe API::MavenPackages do ...@@ -73,7 +72,7 @@ describe API::MavenPackages do
end end
end end
describe 'PUT /api/v4/projects/:id/packages/maven/*app_group/:app_name/:app_version/:file_name/authorize' do describe 'PUT /api/v4/projects/:id/packages/maven/*path/:file_name/authorize' do
it 'authorizes posting package with a valid token' do it 'authorizes posting package with a valid token' do
authorize_upload_with_token authorize_upload_with_token
...@@ -115,7 +114,7 @@ describe API::MavenPackages do ...@@ -115,7 +114,7 @@ describe API::MavenPackages do
end end
end end
describe 'PUT /api/v4/projects/:id/packages/maven/*app_group/:app_name/:app_version/:file_name' do describe 'PUT /api/v4/projects/:id/packages/maven/*path/:file_name' do
let(:file_upload) { fixture_file_upload('ee/spec/fixtures/maven/maven-metadata.xml') } let(:file_upload) { fixture_file_upload('ee/spec/fixtures/maven/maven-metadata.xml') }
before do before do
......
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