2020-07-17 02:09:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe API::GroupPackages do
|
|
|
|
let_it_be(:group) { create(:group, :public) }
|
|
|
|
let_it_be(:project) { create(:project, :public, namespace: group, name: 'project A') }
|
|
|
|
let_it_be(:user) { create(:user) }
|
2021-06-28 23:07:32 -04:00
|
|
|
|
2021-01-06 16:10:18 -05:00
|
|
|
let(:params) { {} }
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2021-01-06 16:10:18 -05:00
|
|
|
subject { get api(url), params: params }
|
2020-07-17 02:09:11 -04:00
|
|
|
|
|
|
|
describe 'GET /groups/:id/packages' do
|
|
|
|
let(:url) { "/groups/#{group.id}/packages" }
|
|
|
|
let(:package_schema) { 'public_api/v4/packages/group_packages' }
|
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
context 'with sorting' do
|
|
|
|
let_it_be(:package1) { create(:npm_package, project: project, version: '3.1.0', name: "@#{project.root_namespace.path}/foo1") }
|
|
|
|
let_it_be(:package2) { create(:nuget_package, project: project, version: '2.0.4') }
|
2021-06-28 23:07:32 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
let(:package3) { create(:maven_package, project: project, version: '1.1.1', name: 'zzz') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
travel_to(1.day.ago) do
|
|
|
|
package3
|
2020-07-17 02:09:11 -04:00
|
|
|
end
|
2020-08-05 05:10:01 -04:00
|
|
|
end
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
context 'without sorting params' do
|
|
|
|
let(:packages) { [package3, package1, package2] }
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
it 'sorts by created_at asc' do
|
|
|
|
subject
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
expect(json_response.map { |package| package['id'] }).to eq(packages.map(&:id))
|
2020-07-17 02:09:11 -04:00
|
|
|
end
|
2020-08-05 05:10:01 -04:00
|
|
|
end
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
it_behaves_like 'package sorting', 'name' do
|
|
|
|
let(:packages) { [package1, package2, package3] }
|
|
|
|
end
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
it_behaves_like 'package sorting', 'created_at' do
|
|
|
|
let(:packages) { [package3, package1, package2] }
|
|
|
|
end
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
it_behaves_like 'package sorting', 'version' do
|
|
|
|
let(:packages) { [package3, package2, package1] }
|
|
|
|
end
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
it_behaves_like 'package sorting', 'type' do
|
|
|
|
let(:packages) { [package3, package1, package2] }
|
|
|
|
end
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
it_behaves_like 'package sorting', 'project_path' do
|
|
|
|
let(:another_project) { create(:project, :public, namespace: group, name: 'project B') }
|
|
|
|
let!(:package4) { create(:npm_package, project: another_project, version: '3.1.0', name: "@#{project.root_namespace.path}/bar") }
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
let(:packages) { [package1, package2, package3, package4] }
|
2020-07-17 02:09:11 -04:00
|
|
|
end
|
2020-08-05 05:10:01 -04:00
|
|
|
end
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
context 'with private group' do
|
|
|
|
let!(:package1) { create(:package, project: project) }
|
|
|
|
let!(:package2) { create(:package, project: project) }
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
let(:group) { create(:group, :private) }
|
|
|
|
let(:subgroup) { create(:group, :private, parent: group) }
|
|
|
|
let(:project) { create(:project, :private, namespace: group) }
|
|
|
|
let(:subproject) { create(:project, :private, namespace: subgroup) }
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
context 'with unauthenticated user' do
|
|
|
|
it_behaves_like 'rejects packages access', :group, :no_type, :not_found
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with authenticated user' do
|
|
|
|
subject { get api(url, user) }
|
|
|
|
|
|
|
|
it_behaves_like 'returns packages', :group, :owner
|
|
|
|
it_behaves_like 'returns packages', :group, :maintainer
|
|
|
|
it_behaves_like 'returns packages', :group, :developer
|
2020-09-25 14:09:46 -04:00
|
|
|
it_behaves_like 'returns packages', :group, :reporter
|
2020-08-05 05:10:01 -04:00
|
|
|
it_behaves_like 'rejects packages access', :group, :guest, :forbidden
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
context 'with subgroup' do
|
|
|
|
let(:subgroup) { create(:group, :private, parent: group) }
|
|
|
|
let(:subproject) { create(:project, :private, namespace: subgroup) }
|
|
|
|
let!(:package3) { create(:npm_package, project: subproject) }
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
it_behaves_like 'returns packages with subgroups', :group, :owner
|
|
|
|
it_behaves_like 'returns packages with subgroups', :group, :maintainer
|
|
|
|
it_behaves_like 'returns packages with subgroups', :group, :developer
|
2020-09-25 14:09:46 -04:00
|
|
|
it_behaves_like 'returns packages with subgroups', :group, :reporter
|
2020-07-17 02:09:11 -04:00
|
|
|
it_behaves_like 'rejects packages access', :group, :guest, :forbidden
|
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
context 'excluding subgroup' do
|
|
|
|
let(:url) { "/groups/#{group.id}/packages?exclude_subgroups=true" }
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
it_behaves_like 'returns packages', :group, :owner
|
|
|
|
it_behaves_like 'returns packages', :group, :maintainer
|
|
|
|
it_behaves_like 'returns packages', :group, :developer
|
2020-09-25 14:09:46 -04:00
|
|
|
it_behaves_like 'returns packages', :group, :reporter
|
2020-07-17 02:09:11 -04:00
|
|
|
it_behaves_like 'rejects packages access', :group, :guest, :forbidden
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-08-05 05:10:01 -04:00
|
|
|
end
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
context 'with public group' do
|
|
|
|
let_it_be(:package1) { create(:package, project: project) }
|
|
|
|
let_it_be(:package2) { create(:package, project: project) }
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
context 'with unauthenticated user' do
|
|
|
|
it_behaves_like 'returns packages', :group, :no_type
|
|
|
|
end
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
context 'with authenticated user' do
|
|
|
|
subject { get api(url, user) }
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
it_behaves_like 'returns packages', :group, :owner
|
|
|
|
it_behaves_like 'returns packages', :group, :maintainer
|
|
|
|
it_behaves_like 'returns packages', :group, :developer
|
|
|
|
it_behaves_like 'returns packages', :group, :reporter
|
|
|
|
it_behaves_like 'returns packages', :group, :guest
|
2020-07-17 02:09:11 -04:00
|
|
|
end
|
2020-08-05 05:10:01 -04:00
|
|
|
end
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
context 'with pagination params' do
|
|
|
|
let_it_be(:package1) { create(:package, project: project) }
|
|
|
|
let_it_be(:package2) { create(:package, project: project) }
|
|
|
|
let_it_be(:package3) { create(:npm_package, project: project) }
|
|
|
|
let_it_be(:package4) { create(:npm_package, project: project) }
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
it_behaves_like 'returns paginated packages'
|
|
|
|
end
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
it_behaves_like 'filters on each package_type', is_project: false
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
context 'does not accept non supported package_type value' do
|
|
|
|
include_context 'package filter context'
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
let(:url) { group_filter_url(:type, 'foo') }
|
2020-07-17 02:09:11 -04:00
|
|
|
|
2020-08-05 05:10:01 -04:00
|
|
|
it_behaves_like 'returning response status', :bad_request
|
2020-07-17 02:09:11 -04:00
|
|
|
end
|
2020-09-03 20:09:08 -04:00
|
|
|
|
2021-01-06 16:10:18 -05:00
|
|
|
it_behaves_like 'with versionless packages'
|
2021-02-17 07:09:26 -05:00
|
|
|
it_behaves_like 'with status param'
|
2020-09-03 20:09:08 -04:00
|
|
|
it_behaves_like 'does not cause n^2 queries'
|
2020-07-17 02:09:11 -04:00
|
|
|
end
|
|
|
|
end
|