Commit e0b2af84 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '36422-add-nuget-metadata-to-package-presenter' into 'master'

Add NuGet metadata and dependency links to package presenter

See merge request gitlab-org/gitlab!33060
parents b50ce95a 5b6ebf27
......@@ -21,11 +21,15 @@ module Packages
}
package_detail[:maven_metadatum] = @package.maven_metadatum if @package.maven_metadatum
package_detail[:nuget_metadatum] = @package.nuget_metadatum if @package.nuget_metadatum
package_detail[:dependency_links] = @package.dependency_links.map(&method(:build_dependency_links))
package_detail[:pipeline] = build_pipeline_info(@package.build_info.pipeline) if @package.build_info
package_detail
end
private
def build_package_file_view(package_file)
{
created_at: package_file.created_at,
......@@ -58,6 +62,14 @@ module Packages
name: user.name
}
end
def build_dependency_links(link)
{
name: link.dependency.name,
version_pattern: link.dependency.version_pattern,
target_framework: link.nuget_metadatum&.target_framework
}.compact
end
end
end
end
......@@ -33,6 +33,7 @@ describe ::Packages::Detail::PackagePresenter do
}
}
end
let!(:dependency_links) { [] }
let!(:expected_package_details) do
{
id: package.id,
......@@ -43,49 +44,55 @@ describe ::Packages::Detail::PackagePresenter do
project_id: package.project_id,
tags: package.tags.as_json,
updated_at: package.updated_at,
version: package.version
version: package.version,
dependency_links: dependency_links
}
end
context 'detail_view' do
context 'with build_info' do
let!(:package) { create(:npm_package, :with_build, project: project) }
let_it_be(:package) { create(:npm_package, :with_build, project: project) }
let(:expected_package_details) { super().merge(pipeline: pipeline_info) }
it 'returns details with pipeline' do
expected_package_details[:pipeline] = pipeline_info
expect(presenter.detail_view).to eq expected_package_details
end
end
context 'without build info' do
let!(:package) { create(:npm_package, project: project) }
let_it_be(:package) { create(:npm_package, project: project) }
it 'returns details without pipeline' do
expect(presenter.detail_view).to eq expected_package_details
end
end
end
it 'build_package_file_view returns correct file data' do
package_files_result = package.package_files.map { |pf| presenter.build_package_file_view(pf) }
expect(package_files_result).to eq expected_package_files
end
context 'with nuget_metadatum' do
let_it_be(:package) { create(:nuget_package, project: project) }
let_it_be(:nuget_metadatum) { create(:nuget_metadatum, package: package) }
let(:expected_package_details) { super().merge(nuget_metadatum: nuget_metadatum) }
context 'build_pipeline_info' do
it 'returns correct data when there is pipeline_info' do
expect(presenter.build_pipeline_info(package.build_info.pipeline)).to eq pipeline_info
it 'returns nuget_metadatum' do
expect(presenter.detail_view).to eq expected_package_details
end
end
context 'build_user_info' do
it 'returns correct data when there is a user' do
expect(presenter.build_user_info(package.build_info.pipeline.user)).to eq user_info
context 'with dependency_links' do
let_it_be(:package) { create(:nuget_package, project: project) }
let_it_be(:dependency_link) { create(:packages_dependency_link, package: package) }
let_it_be(:nuget_dependency) { create(:nuget_dependency_link_metadatum, dependency_link: dependency_link) }
let_it_be(:expected_link) do
{
name: dependency_link.dependency.name,
version_pattern: dependency_link.dependency.version_pattern,
target_framework: nuget_dependency.target_framework
}
end
let_it_be(:dependency_links) { [expected_link] }
it 'returns nil when there is not a user' do
expect(presenter.build_user_info(nil)).to eq nil
it 'returns the correct dependency link' do
expect(presenter.detail_view).to eq expected_package_details
end
end
end
end
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