2021-03-11 19:13:27 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'package details' do
|
|
|
|
include GraphqlHelpers
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
let_it_be_with_reload(:group) { create(:group) }
|
|
|
|
let_it_be_with_reload(:project) { create(:project, group: group) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
2021-04-29 21:17:54 +05:30
|
|
|
let_it_be(:composer_package) { create(:composer_package, project: project) }
|
2021-03-11 19:13:27 +05:30
|
|
|
let_it_be(:composer_json) { { name: 'name', type: 'type', license: 'license', version: 1 } }
|
|
|
|
let_it_be(:composer_metadatum) do
|
|
|
|
# we are forced to manually create the metadatum, without using the factory to force the sha to be a string
|
|
|
|
# and avoid an error where gitaly can't find the repository
|
2021-04-29 21:17:54 +05:30
|
|
|
create(:composer_metadatum, package: composer_package, target_sha: 'foo_sha', composer_json: composer_json)
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
let(:depth) { 3 }
|
2021-04-29 21:17:54 +05:30
|
|
|
let(:excluded) { %w[metadata apiFuzzingCiConfiguration pipeline packageFiles] }
|
|
|
|
let(:metadata) { query_graphql_fragment('ComposerMetadata') }
|
|
|
|
let(:package_files) {all_graphql_fields_for('PackageFile')}
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:package_global_id) { global_id_of(composer_package) }
|
|
|
|
let(:package_details) { graphql_data_at(:package) }
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
let(:query) do
|
|
|
|
graphql_query_for(:package, { id: package_global_id }, <<~FIELDS)
|
2021-04-29 21:17:54 +05:30
|
|
|
#{all_graphql_fields_for('PackageDetailsType', max_depth: depth, excluded: excluded)}
|
2021-03-11 19:13:27 +05:30
|
|
|
metadata {
|
2021-04-29 21:17:54 +05:30
|
|
|
#{metadata}
|
|
|
|
}
|
|
|
|
packageFiles {
|
|
|
|
nodes {
|
|
|
|
#{package_files}
|
|
|
|
}
|
2021-03-11 19:13:27 +05:30
|
|
|
}
|
|
|
|
FIELDS
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { post_graphql(query, current_user: user) }
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
context 'with unauthorized user' do
|
2021-03-11 19:13:27 +05:30
|
|
|
before do
|
2022-03-02 08:16:31 +05:30
|
|
|
project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it 'returns no packages' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(graphql_data_at(:package)).to be_nil
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
context 'with authorized user' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it_behaves_like 'a working graphql query' do
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it 'matches the JSON schema' do
|
|
|
|
expect(package_details).to match_schema('graphql/packages/package_details')
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
context 'there are other versions of this package' do
|
|
|
|
let(:depth) { 3 }
|
|
|
|
let(:excluded) { %w[metadata project tags pipelines] } # to limit the query complexity
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
let_it_be(:siblings) { create_list(:composer_package, 2, project: project, name: composer_package.name) }
|
|
|
|
|
|
|
|
it 'includes the sibling versions' do
|
2021-03-11 19:13:27 +05:30
|
|
|
subject
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
expect(graphql_data_at(:package, :versions, :nodes)).to match_array(
|
|
|
|
siblings.map { |p| a_hash_including('id' => global_id_of(p)) }
|
|
|
|
)
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
context 'going deeper' do
|
|
|
|
let(:depth) { 6 }
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it 'does not create a cycle of versions' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(graphql_data_at(:package, :versions, :nodes, :version)).to be_present
|
|
|
|
expect(graphql_data_at(:package, :versions, :nodes, :versions, :nodes)).to match_array [nil, nil]
|
|
|
|
end
|
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
context 'with package files pending destruction' do
|
|
|
|
let_it_be(:package_file) { create(:package_file, package: composer_package) }
|
|
|
|
let_it_be(:package_file_pending_destruction) { create(:package_file, :pending_destruction, package: composer_package) }
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
let(:package_file_ids) { graphql_data_at(:package, :package_files, :nodes).map { |node| node["id"] } }
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it 'does not return them' do
|
|
|
|
subject
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
expect(package_file_ids).to contain_exactly(package_file.to_global_id.to_s)
|
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
end
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
context 'with a batched query' do
|
|
|
|
let_it_be(:conan_package) { create(:conan_package, project: project) }
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
let(:batch_query) do
|
|
|
|
<<~QUERY
|
|
|
|
{
|
|
|
|
a: package(id: "#{global_id_of(composer_package)}") { name }
|
|
|
|
b: package(id: "#{global_id_of(conan_package)}") { name }
|
|
|
|
}
|
|
|
|
QUERY
|
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
let(:a_packages_names) { graphql_data_at(:a, :packages, :nodes, :name) }
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it 'returns an error for the second package and data for the first' do
|
|
|
|
post_graphql(batch_query, current_user: user)
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
expect(graphql_data_at(:a, :name)).to eq(composer_package.name)
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
expect_graphql_errors_to_include [/Package details can be requested only for one package at a time/]
|
|
|
|
expect(graphql_data_at(:b)).to be(nil)
|
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
end
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
context 'pipelines field', :aggregate_failures do
|
|
|
|
let(:pipelines) { create_list(:ci_pipeline, 6, project: project) }
|
|
|
|
let(:pipeline_gids) { pipelines.sort_by(&:id).map(&:to_gid).map(&:to_s).reverse }
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
before do
|
2022-04-04 11:22:00 +05:30
|
|
|
pipelines.each do |pipeline|
|
|
|
|
create(:package_build_info, package: composer_package, pipeline: pipeline)
|
|
|
|
end
|
2022-03-02 08:16:31 +05:30
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
def run_query(args)
|
|
|
|
pipelines_nodes = <<~QUERY
|
|
|
|
nodes {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
pageInfo {
|
|
|
|
startCursor
|
|
|
|
endCursor
|
|
|
|
}
|
|
|
|
QUERY
|
|
|
|
|
|
|
|
query = graphql_query_for(:package, { id: package_global_id }, query_graphql_field("pipelines", args, pipelines_nodes))
|
|
|
|
post_graphql(query, current_user: user)
|
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it 'loads the second page with pagination first correctly' do
|
|
|
|
run_query(first: 2)
|
|
|
|
pipeline_ids = graphql_data.dig('package', 'pipelines', 'nodes').pluck('id')
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
expect(pipeline_ids).to eq(pipeline_gids[0..1])
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
cursor = graphql_data.dig('package', 'pipelines', 'pageInfo', 'endCursor')
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
run_query(first: 2, after: cursor)
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
pipeline_ids = graphql_data.dig('package', 'pipelines', 'nodes').pluck('id')
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
expect(pipeline_ids).to eq(pipeline_gids[2..3])
|
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it 'loads the second page with pagination last correctly' do
|
|
|
|
run_query(last: 2)
|
|
|
|
pipeline_ids = graphql_data.dig('package', 'pipelines', 'nodes').pluck('id')
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
expect(pipeline_ids).to eq(pipeline_gids[4..5])
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
cursor = graphql_data.dig('package', 'pipelines', 'pageInfo', 'startCursor')
|
|
|
|
|
|
|
|
run_query(last: 2, before: cursor)
|
|
|
|
|
|
|
|
pipeline_ids = graphql_data.dig('package', 'pipelines', 'nodes').pluck('id')
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
expect(pipeline_ids).to eq(pipeline_gids[2..3])
|
|
|
|
end
|
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
context 'package managers paths' do
|
2022-01-26 12:08:38 +05:30
|
|
|
before do
|
2022-03-02 08:16:31 +05:30
|
|
|
subject
|
2022-01-26 12:08:38 +05:30
|
|
|
end
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it 'returns npm_url correctly' do
|
|
|
|
expect(graphql_data_at(:package, :npm_url)).to eq("http://localhost/api/v4/projects/#{project.id}/packages/npm")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns maven_url correctly' do
|
|
|
|
expect(graphql_data_at(:package, :maven_url)).to eq("http://localhost/api/v4/projects/#{project.id}/packages/maven")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns conan_url correctly' do
|
|
|
|
expect(graphql_data_at(:package, :conan_url)).to eq("http://localhost/api/v4/projects/#{project.id}/packages/conan")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nuget_url correctly' do
|
|
|
|
expect(graphql_data_at(:package, :nuget_url)).to eq("http://localhost/api/v4/projects/#{project.id}/packages/nuget/index.json")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns pypi_url correctly' do
|
|
|
|
expect(graphql_data_at(:package, :pypi_url)).to eq("http://__token__:<your_personal_token>@localhost/api/v4/projects/#{project.id}/packages/pypi/simple")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns pypi_setup_url correctly' do
|
|
|
|
expect(graphql_data_at(:package, :pypi_setup_url)).to eq("http://localhost/api/v4/projects/#{project.id}/packages/pypi")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns composer_url correctly' do
|
|
|
|
expect(graphql_data_at(:package, :composer_url)).to eq("http://localhost/api/v4/group/#{group.id}/-/packages/composer/packages.json")
|
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it 'returns composer_config_repository_url correctly' do
|
|
|
|
expect(graphql_data_at(:package, :composer_config_repository_url)).to eq("localhost/#{group.id}")
|
2022-01-26 12:08:38 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|