debian-mirror-gitlab/spec/services/packages/nuget/search_service_spec.rb

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

164 lines
4.8 KiB
Ruby
Raw Permalink Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
2021-03-08 18:12:59 +05:30
2020-07-28 23:09:34 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Packages::Nuget::SearchService, feature_category: :package_registry do
2021-03-08 18:12:59 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:subgroup) { create(:group, parent: group) }
let_it_be(:project) { create(:project, namespace: subgroup) }
2021-06-08 01:23:25 +05:30
let_it_be_with_refind(:package_a) { create(:nuget_package, project: project, name: 'DummyPackageA') }
2020-07-28 23:09:34 +05:30
let_it_be(:packages_b) { create_list(:nuget_package, 5, project: project, name: 'DummyPackageB') }
let_it_be(:packages_c) { create_list(:nuget_package, 5, project: project, name: 'DummyPackageC') }
let_it_be(:package_d) { create(:nuget_package, project: project, name: 'FooBarD') }
let_it_be(:other_package_a) { create(:nuget_package, name: 'DummyPackageA') }
let_it_be(:other_package_a) { create(:nuget_package, name: 'DummyPackageB') }
2021-09-30 23:02:18 +05:30
2020-07-28 23:09:34 +05:30
let(:search_term) { 'ummy' }
let(:per_page) { 5 }
let(:padding) { 0 }
let(:include_prerelease_versions) { true }
let(:options) { { include_prerelease_versions: include_prerelease_versions, per_page: per_page, padding: padding } }
describe '#execute' do
2021-03-08 18:12:59 +05:30
subject { described_class.new(user, target, search_term, options).execute }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
shared_examples 'handling all the conditions' do
it { expect_search_results 3, package_a, packages_b, packages_c }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
context 'with a smaller per page count' do
let(:per_page) { 2 }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
it { expect_search_results 3, package_a, packages_b }
end
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
context 'with 0 per page count' do
let(:per_page) { 0 }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
it { expect_search_results 3, [] }
end
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
context 'with a negative per page count' do
let(:per_page) { -1 }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
it { expect { subject }.to raise_error(ArgumentError, 'negative per_page') }
end
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
context 'with a padding' do
let(:padding) { 2 }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
it { expect_search_results 3, packages_c }
end
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
context 'with a too big padding' do
let(:padding) { 5 }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
it { expect_search_results 3, [] }
end
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
context 'with a negative padding' do
let(:padding) { -1 }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
it { expect { subject }.to raise_error(ArgumentError, 'negative padding') }
end
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
context 'with search term' do
let(:search_term) { 'umm' }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
it { expect_search_results 3, package_a, packages_b, packages_c }
end
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
context 'with nil search term' do
let(:search_term) { nil }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
it { expect_search_results 4, package_a, packages_b, packages_c, package_d }
end
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
context 'with empty search term' do
let(:search_term) { '' }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
it { expect_search_results 4, package_a, packages_b, packages_c, package_d }
end
2020-07-28 23:09:34 +05:30
2021-06-08 01:23:25 +05:30
context 'with non-displayable packages' do
let(:search_term) { '' }
before do
package_a.update_column(:status, 1)
end
it { expect_search_results 3, packages_b, packages_c, package_d }
end
2021-03-08 18:12:59 +05:30
context 'with prefix search term' do
let(:search_term) { 'dummy' }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
it { expect_search_results 3, package_a, packages_b, packages_c }
end
context 'with suffix search term' do
let(:search_term) { 'packagec' }
it { expect_search_results 1, packages_c }
end
context 'with pre release packages' do
let_it_be(:package_e) { create(:nuget_package, project: project, name: 'DummyPackageE', version: '3.2.1-alpha') }
context 'including them' do
it { expect_search_results 4, package_a, packages_b, packages_c, package_e }
end
context 'excluding them' do
let(:include_prerelease_versions) { false }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
it { expect_search_results 3, package_a, packages_b, packages_c }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
context 'when mixed with release versions' do
let_it_be(:package_e_release) { create(:nuget_package, project: project, name: 'DummyPackageE', version: '3.2.1') }
it { expect_search_results 4, package_a, packages_b, packages_c, package_e_release }
end
end
end
2020-07-28 23:09:34 +05:30
end
2021-03-08 18:12:59 +05:30
context 'with project' do
let(:target) { project }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
before do
project.add_developer(user)
2020-07-28 23:09:34 +05:30
end
2021-03-08 18:12:59 +05:30
it_behaves_like 'handling all the conditions'
end
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
context 'with subgroup' do
let(:target) { subgroup }
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
before do
subgroup.add_developer(user)
end
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
it_behaves_like 'handling all the conditions'
end
context 'with group' do
let(:target) { group }
before do
group.add_developer(user)
2020-07-28 23:09:34 +05:30
end
2021-03-08 18:12:59 +05:30
it_behaves_like 'handling all the conditions'
2020-07-28 23:09:34 +05:30
end
def expect_search_results(total_count, *results)
search = subject
expect(search.total_count).to eq total_count
expect(search.results).to match_array(Array.wrap(results).flatten)
end
end
end