debian-mirror-gitlab/spec/presenters/packages/detail/package_presenter_spec.rb

126 lines
4 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Packages::Detail::PackagePresenter do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, creator: user) }
let_it_be(:package) { create(:npm_package, :with_build, project: project) }
let(:presenter) { described_class.new(package) }
let_it_be(:user_info) { { name: user.name, avatar_url: user.avatar_url } }
2020-10-24 23:57:45 +05:30
2020-07-28 23:09:34 +05:30
let!(:expected_package_files) do
2020-10-24 23:57:45 +05:30
package.package_files.map do |file|
{
created_at: file.created_at,
download_path: file.download_path,
file_name: file.file_name,
size: file.size
}
end
2020-07-28 23:09:34 +05:30
end
2020-10-24 23:57:45 +05:30
2020-07-28 23:09:34 +05:30
let(:pipeline_info) do
pipeline = package.build_info.pipeline
{
created_at: pipeline.created_at,
id: pipeline.id,
sha: pipeline.sha,
ref: pipeline.ref,
git_commit_message: pipeline.git_commit_message,
user: user_info,
project: {
name: pipeline.project.name,
2020-10-24 23:57:45 +05:30
web_url: pipeline.project.web_url,
pipeline_url: include("pipelines/#{pipeline.id}"),
commit_url: include("commit/#{pipeline.sha}")
2020-07-28 23:09:34 +05:30
}
}
end
2020-10-24 23:57:45 +05:30
2020-07-28 23:09:34 +05:30
let!(:dependency_links) { [] }
2020-10-24 23:57:45 +05:30
2020-07-28 23:09:34 +05:30
let!(:expected_package_details) do
{
id: package.id,
created_at: package.created_at,
name: package.name,
package_files: expected_package_files,
package_type: package.package_type,
project_id: package.project_id,
tags: package.tags.as_json,
updated_at: package.updated_at,
version: package.version,
dependency_links: dependency_links
}
end
context 'detail_view' do
context 'with build_info' do
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
2020-10-24 23:57:45 +05:30
expect(presenter.detail_view).to match expected_package_details
2020-07-28 23:09:34 +05:30
end
end
context 'without build info' do
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
2020-10-24 23:57:45 +05:30
context 'with conan metadata' do
let(:package) { create(:conan_package, project: project) }
2021-01-03 14:25:43 +05:30
let(:expected_package_details) { super().merge(conan_metadatum: package.conan_metadatum, conan_package_name: package.name, name: package.conan_recipe) }
2020-10-24 23:57:45 +05:30
it 'returns conan_metadatum' do
expect(presenter.detail_view).to eq expected_package_details
end
end
context 'with composer metadata' do
let(:package) { create(:composer_package, :with_metadatum, sha: '123', project: project) }
let(:expected_package_details) { super().merge(composer_metadatum: package.composer_metadatum) }
it 'returns composer_metadatum' do
expect(presenter.detail_view).to eq expected_package_details
end
end
2020-07-28 23:09:34 +05:30
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) }
it 'returns nuget_metadatum' do
expect(presenter.detail_view).to eq expected_package_details
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) }
2020-10-24 23:57:45 +05:30
2020-07-28 23:09:34 +05:30
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
2020-10-24 23:57:45 +05:30
2020-07-28 23:09:34 +05:30
let_it_be(:dependency_links) { [expected_link] }
it 'returns the correct dependency link' do
expect(presenter.detail_view).to eq expected_package_details
end
end
end
end