@@ -2,6 +2,7 @@ import { CollectionsRepository } from '../../../src/collections/infra/repositori
22import { TestConstants } from '../../testHelpers/TestConstants'
33import {
44 CollectionPreview ,
5+ CollectionSearchCriteria ,
56 CreatedDatasetIdentifiers ,
67 DatasetPreview ,
78 FilePreview ,
@@ -265,26 +266,28 @@ describe('CollectionsRepository', () => {
265266 const expectedFileMd5 = '68b22040025784da775f55cfcb6dee2e'
266267 const expectedDatasetCitationFragment =
267268 'Admin, Dataverse; Owner, Dataverse, 2024, "Dataset created using the createDataset use case'
269+ const expectedDatasetDescription = 'Dataset created using the createDataset use case'
270+ const expectedFileName = 'test-file-1.txt'
268271
269272 expect ( actualFilePreview . checksum ?. type ) . toBe ( 'MD5' )
270273 expect ( actualFilePreview . checksum ?. value ) . toBe ( expectedFileMd5 )
271274 expect ( actualFilePreview . datasetCitation ) . toContain ( expectedDatasetCitationFragment )
272275 expect ( actualFilePreview . datasetId ) . toBe ( testDatasetIds . numericId )
273- expect ( actualFilePreview . datasetName ) . toBe ( 'Dataset created using the createDataset use case' )
276+ expect ( actualFilePreview . datasetName ) . toBe ( expectedDatasetDescription )
274277 expect ( actualFilePreview . datasetPersistentId ) . toBe ( testDatasetIds . persistentId )
275278 expect ( actualFilePreview . description ) . toBe ( '' )
276279 expect ( actualFilePreview . fileContentType ) . toBe ( 'text/plain' )
277280 expect ( actualFilePreview . fileId ) . not . toBeUndefined ( )
278281 expect ( actualFilePreview . fileType ) . toBe ( 'Plain Text' )
279282 expect ( actualFilePreview . md5 ) . toBe ( expectedFileMd5 )
280- expect ( actualFilePreview . name ) . toBe ( 'test-file-1.txt' )
283+ expect ( actualFilePreview . name ) . toBe ( expectedFileName )
281284 expect ( actualFilePreview . publicationStatuses [ 0 ] ) . toBe ( PublicationStatus . Unpublished )
282285 expect ( actualFilePreview . publicationStatuses [ 1 ] ) . toBe ( PublicationStatus . Draft )
283286 expect ( actualFilePreview . sizeInBytes ) . toBe ( 12 )
284287 expect ( actualFilePreview . url ) . not . toBeUndefined ( )
285288 expect ( actualFilePreview . releaseOrCreateDate ) . not . toBeUndefined ( )
286289
287- expect ( actualDatasetPreview . title ) . toBe ( 'Dataset created using the createDataset use case' )
290+ expect ( actualDatasetPreview . title ) . toBe ( expectedDatasetDescription )
288291 expect ( actualDatasetPreview . citation ) . toContain ( expectedDatasetCitationFragment )
289292 expect ( actualDatasetPreview . description ) . toBe ( 'This is the description of the dataset.' )
290293 expect ( actualDatasetPreview . persistentId ) . not . toBeUndefined ( )
@@ -314,7 +317,56 @@ describe('CollectionsRepository', () => {
314317 // Test limit and offset
315318 actual = await sut . getCollectionItems ( testCollectionAlias , 1 , 1 )
316319 expect ( ( actual . items [ 0 ] as DatasetPreview ) . persistentId ) . toBe ( testDatasetIds . persistentId )
320+ expect ( actual . items . length ) . toBe ( 1 )
317321 expect ( actual . totalItemCount ) . toBe ( 3 )
322+
323+ // Test search text
324+ const collectionSearchCriteriaForFile = new CollectionSearchCriteria ( ) . withSearchText (
325+ 'test-fi'
326+ )
327+ actual = await sut . getCollectionItems (
328+ testCollectionAlias ,
329+ undefined ,
330+ undefined ,
331+ collectionSearchCriteriaForFile
332+ )
333+ expect ( actual . totalItemCount ) . toBe ( 1 )
334+ expect ( ( actual . items [ 0 ] as FilePreview ) . name ) . toBe ( expectedFileName )
335+
336+ const collectionSearchCriteriaForDataset = new CollectionSearchCriteria ( ) . withSearchText (
337+ 'This is the description'
338+ )
339+ actual = await sut . getCollectionItems (
340+ testCollectionAlias ,
341+ undefined ,
342+ undefined ,
343+ collectionSearchCriteriaForDataset
344+ )
345+ expect ( actual . totalItemCount ) . toBe ( 1 )
346+ expect ( ( actual . items [ 0 ] as DatasetPreview ) . title ) . toBe ( expectedDatasetDescription )
347+
348+ const collectionSearchCriteriaForDatasetAndCollection =
349+ new CollectionSearchCriteria ( ) . withSearchText ( 'the' )
350+ actual = await sut . getCollectionItems (
351+ testCollectionAlias ,
352+ undefined ,
353+ undefined ,
354+ collectionSearchCriteriaForDatasetAndCollection
355+ )
356+ expect ( actual . totalItemCount ) . toBe ( 2 )
357+ expect ( ( actual . items [ 0 ] as DatasetPreview ) . title ) . toBe ( expectedDatasetDescription )
358+ expect ( ( actual . items [ 1 ] as CollectionPreview ) . name ) . toBe ( expectedCollectionsName )
359+
360+ // Test search text, limit and offset
361+ actual = await sut . getCollectionItems (
362+ testCollectionAlias ,
363+ 1 ,
364+ 1 ,
365+ collectionSearchCriteriaForDatasetAndCollection
366+ )
367+ expect ( actual . items . length ) . toBe ( 1 )
368+ expect ( actual . totalItemCount ) . toBe ( 2 )
369+ expect ( ( actual . items [ 0 ] as CollectionPreview ) . name ) . toBe ( expectedCollectionsName )
318370 } )
319371
320372 test ( 'should return error when collection does not exist' , async ( ) => {
0 commit comments