2020-07-21 08:09:30 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe PackagesHelper do
|
2021-06-14 11:09:48 -04:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
let_it_be_with_reload(:project) { create(:project) }
|
2020-07-21 08:09:30 -04:00
|
|
|
let_it_be(:base_url) { "#{Gitlab.config.gitlab.url}/api/v4/" }
|
|
|
|
|
2021-06-14 11:09:48 -04:00
|
|
|
describe '#package_registry_instance_url' do
|
|
|
|
it 'returns conan instance url when registry_type is conant' do
|
2020-07-21 08:09:30 -04:00
|
|
|
url = helper.package_registry_instance_url(:conan)
|
|
|
|
|
|
|
|
expect(url).to eq("#{base_url}packages/conan")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns npm instance url when registry_type is npm' do
|
|
|
|
url = helper.package_registry_instance_url(:npm)
|
|
|
|
|
|
|
|
expect(url).to eq("#{base_url}packages/npm")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-14 11:09:48 -04:00
|
|
|
describe '#package_registry_project_url' do
|
2020-07-21 08:09:30 -04:00
|
|
|
it 'returns maven registry url when registry_type is not provided' do
|
|
|
|
url = helper.package_registry_project_url(1)
|
|
|
|
|
|
|
|
expect(url).to eq("#{base_url}projects/1/packages/maven")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns specified registry url when registry_type is provided' do
|
|
|
|
url = helper.package_registry_project_url(1, :npm)
|
|
|
|
|
|
|
|
expect(url).to eq("#{base_url}projects/1/packages/npm")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-14 11:09:48 -04:00
|
|
|
describe '#pypi_registry_url' do
|
2020-07-21 08:09:30 -04:00
|
|
|
let_it_be(:base_url_with_token) { base_url.sub('://', '://__token__:<your_personal_token>@') }
|
|
|
|
|
|
|
|
it 'returns the pypi registry url' do
|
|
|
|
url = helper.pypi_registry_url(1)
|
|
|
|
|
|
|
|
expect(url).to eq("#{base_url_with_token}projects/1/packages/pypi/simple")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-14 11:09:48 -04:00
|
|
|
describe '#composer_registry_url' do
|
2020-08-11 08:09:55 -04:00
|
|
|
it 'return the composer registry url' do
|
|
|
|
url = helper.composer_registry_url(1)
|
|
|
|
|
|
|
|
expect(url).to eq("#{base_url}group/1/-/packages/composer/packages.json")
|
|
|
|
end
|
|
|
|
end
|
2020-10-13 08:08:41 -04:00
|
|
|
|
2021-06-14 11:09:48 -04:00
|
|
|
describe '#composer_config_repository_name' do
|
2020-10-13 08:08:41 -04:00
|
|
|
let(:host) { Gitlab.config.gitlab.host }
|
|
|
|
let(:group_id) { 1 }
|
|
|
|
|
|
|
|
it 'return global unique composer registry id' do
|
|
|
|
id = helper.composer_config_repository_name(group_id)
|
|
|
|
|
|
|
|
expect(id).to eq("#{host}/#{group_id}")
|
|
|
|
end
|
|
|
|
end
|
2021-06-14 11:09:48 -04:00
|
|
|
|
|
|
|
describe '#show_cleanup_policy_on_alert' do
|
2021-07-15 08:09:01 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
2021-06-14 11:09:48 -04:00
|
|
|
let_it_be_with_reload(:container_repository) { create(:container_repository) }
|
|
|
|
|
|
|
|
subject { helper.show_cleanup_policy_on_alert(project.reload) }
|
|
|
|
|
|
|
|
where(:com, :config_registry, :project_registry, :historic_entries, :historic_entry, :nil_policy, :container_repositories_exist, :expected_result) do
|
|
|
|
false | false | false | false | false | false | false | false
|
|
|
|
false | false | false | false | false | false | true | false
|
|
|
|
false | false | false | false | false | true | false | false
|
|
|
|
false | false | false | false | false | true | true | false
|
|
|
|
false | false | false | false | true | false | false | false
|
|
|
|
false | false | false | false | true | false | true | false
|
|
|
|
false | false | false | false | true | true | false | false
|
|
|
|
false | false | false | false | true | true | true | false
|
|
|
|
false | false | false | true | false | false | false | false
|
|
|
|
false | false | false | true | false | false | true | false
|
|
|
|
false | false | false | true | false | true | false | false
|
|
|
|
false | false | false | true | false | true | true | false
|
|
|
|
false | false | false | true | true | false | false | false
|
|
|
|
false | false | false | true | true | false | true | false
|
|
|
|
false | false | false | true | true | true | false | false
|
|
|
|
false | false | false | true | true | true | true | false
|
|
|
|
false | false | true | false | false | false | false | false
|
|
|
|
false | false | true | false | false | false | true | false
|
|
|
|
false | false | true | false | false | true | false | false
|
|
|
|
false | false | true | false | false | true | true | false
|
|
|
|
false | false | true | false | true | false | false | false
|
|
|
|
false | false | true | false | true | false | true | false
|
|
|
|
false | false | true | false | true | true | false | false
|
|
|
|
false | false | true | false | true | true | true | false
|
|
|
|
false | false | true | true | false | false | false | false
|
|
|
|
false | false | true | true | false | false | true | false
|
|
|
|
false | false | true | true | false | true | false | false
|
|
|
|
false | false | true | true | false | true | true | false
|
|
|
|
false | false | true | true | true | false | false | false
|
|
|
|
false | false | true | true | true | false | true | false
|
|
|
|
false | false | true | true | true | true | false | false
|
|
|
|
false | false | true | true | true | true | true | false
|
|
|
|
false | true | false | false | false | false | false | false
|
|
|
|
false | true | false | false | false | false | true | false
|
|
|
|
false | true | false | false | false | true | false | false
|
|
|
|
false | true | false | false | false | true | true | false
|
|
|
|
false | true | false | false | true | false | false | false
|
|
|
|
false | true | false | false | true | false | true | false
|
|
|
|
false | true | false | false | true | true | false | false
|
|
|
|
false | true | false | false | true | true | true | false
|
|
|
|
false | true | false | true | false | false | false | false
|
|
|
|
false | true | false | true | false | false | true | false
|
|
|
|
false | true | false | true | false | true | false | false
|
|
|
|
false | true | false | true | false | true | true | false
|
|
|
|
false | true | false | true | true | false | false | false
|
|
|
|
false | true | false | true | true | false | true | false
|
|
|
|
false | true | false | true | true | true | false | false
|
|
|
|
false | true | false | true | true | true | true | false
|
|
|
|
false | true | true | false | false | false | false | false
|
|
|
|
false | true | true | false | false | false | true | false
|
|
|
|
false | true | true | false | false | true | false | false
|
|
|
|
false | true | true | false | false | true | true | false
|
|
|
|
false | true | true | false | true | false | false | false
|
|
|
|
false | true | true | false | true | false | true | false
|
|
|
|
false | true | true | false | true | true | false | false
|
|
|
|
false | true | true | false | true | true | true | false
|
|
|
|
false | true | true | true | false | false | false | false
|
|
|
|
false | true | true | true | false | false | true | false
|
|
|
|
false | true | true | true | false | true | false | false
|
|
|
|
false | true | true | true | false | true | true | false
|
|
|
|
false | true | true | true | true | false | false | false
|
|
|
|
false | true | true | true | true | false | true | false
|
|
|
|
false | true | true | true | true | true | false | false
|
|
|
|
false | true | true | true | true | true | true | false
|
|
|
|
true | false | false | false | false | false | false | false
|
|
|
|
true | false | false | false | false | false | true | false
|
|
|
|
true | false | false | false | false | true | false | false
|
|
|
|
true | false | false | false | false | true | true | false
|
|
|
|
true | false | false | false | true | false | false | false
|
|
|
|
true | false | false | false | true | false | true | false
|
|
|
|
true | false | false | false | true | true | false | false
|
|
|
|
true | false | false | false | true | true | true | false
|
|
|
|
true | false | false | true | false | false | false | false
|
|
|
|
true | false | false | true | false | false | true | false
|
|
|
|
true | false | false | true | false | true | false | false
|
|
|
|
true | false | false | true | false | true | true | false
|
|
|
|
true | false | false | true | true | false | false | false
|
|
|
|
true | false | false | true | true | false | true | false
|
|
|
|
true | false | false | true | true | true | false | false
|
|
|
|
true | false | false | true | true | true | true | false
|
|
|
|
true | false | true | false | false | false | false | false
|
|
|
|
true | false | true | false | false | false | true | false
|
|
|
|
true | false | true | false | false | true | false | false
|
|
|
|
true | false | true | false | false | true | true | false
|
|
|
|
true | false | true | false | true | false | false | false
|
|
|
|
true | false | true | false | true | false | true | false
|
|
|
|
true | false | true | false | true | true | false | false
|
|
|
|
true | false | true | false | true | true | true | false
|
|
|
|
true | false | true | true | false | false | false | false
|
|
|
|
true | false | true | true | false | false | true | false
|
|
|
|
true | false | true | true | false | true | false | false
|
|
|
|
true | false | true | true | false | true | true | false
|
|
|
|
true | false | true | true | true | false | false | false
|
|
|
|
true | false | true | true | true | false | true | false
|
|
|
|
true | false | true | true | true | true | false | false
|
|
|
|
true | false | true | true | true | true | true | false
|
|
|
|
true | true | false | false | false | false | false | false
|
|
|
|
true | true | false | false | false | false | true | false
|
|
|
|
true | true | false | false | false | true | false | false
|
|
|
|
true | true | false | false | false | true | true | false
|
|
|
|
true | true | false | false | true | false | false | false
|
|
|
|
true | true | false | false | true | false | true | false
|
|
|
|
true | true | false | false | true | true | false | false
|
|
|
|
true | true | false | false | true | true | true | false
|
|
|
|
true | true | false | true | false | false | false | false
|
|
|
|
true | true | false | true | false | false | true | false
|
|
|
|
true | true | false | true | false | true | false | false
|
|
|
|
true | true | false | true | false | true | true | false
|
|
|
|
true | true | false | true | true | false | false | false
|
|
|
|
true | true | false | true | true | false | true | false
|
|
|
|
true | true | false | true | true | true | false | false
|
|
|
|
true | true | false | true | true | true | true | false
|
|
|
|
true | true | true | false | false | false | false | false
|
|
|
|
true | true | true | false | false | false | true | false
|
|
|
|
true | true | true | false | false | true | false | false
|
|
|
|
true | true | true | false | false | true | true | false
|
|
|
|
true | true | true | false | true | false | false | false
|
|
|
|
true | true | true | false | true | false | true | false
|
|
|
|
true | true | true | false | true | true | false | false
|
|
|
|
true | true | true | false | true | true | true | true
|
|
|
|
true | true | true | true | false | false | false | false
|
|
|
|
true | true | true | true | false | false | true | false
|
|
|
|
true | true | true | true | false | true | false | false
|
|
|
|
true | true | true | true | false | true | true | false
|
|
|
|
true | true | true | true | true | false | false | false
|
|
|
|
true | true | true | true | true | false | true | false
|
|
|
|
true | true | true | true | true | true | false | false
|
|
|
|
true | true | true | true | true | true | true | false
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
before do
|
2021-07-15 08:09:01 -04:00
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
2021-06-14 11:09:48 -04:00
|
|
|
allow(Gitlab).to receive(:com?).and_return(com)
|
|
|
|
stub_config(registry: { enabled: config_registry })
|
2021-07-15 08:09:01 -04:00
|
|
|
allow(project).to receive(:feature_available?).with(:container_registry, user).and_return(project_registry)
|
2021-06-14 11:09:48 -04:00
|
|
|
stub_application_setting(container_expiration_policies_enable_historic_entries: historic_entries)
|
|
|
|
stub_feature_flags(container_expiration_policies_historic_entry: false)
|
|
|
|
stub_feature_flags(container_expiration_policies_historic_entry: project) if historic_entry
|
|
|
|
|
|
|
|
project.container_expiration_policy.destroy! if nil_policy
|
|
|
|
container_repository.update!(project_id: project.id) if container_repositories_exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(expected_result) }
|
|
|
|
end
|
|
|
|
end
|
2021-07-21 11:08:52 -04:00
|
|
|
|
|
|
|
describe '#package_details_data' do
|
|
|
|
let_it_be(:package) { create(:package) }
|
|
|
|
|
2021-09-13 11:10:34 -04:00
|
|
|
let(:expected_result) do
|
|
|
|
{
|
|
|
|
package_id: package.id,
|
|
|
|
can_delete: 'true',
|
|
|
|
project_name: project.name,
|
|
|
|
group_list_url: ''
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-07-21 11:08:52 -04:00
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user) { project.owner }
|
|
|
|
allow(helper).to receive(:can?) { true }
|
|
|
|
end
|
|
|
|
|
2021-09-13 11:10:34 -04:00
|
|
|
context 'in a project without a group' do
|
|
|
|
it 'populates presenter data' do
|
|
|
|
result = helper.package_details_data(project, package)
|
2021-07-21 11:08:52 -04:00
|
|
|
|
2021-09-13 11:10:34 -04:00
|
|
|
expect(result).to match(hash_including(expected_result))
|
|
|
|
end
|
2021-07-21 11:08:52 -04:00
|
|
|
end
|
|
|
|
|
2021-09-13 11:10:34 -04:00
|
|
|
context 'in a project with a group' do
|
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be(:project_with_group) { create(:project, group: group) }
|
2021-07-21 11:08:52 -04:00
|
|
|
|
2021-09-13 11:10:34 -04:00
|
|
|
it 'populates presenter data' do
|
|
|
|
result = helper.package_details_data(project_with_group, package)
|
|
|
|
expected = expected_result.merge({
|
|
|
|
group_list_url: group_packages_path(project_with_group.group),
|
|
|
|
project_name: project_with_group.name
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(result).to match(hash_including(expected))
|
|
|
|
end
|
2021-07-21 11:08:52 -04:00
|
|
|
end
|
|
|
|
end
|
2021-10-04 14:12:46 -04:00
|
|
|
|
|
|
|
describe '#packages_list_data' do
|
|
|
|
let_it_be(:resource) { project }
|
|
|
|
let_it_be(:type) { 'project' }
|
|
|
|
|
|
|
|
let(:expected_result) do
|
|
|
|
{
|
|
|
|
resource_id: resource.id,
|
|
|
|
full_path: resource.full_path,
|
|
|
|
page_type: type
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
subject(:result) { helper.packages_list_data(type, resource) }
|
|
|
|
|
|
|
|
context 'at a project level' do
|
|
|
|
it 'populates presenter data' do
|
|
|
|
expect(result).to match(hash_including(expected_result))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'at a group level' do
|
|
|
|
let_it_be(:resource) { create(:group) }
|
|
|
|
let_it_be(:type) { 'group' }
|
|
|
|
|
|
|
|
it 'populates presenter data' do
|
|
|
|
expect(result).to match(hash_including(expected_result))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-07-21 08:09:30 -04:00
|
|
|
end
|