@@ -24,6 +24,10 @@ import { uploadFileViaApi } from '../../testHelpers/files/filesHelper'
2424import { deleteUnpublishedDatasetViaApi } from '../../testHelpers/datasets/datasetHelper'
2525import { PublicationStatus } from '../../../src/core/domain/models/PublicationStatus'
2626import { CollectionType } from '../../../src/collections/domain/models/CollectionType'
27+ import {
28+ OrderType ,
29+ SortType
30+ } from '../../../src/collections/domain/models/GetCollectionItemsQueryParams'
2731
2832describe ( 'CollectionsRepository' , ( ) => {
2933 const testCollectionAlias = 'collectionsRepositoryTestCollection'
@@ -525,6 +529,76 @@ describe('CollectionsRepository', () => {
525529 expect ( ( actual . items [ 0 ] as FilePreview ) . name ) . toBe ( expectedFileName )
526530 expect ( ( actual . items [ 1 ] as CollectionPreview ) . name ) . toBe ( expectedCollectionsName )
527531 expect ( actual . facets ) . toEqual ( expectedFacetsFromCollectionAndFile )
532+
533+ // Test sort and order
534+
535+ // Sort by name ascending
536+ const collectionSearchCriteriaNameAscending = new CollectionSearchCriteria ( )
537+ . withSort ( SortType . NAME )
538+ . withOrder ( OrderType . ASC )
539+
540+ actual = await sut . getCollectionItems (
541+ testCollectionAlias ,
542+ undefined ,
543+ undefined ,
544+ collectionSearchCriteriaNameAscending
545+ )
546+ expect ( actual . items . length ) . toBe ( 3 )
547+ expect ( actual . totalItemCount ) . toBe ( 3 )
548+ expect ( ( actual . items [ 0 ] as DatasetPreview ) . type ) . toBe ( CollectionItemType . DATASET )
549+ expect ( ( actual . items [ 1 ] as CollectionPreview ) . type ) . toBe ( CollectionItemType . COLLECTION )
550+ expect ( ( actual . items [ 2 ] as FilePreview ) . type ) . toBe ( CollectionItemType . FILE )
551+
552+ // Sort by name descending
553+ const collectionSearchCriteriaNameDescending = new CollectionSearchCriteria ( )
554+ . withSort ( SortType . NAME )
555+ . withOrder ( OrderType . DESC )
556+
557+ actual = await sut . getCollectionItems (
558+ testCollectionAlias ,
559+ undefined ,
560+ undefined ,
561+ collectionSearchCriteriaNameDescending
562+ )
563+ expect ( actual . items . length ) . toBe ( 3 )
564+ expect ( actual . totalItemCount ) . toBe ( 3 )
565+ expect ( ( actual . items [ 0 ] as FilePreview ) . type ) . toBe ( CollectionItemType . FILE )
566+ expect ( ( actual . items [ 1 ] as CollectionPreview ) . type ) . toBe ( CollectionItemType . COLLECTION )
567+ expect ( ( actual . items [ 2 ] as DatasetPreview ) . type ) . toBe ( CollectionItemType . DATASET )
568+
569+ // Sort by date ascending
570+ const collectionSearchCriteriaDateAscending = new CollectionSearchCriteria ( )
571+ . withSort ( SortType . DATE )
572+ . withOrder ( OrderType . ASC )
573+
574+ actual = await sut . getCollectionItems (
575+ testCollectionAlias ,
576+ undefined ,
577+ undefined ,
578+ collectionSearchCriteriaDateAscending
579+ )
580+ expect ( actual . items . length ) . toBe ( 3 )
581+ expect ( actual . totalItemCount ) . toBe ( 3 )
582+ expect ( ( actual . items [ 0 ] as CollectionPreview ) . type ) . toBe ( CollectionItemType . COLLECTION )
583+ expect ( ( actual . items [ 1 ] as DatasetPreview ) . type ) . toBe ( CollectionItemType . DATASET )
584+ expect ( ( actual . items [ 2 ] as FilePreview ) . type ) . toBe ( CollectionItemType . FILE )
585+
586+ // Sort by date descending
587+ const collectionSearchCriteriaDateDescending = new CollectionSearchCriteria ( )
588+ . withSort ( SortType . DATE )
589+ . withOrder ( OrderType . DESC )
590+
591+ actual = await sut . getCollectionItems (
592+ testCollectionAlias ,
593+ undefined ,
594+ undefined ,
595+ collectionSearchCriteriaDateDescending
596+ )
597+ expect ( actual . items . length ) . toBe ( 3 )
598+ expect ( actual . totalItemCount ) . toBe ( 3 )
599+ expect ( ( actual . items [ 0 ] as FilePreview ) . type ) . toBe ( CollectionItemType . FILE )
600+ expect ( ( actual . items [ 1 ] as DatasetPreview ) . type ) . toBe ( CollectionItemType . DATASET )
601+ expect ( ( actual . items [ 2 ] as CollectionPreview ) . type ) . toBe ( CollectionItemType . COLLECTION )
528602 } )
529603
530604 test ( 'should return error when collection does not exist' , async ( ) => {
0 commit comments