debian-mirror-gitlab/spec/finders/packages/pypi/packages_finder_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
2.9 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Packages::Pypi::PackagesFinder do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:project2) { create(:project, group: group) }
let_it_be(:package1) { create(:pypi_package, project: project) }
let_it_be(:package2) { create(:pypi_package, project: project) }
let_it_be(:package3) { create(:pypi_package, name: package2.name, project: project) }
let_it_be(:package4) { create(:pypi_package, name: package2.name, project: project2) }
2022-07-23 23:45:48 +05:30
shared_examples 'when no package is found' do
context 'non-existing package' do
let(:package_name) { 'none' }
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
it { expect(subject).to be_empty }
end
end
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
shared_examples 'when package_name param is a non-normalized name' do
context 'non-existing package' do
let(:package_name) { package2.name.upcase.tr('-', '.') }
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
it { expect(subject).to be_empty }
2021-06-08 01:23:25 +05:30
end
2022-07-23 23:45:48 +05:30
end
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
describe '#execute' do
subject { described_class.new(user, scope, package_name: package_name).execute }
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
context 'with package name param' do
let(:package_name) { package2.name }
context 'within a project' do
let(:scope) { project }
it { is_expected.to contain_exactly(package2, package3) }
it_behaves_like 'when no package is found'
it_behaves_like 'when package_name param is a non-normalized name'
2021-06-08 01:23:25 +05:30
end
2022-07-23 23:45:48 +05:30
context 'within a group' do
let(:scope) { group }
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
it { expect(subject).to be_empty }
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
context 'user with access to only one project' do
before do
project2.add_developer(user)
end
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
it { is_expected.to contain_exactly(package4) }
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
it_behaves_like 'when no package is found'
it_behaves_like 'when package_name param is a non-normalized name'
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
context 'user with access to multiple projects' do
before do
project.add_developer(user)
end
it { is_expected.to contain_exactly(package2, package3, package4) }
end
2021-06-08 01:23:25 +05:30
end
2022-07-23 23:45:48 +05:30
end
end
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
context 'without package_name param' do
let(:package_name) { nil }
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
context 'within a group' do
let(:scope) { group }
2021-06-08 01:23:25 +05:30
2022-07-23 23:45:48 +05:30
context 'user with access to only one project' do
2021-06-08 01:23:25 +05:30
before do
2022-07-23 23:45:48 +05:30
project2.add_developer(user)
2021-06-08 01:23:25 +05:30
end
2022-07-23 23:45:48 +05:30
it { is_expected.to contain_exactly(package4) }
context 'user with access to multiple projects' do
before do
project.add_developer(user)
end
it { is_expected.to contain_exactly(package1, package2, package3, package4) }
end
2021-06-08 01:23:25 +05:30
end
end
2022-07-23 23:45:48 +05:30
context 'within a project' do
let(:scope) { project }
it { is_expected.to contain_exactly(package1, package2, package3) }
end
2021-06-08 01:23:25 +05:30
end
end
end