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

104 lines
3 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Packages::PackagesFinder do
let_it_be(:project) { create(:project) }
let_it_be(:maven_package) { create(:maven_package, project: project, created_at: 2.days.ago, name: 'maven', version: '2.0.0') }
let_it_be(:conan_package) { create(:conan_package, project: project, created_at: 1.day.ago, name: 'conan', version: '1.0.0') }
describe '#execute' do
let(:params) { {} }
subject { described_class.new(project, params).execute }
context 'with package_type' do
let_it_be(:npm_package1) { create(:npm_package, project: project) }
let_it_be(:npm_package2) { create(:npm_package, project: project) }
context 'conan packages' do
let(:params) { { package_type: 'conan' } }
it { is_expected.to eq([conan_package]) }
end
context 'npm packages' do
let(:params) { { package_type: 'npm' } }
it { is_expected.to match_array([npm_package1, npm_package2]) }
end
end
context 'with order_by' do
context 'by default is created_at' do
it { is_expected.to eq([maven_package, conan_package]) }
end
context 'order by name' do
let(:params) { { order_by: 'name' } }
it { is_expected.to eq([conan_package, maven_package]) }
end
context 'order by version' do
let(:params) { { order_by: 'version' } }
it { is_expected.to eq([conan_package, maven_package]) }
end
context 'order by type' do
let(:params) { { order_by: 'type' } }
it { is_expected.to eq([maven_package, conan_package]) }
end
end
context 'with sort' do
context 'by default is ascending' do
it { is_expected.to eq([maven_package, conan_package]) }
end
context 'can sort descended' do
let(:params) { { sort: 'desc' } }
it { is_expected.to eq([conan_package, maven_package]) }
end
end
context 'with package_name' do
let(:params) { { package_name: 'maven' } }
it { is_expected.to eq([maven_package]) }
end
context 'with nil params' do
it { is_expected.to match_array([conan_package, maven_package]) }
end
context 'with processing packages' do
2021-06-08 01:23:25 +05:30
let_it_be(:nuget_package) { create(:nuget_package, :processing, project: project) }
2020-07-28 23:09:34 +05:30
it { is_expected.to match_array([conan_package, maven_package]) }
end
2022-06-21 17:19:12 +05:30
context 'preload_pipelines' do
it 'preloads pipelines by default' do
expect(Packages::Package).to receive(:preload_pipelines).and_call_original
expect(subject).to match_array([maven_package, conan_package])
end
context 'set to false' do
let(:params) { { preload_pipelines: false } }
it 'does not preload pipelines' do
expect(Packages::Package).not_to receive(:preload_pipelines)
expect(subject).to match_array([maven_package, conan_package])
end
end
end
2021-03-08 18:12:59 +05:30
it_behaves_like 'concerning versionless param'
2021-03-11 19:13:27 +05:30
it_behaves_like 'concerning package statuses'
2020-07-28 23:09:34 +05:30
end
end