Commit 2acaad36 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera Committed by Etienne Baqué

Fix dependency proxy manifest sorting on pagination

parent 9d34f894
......@@ -8,6 +8,7 @@ module Types
authorize :read_dependency_proxy
field :id, ::Types::GlobalIDType[::DependencyProxy::Manifest], null: false, description: 'ID of the manifest.'
field :created_at, Types::TimeType, null: false, description: 'Date of creation.'
field :updated_at, Types::TimeType, null: false, description: 'Date of most recent update.'
field :file_name, GraphQL::Types::String, null: false, description: 'Name of the manifest.'
......
......@@ -220,6 +220,10 @@ module Types
group.container_repositories.size
end
def dependency_proxy_manifests
group.dependency_proxy_manifests.order_id_desc
end
def dependency_proxy_image_count
group.dependency_proxy_manifests.count
end
......
......@@ -14,6 +14,8 @@ class DependencyProxy::Manifest < ApplicationRecord
validates :file_name, presence: true
validates :digest, presence: true
scope :order_id_desc, -> { reorder(id: :desc) }
mount_file_store_uploader DependencyProxy::FileUploader
def self.find_by_file_name_or_digest(file_name:, digest:)
......
......@@ -9236,6 +9236,7 @@ Dependency proxy manifest.
| <a id="dependencyproxymanifestcreatedat"></a>`createdAt` | [`Time!`](#time) | Date of creation. |
| <a id="dependencyproxymanifestdigest"></a>`digest` | [`String!`](#string) | Digest of the manifest. |
| <a id="dependencyproxymanifestfilename"></a>`fileName` | [`String!`](#string) | Name of the manifest. |
| <a id="dependencyproxymanifestid"></a>`id` | [`DependencyProxyManifestID!`](#dependencyproxymanifestid) | ID of the manifest. |
| <a id="dependencyproxymanifestimagename"></a>`imageName` | [`String!`](#string) | Name of the image. |
| <a id="dependencyproxymanifestsize"></a>`size` | [`String!`](#string) | Size of the manifest file. |
| <a id="dependencyproxymanifestupdatedat"></a>`updatedAt` | [`Time!`](#time) | Date of most recent update. |
......@@ -17275,6 +17276,12 @@ An example `DastSiteValidationID` is: `"gid://gitlab/DastSiteValidation/1"`.
Date represented in ISO 8601.
### `DependencyProxyManifestID`
A `DependencyProxyManifestID` is a global ID. It is encoded as a string.
An example `DependencyProxyManifestID` is: `"gid://gitlab/DependencyProxy::Manifest/1"`.
### `DesignManagementDesignAtVersionID`
A `DesignManagementDesignAtVersionID` is a global ID. It is encoded as a string.
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe GitlabSchema.types['DependencyProxyManifest'] do
it 'includes dependency proxy manifest fields' do
expected_fields = %w[
file_name image_name size created_at updated_at digest
id file_name image_name size created_at updated_at digest
]
expect(described_class).to include_graphql_fields(*expected_fields)
......
......@@ -15,6 +15,17 @@ RSpec.describe DependencyProxy::Manifest, type: :model do
it { is_expected.to validate_presence_of(:digest) }
end
describe 'scopes' do
let_it_be(:manifest_one) { create(:dependency_proxy_manifest) }
let_it_be(:manifest_two) { create(:dependency_proxy_manifest) }
let_it_be(:manifests) { [manifest_one, manifest_two] }
let_it_be(:ids) { manifests.map(&:id) }
it 'order_id_desc' do
expect(described_class.where(id: ids).order_id_desc.to_a).to eq [manifest_two, manifest_one]
end
end
describe 'file is being stored' do
subject { create(:dependency_proxy_manifest) }
......
......@@ -116,4 +116,26 @@ RSpec.describe 'getting dependency proxy manifests in a group' do
expect(dependency_proxy_image_count_response).to eq(manifests.size)
end
describe 'sorting and pagination' do
let(:data_path) { ['group', :dependencyProxyManifests] }
let(:current_user) { owner }
context 'with default sorting' do
let_it_be(:descending_manifests) { manifests.reverse.map { |manifest| global_id_of(manifest)} }
it_behaves_like 'sorted paginated query' do
let(:sort_param) { '' }
let(:first_param) { 2 }
let(:all_records) { descending_manifests }
end
end
def pagination_query(params)
# remove sort since the type does not accept sorting, but be future proof
graphql_query_for('group', { 'fullPath' => group.full_path },
query_nodes(:dependencyProxyManifests, :id, include_pagination_info: true, args: params.merge(sort: 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