Commit b8ed46c7 authored by Nick Kipling's avatar Nick Kipling

Applying reviewer feedback

Resolved issues in presenter, marked functions as private
Updated tests
Removed tests for newly private functions
parent d00d952d
......@@ -22,12 +22,14 @@ 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 { |dl| build_dependency_links(dl) } if @package.dependency_links
package_detail[:dependency_links] = @package.dependency_links.map { |dl| build_dependency_links(dl) }
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,
......@@ -65,8 +67,8 @@ module Packages
{
name: link.dependency.name,
version_pattern: link.dependency.version_pattern,
target_framework: link.nuget_metadatum.target_framework
}
target_framework: link.nuget_metadatum&.target_framework
}.compact
end
end
end
......
......@@ -50,7 +50,7 @@ describe ::Packages::Detail::PackagePresenter do
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) }
it 'returns details with pipeline' do
expected_package_details[:pipeline] = pipeline_info
......@@ -60,7 +60,7 @@ describe ::Packages::Detail::PackagePresenter do
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
......@@ -77,44 +77,24 @@ describe ::Packages::Detail::PackagePresenter 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 '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
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
end
it 'returns nil when there is not a user' do
expect(presenter.build_user_info(nil)).to eq nil
end
end
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
context 'build_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
it 'returns the correct dependency link' do
expected_package_details[:dependency_links] = [expected_link]
it 'returns correct dependency data for nuget packages' do
expect(presenter.build_dependency_links(dependency_link)).to eq expected_link
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