Add full request test for new graphql endpoint

Final clean up of the code, adding a full stack test
For the new endpoint
Co-authored-by: default avatarTetiana Chupryna <tchupryna@gitlab.com>
Co-authored-by: default avatarDavid Fernandez <dfernandez@gitlab.com>
Co-authored-by: default avatarNick Kipling <nkipling@gitlab.com>
Co-authored-by: default avatarSteve Abrams <sabrams@gitlab.com>
parent 5a203b15
......@@ -6640,6 +6640,76 @@ interface Noteable {
): NoteConnection!
}
"""
Represents a package
"""
type Package {
"""
The created date
"""
createdAt: Time!
"""
The ID of the package
"""
id: ID!
"""
The name of the package
"""
name: String!
"""
The type of the package
"""
packageType: PackageTypeEnum!
"""
The update date
"""
updatedAt: Time!
"""
The version of the package
"""
version: String
}
"""
The connection type for Package.
"""
type PackageConnection {
"""
A list of edges.
"""
edges: [PackageEdge]
"""
A list of nodes.
"""
nodes: [Package]
"""
Information to aid in pagination.
"""
pageInfo: PageInfo!
}
"""
An edge in a connection.
"""
type PackageEdge {
"""
A cursor for use in pagination.
"""
cursor: String!
"""
The item at the end of the edge.
"""
node: Package
}
"""
Represents the sync and verification state of a package file
"""
......@@ -6720,6 +6790,38 @@ type PackageFileRegistryEdge {
node: PackageFileRegistry
}
enum PackageTypeEnum {
"""
Packages from the composer package manager
"""
COMPOSER
"""
Packages from the conan package manager
"""
CONAN
"""
Packages from the maven package manager
"""
MAVEN
"""
Packages from the npm package manager
"""
NPM
"""
Packages from the nuget package manager
"""
NUGET
"""
Packages from the pypi package manager
"""
PYPI
}
"""
Information about pagination in a connection.
"""
......@@ -7417,6 +7519,31 @@ type Project {
"""
openIssuesCount: Int
"""
Packages of the project
"""
packages(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): PackageConnection
"""
Path of the project
"""
......
......@@ -984,6 +984,19 @@ Represents a milestone.
| `readNote` | Boolean! | Indicates the user can perform `read_note` on this resource |
| `resolveNote` | Boolean! | Indicates the user can perform `resolve_note` on this resource |
## Package
Represents a package
| Name | Type | Description |
| --- | ---- | ---------- |
| `createdAt` | Time! | The created date |
| `id` | ID! | The ID of the package |
| `name` | String! | The name of the package |
| `packageType` | PackageTypeEnum! | The type of the package |
| `updatedAt` | Time! | The update date |
| `version` | String | The version of the package |
## PackageFileRegistry
Represents the sync and verification state of a package file
......
......@@ -6,6 +6,7 @@ module Resolvers
def resolve(**args)
return unless packages_available?(object, current_user)
::Packages::PackagesFinder.new(object).execute
end
......@@ -16,4 +17,3 @@ module Resolvers
end
end
end
\ No newline at end of file
......@@ -3,8 +3,7 @@
module Types
class PackageTypeEnum < BaseEnum
::Packages::Package.package_types.keys.each do |package_type|
value package_type.to_s.upcase, value: package_type.to_s
value package_type.to_s.upcase, "Packages from the #{package_type} package manager", value: package_type.to_s
end
end
end
\ No newline at end of file
---
title: Add graphql endpoint for project packages list
merge_request: 31344
author:
type: added
......@@ -9,7 +9,6 @@ describe Resolvers::PackagesResolver do
let_it_be(:project) { create(:project) }
let_it_be(:package) { create(:package, project: project) }
describe '#resolve' do
subject(:packages) { resolve(described_class, ctx: { current_user: user }, obj: project) }
......@@ -30,7 +29,7 @@ describe Resolvers::PackagesResolver do
it { is_expected.to contain_exactly(package) }
end
context 'when the user is not authorized to read the package' do
it { is_expected.to be_nil }
end
......@@ -46,8 +45,11 @@ describe Resolvers::PackagesResolver do
end
context 'when the package feature is not enabled' do
before do
stub_licensed_features(packages: false)
end
it { is_expected.to be_nil }
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe 'getting a package list for a project' do
include GraphqlHelpers
let_it_be(:project) { create(:project) }
let_it_be(:current_user) { create(:user) }
let_it_be(:package) { create(:package, project: project) }
let(:packages_data) { graphql_data['project']['packages']['edges'] }
let(:fields) do
<<~QUERY
edges {
node {
#{all_graphql_fields_for('packages'.classify)}
}
}
QUERY
end
let(:query) do
graphql_query_for(
'project',
{ 'fullPath' => project.full_path },
query_graphql_field('packages', {}, fields)
)
end
context 'when package feature is available' do
before do
stub_licensed_features(packages: true)
end
context 'when user has access to the project' do
before do
project.add_reporter(current_user)
end
it_behaves_like 'a working graphql query' do
before do
post_graphql(query, current_user: current_user)
end
end
it 'returns packages successfully' do
post_graphql(query, current_user: current_user)
expect(graphql_errors).to be_nil
expect(packages_data[0]['node']['name']).to eq package.name
end
end
context 'when the user does not have access to the packages' do
it 'returns nil' do
post_graphql(query)
expect(graphql_data['project']).to be_nil
end
end
end
context 'when package feature is not available' do
before do
stub_licensed_features(packages: false)
project.add_reporter(current_user)
end
it 'returns nil' do
post_graphql(query)
expect(graphql_data['project']).to be_nil
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment