@@ -20,8 +20,12 @@ import {
2020 ROOT_COLLECTION_ALIAS
2121} from '../../testHelpers/collections/collectionHelper'
2222import { CollectionPayload } from '../../../src/collections/infra/repositories/transformers/CollectionPayload'
23- import { uploadFileViaApi } from '../../testHelpers/files/filesHelper'
24- import { deleteUnpublishedDatasetViaApi } from '../../testHelpers/datasets/datasetHelper'
23+ import { updateFileTabularTags , uploadFileViaApi } from '../../testHelpers/files/filesHelper'
24+ import {
25+ deletePublishedDatasetViaApi ,
26+ deleteUnpublishedDatasetViaApi ,
27+ publishDatasetViaApi
28+ } from '../../testHelpers/datasets/datasetHelper'
2529import { PublicationStatus } from '../../../src/core/domain/models/PublicationStatus'
2630import { CollectionType } from '../../../src/collections/domain/models/CollectionType'
2731import {
@@ -33,7 +37,7 @@ describe('CollectionsRepository', () => {
3337 const testCollectionAlias = 'collectionsRepositoryTestCollection'
3438 const sut : CollectionsRepository = new CollectionsRepository ( )
3539 let testCollectionId : number
36-
40+ const currentYear = new Date ( ) . getFullYear ( )
3741 beforeAll ( async ( ) => {
3842 ApiConfig . init (
3943 TestConstants . TEST_API_URL ,
@@ -292,8 +296,7 @@ describe('CollectionsRepository', () => {
292296 const actualCollectionPreview = actual . items [ 2 ] as CollectionPreview
293297
294298 const expectedFileMd5 = '68b22040025784da775f55cfcb6dee2e'
295- const expectedDatasetCitationFragment =
296- 'Admin, Dataverse; Owner, Dataverse, 2025, "Dataset created using the createDataset use case'
299+ const expectedDatasetCitationFragment = `Admin, Dataverse; Owner, Dataverse, ${ currentYear } , "Dataset created using the createDataset use case"`
297300 const expectedDatasetDescription = 'Dataset created using the createDataset use case'
298301 const expectedFileName = 'test-file-1.txt'
299302 const expectedCollectionsName = 'Scientific Research'
@@ -660,6 +663,156 @@ describe('CollectionsRepository', () => {
660663 } )
661664 } )
662665
666+ describe ( 'getCollectionItems for published tabular file' , ( ) => {
667+ let testDatasetIds : CreatedDatasetIdentifiers
668+ const testTextFile4Name = 'test-file-4.tab'
669+ const testSubCollectionAlias = 'collectionsRepositoryTestSubCollection'
670+
671+ beforeAll ( async ( ) => {
672+ await sut . publishCollection ( testCollectionId ) . catch ( ( ) => {
673+ throw new Error ( `Tests beforeAll(): Error while publishing collection ${ testCollectionId } ` )
674+ } )
675+
676+ const collectionPayload = await createCollectionViaApi (
677+ testSubCollectionAlias ,
678+ testCollectionAlias
679+ ) . catch ( ( ) => {
680+ throw new Error (
681+ `Tests beforeAll(): Error while creating subcollection ${ testSubCollectionAlias } `
682+ )
683+ } )
684+
685+ await sut . publishCollection ( collectionPayload . id ) . catch ( ( ) => {
686+ throw new Error ( `Tests beforeAll(): Error while publishing collection ${ testCollectionId } ` )
687+ } )
688+
689+ try {
690+ testDatasetIds = await createDataset . execute (
691+ TestConstants . TEST_NEW_DATASET_DTO ,
692+ testSubCollectionAlias
693+ )
694+ } catch ( error ) {
695+ throw new Error ( 'Tests beforeAll(): Error while creating test dataset' )
696+ }
697+ const uploadFileViaApiResult = await uploadFileViaApi (
698+ testDatasetIds . numericId ,
699+ testTextFile4Name ,
700+ {
701+ categories : [ 'tabular data' ]
702+ }
703+ ) . catch ( ( ) => {
704+ throw new Error ( `Tests beforeAll(): Error while uploading file ${ testTextFile4Name } ` )
705+ } )
706+ await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) )
707+
708+ await updateFileTabularTags ( uploadFileViaApiResult . data . data . files [ 0 ] . dataFile . id , [
709+ 'Survey' ,
710+ 'Genomics'
711+ ] ) . catch ( ( ) => {
712+ throw new Error (
713+ `Tests beforeAll(): Error while updating file tabular tags ${ uploadFileViaApiResult . data . data . files [ 0 ] . dataFile . id } `
714+ )
715+ } )
716+
717+ await publishDatasetViaApi ( testDatasetIds . numericId ) . catch ( ( ) => {
718+ throw new Error (
719+ `Tests beforeAll(): Error while publishing dataset ${ testDatasetIds . numericId } `
720+ )
721+ } )
722+ } )
723+
724+ afterAll ( async ( ) => {
725+ try {
726+ await deletePublishedDatasetViaApi ( testDatasetIds . persistentId )
727+ } catch ( error ) {
728+ throw new Error (
729+ `Tests afterAll(): Error while deleting test dataset ${ testDatasetIds . persistentId } `
730+ )
731+ }
732+ try {
733+ await deleteCollectionViaApi ( testSubCollectionAlias )
734+ } catch ( error ) {
735+ throw new Error (
736+ `Tests afterAll(): Error while deleting subcollection ${ testSubCollectionAlias } `
737+ )
738+ }
739+ } )
740+
741+ test ( 'should return collection items given a valid collection alias' , async ( ) => {
742+ // Give enough time to Solr for indexing
743+ await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) )
744+
745+ const actual = await sut . getCollectionItems ( testCollectionAlias )
746+ const actualFilePreview = actual . items [ 1 ] as FilePreview
747+ const actualDatasetPreview = actual . items [ 0 ] as DatasetPreview
748+ const actualCollectionPreview = actual . items [ 2 ] as CollectionPreview
749+
750+ const expectedFileMd5 = '77c7f03a7d7772907b43f0b322cef723'
751+
752+ const expectedDatasetCitationFragment = `Admin, Dataverse; Owner, Dataverse, ${ currentYear } , "Dataset created using the createDataset use case`
753+ const expectedDatasetDescription = 'Dataset created using the createDataset use case'
754+ const expectedFileName = 'test-file-4.tab'
755+ const expectedCollectionsName = 'Scientific Research'
756+
757+ expect ( actualFilePreview . checksum ?. type ) . toBe ( 'MD5' )
758+ expect ( actualFilePreview . checksum ?. value ) . toBe ( expectedFileMd5 )
759+ expect ( actualFilePreview . datasetCitation ) . toContain ( expectedDatasetCitationFragment )
760+ expect ( actualFilePreview . datasetId ) . toBe ( testDatasetIds . numericId )
761+ expect ( actualFilePreview . datasetName ) . toBe ( expectedDatasetDescription )
762+ expect ( actualFilePreview . datasetPersistentId ) . toBe ( testDatasetIds . persistentId )
763+ expect ( actualFilePreview . description ) . toBe ( '' )
764+ expect ( actualFilePreview . fileContentType ) . toBe ( 'text/tab-separated-values' )
765+ expect ( actualFilePreview . fileId ) . not . toBeUndefined ( )
766+ expect ( actualFilePreview . fileType ) . toBe ( 'Tab-Delimited' )
767+ expect ( actualFilePreview . md5 ) . toBe ( expectedFileMd5 )
768+ expect ( actualFilePreview . name ) . toBe ( expectedFileName )
769+ expect ( actualFilePreview . publicationStatuses [ 0 ] ) . toBe ( PublicationStatus . Published )
770+ expect ( actualFilePreview . sizeInBytes ) . toBe ( 137 )
771+ expect ( actualFilePreview . url ) . not . toBeUndefined ( )
772+ expect ( actualFilePreview . releaseOrCreateDate ) . not . toBeUndefined ( )
773+ expect ( actualFilePreview . type ) . toBe ( CollectionItemType . FILE )
774+ expect ( actualFilePreview . restricted ) . toBe ( false )
775+ expect ( actualFilePreview . canDownloadFile ) . toBe ( true )
776+ expect ( actualFilePreview . categories ) . toEqual ( [ 'tabular data' ] )
777+ expect ( actualFilePreview . tabularTags ) . toEqual ( [ 'Genomics' , 'Survey' ] )
778+ expect ( actualFilePreview . observations ) . toBe ( 10 )
779+ expect ( actualFilePreview . variables ) . toBe ( 3 )
780+
781+ expect ( actualDatasetPreview . title ) . toBe ( expectedDatasetDescription )
782+ expect ( actualDatasetPreview . citation ) . toContain ( expectedDatasetCitationFragment )
783+ expect ( actualDatasetPreview . description ) . toBe ( 'This is the description of the dataset.' )
784+ expect ( actualDatasetPreview . persistentId ) . not . toBeUndefined ( )
785+ expect ( actualDatasetPreview . persistentId ) . not . toBeUndefined ( )
786+ expect ( actualDatasetPreview . publicationStatuses [ 0 ] ) . toBe ( PublicationStatus . Published )
787+ expect ( actualDatasetPreview . versionId ) . not . toBeUndefined ( )
788+ expect ( actualDatasetPreview . versionInfo . createTime ) . not . toBeUndefined ( )
789+ expect ( actualDatasetPreview . versionInfo . lastUpdateTime ) . not . toBeUndefined ( )
790+ expect ( actualDatasetPreview . versionInfo . majorNumber ) . toBe ( 1 )
791+ expect ( actualDatasetPreview . versionInfo . minorNumber ) . toBe ( 0 )
792+ expect ( actualDatasetPreview . versionInfo . state ) . toBe ( 'RELEASED' )
793+ expect ( actualDatasetPreview . parentCollectionAlias ) . toBe (
794+ 'collectionsRepositoryTestSubCollection'
795+ )
796+ expect ( actualDatasetPreview . parentCollectionName ) . toBe ( expectedCollectionsName )
797+ expect ( actualDatasetPreview . type ) . toBe ( CollectionItemType . DATASET )
798+
799+ expect ( actualCollectionPreview . name ) . toBe ( expectedCollectionsName )
800+ expect ( actualCollectionPreview . alias ) . toBe ( testSubCollectionAlias )
801+ expect ( actualCollectionPreview . description ) . toBe ( 'We do all the science.' )
802+ expect ( actualCollectionPreview . imageUrl ) . toBe ( undefined )
803+ expect ( actualCollectionPreview . parentAlias ) . toBe ( testCollectionAlias )
804+ expect ( actualCollectionPreview . parentName ) . toBe ( expectedCollectionsName )
805+ expect ( actualCollectionPreview . publicationStatuses [ 0 ] ) . toBe ( PublicationStatus . Published )
806+ expect ( actualCollectionPreview . releaseOrCreateDate ) . not . toBeUndefined ( )
807+ expect ( actualCollectionPreview . affiliation ) . toBe ( 'Scientific Research University' )
808+ expect ( actualCollectionPreview . parentAlias ) . toBe ( 'collectionsRepositoryTestCollection' )
809+ expect ( actualCollectionPreview . parentName ) . toBe ( expectedCollectionsName )
810+ expect ( actualCollectionPreview . type ) . toBe ( CollectionItemType . COLLECTION )
811+
812+ expect ( actual . totalItemCount ) . toBe ( 3 )
813+ } )
814+ } )
815+
663816 describe ( 'updateCollection' , ( ) => {
664817 const testUpdatedCollectionAlias = 'updateCollection-test-updatedAlias'
665818
0 commit comments