Skip to content

Commit 6059618

Browse files
committed
test: add integration and unit cases
1 parent 77b9d26 commit 6059618

File tree

4 files changed

+76
-7
lines changed

4 files changed

+76
-7
lines changed

test/environment/.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
POSTGRES_VERSION=13
22
DATAVERSE_DB_USER=dataverse
33
SOLR_VERSION=9.3.0
4-
DATAVERSE_IMAGE_REGISTRY=docker.io
5-
DATAVERSE_IMAGE_TAG=unstable
4+
DATAVERSE_IMAGE_REGISTRY=ghcr.io
5+
DATAVERSE_IMAGE_TAG=11127-search-api-counts
66
DATAVERSE_BOOTSTRAP_TIMEOUT=5m

test/integration/collections/CollectionsRepository.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ describe('CollectionsRepository', () => {
417417
expect(actualCollectionPreview.type).toBe(CollectionItemType.COLLECTION)
418418

419419
expect(actual.totalItemCount).toBe(3)
420+
expect(actual.countPerObjectType.dataverses).toBe(1)
421+
expect(actual.countPerObjectType.datasets).toBe(1)
422+
expect(actual.countPerObjectType.files).toBe(1)
420423

421424
expect(actual.facets).toEqual(expectedFacetsAll)
422425

@@ -438,6 +441,9 @@ describe('CollectionsRepository', () => {
438441
)
439442
expect(actual.totalItemCount).toBe(1)
440443
expect((actual.items[0] as FilePreview).name).toBe(expectedFileName)
444+
expect(actual.countPerObjectType.dataverses).toBe(0)
445+
expect(actual.countPerObjectType.datasets).toBe(0)
446+
expect(actual.countPerObjectType.files).toBe(1)
441447

442448
const collectionSearchCriteriaForDataset = new CollectionSearchCriteria().withSearchText(
443449
'This is the description'
@@ -450,6 +456,9 @@ describe('CollectionsRepository', () => {
450456
)
451457
expect(actual.totalItemCount).toBe(1)
452458
expect((actual.items[0] as DatasetPreview).title).toBe(expectedDatasetDescription)
459+
expect(actual.countPerObjectType.dataverses).toBe(0)
460+
expect(actual.countPerObjectType.datasets).toBe(1)
461+
expect(actual.countPerObjectType.files).toBe(0)
453462

454463
const collectionSearchCriteriaForDatasetAndCollection =
455464
new CollectionSearchCriteria().withSearchText('the')
@@ -462,6 +471,9 @@ describe('CollectionsRepository', () => {
462471
expect(actual.totalItemCount).toBe(2)
463472
expect((actual.items[0] as DatasetPreview).title).toBe(expectedDatasetDescription)
464473
expect((actual.items[1] as CollectionPreview).name).toBe(expectedCollectionsName)
474+
expect(actual.countPerObjectType.dataverses).toBe(1)
475+
expect(actual.countPerObjectType.datasets).toBe(1)
476+
expect(actual.countPerObjectType.files).toBe(0)
465477

466478
// Test search text, limit and offset
467479
actual = await sut.getCollectionItems(
@@ -473,6 +485,9 @@ describe('CollectionsRepository', () => {
473485
expect(actual.items.length).toBe(1)
474486
expect(actual.totalItemCount).toBe(2)
475487
expect((actual.items[0] as CollectionPreview).name).toBe(expectedCollectionsName)
488+
expect(actual.countPerObjectType.dataverses).toBe(1)
489+
expect(actual.countPerObjectType.datasets).toBe(1)
490+
expect(actual.countPerObjectType.files).toBe(0)
476491

477492
// Test type collection
478493
const collectionSearchCriteriaForCollectionType =
@@ -487,6 +502,9 @@ describe('CollectionsRepository', () => {
487502
expect(actual.totalItemCount).toBe(1)
488503
expect((actual.items[0] as CollectionPreview).name).toBe(expectedCollectionsName)
489504
expect(actual.facets).toEqual(expectedFacetsFromCollectionOnly)
505+
expect(actual.countPerObjectType.dataverses).toBe(1)
506+
expect(actual.countPerObjectType.datasets).toBe(0)
507+
expect(actual.countPerObjectType.files).toBe(0)
490508

491509
// Test type dataset
492510
const collectionSearchCriteriaForDatasetType = new CollectionSearchCriteria().withItemTypes([
@@ -502,6 +520,9 @@ describe('CollectionsRepository', () => {
502520
expect(actual.totalItemCount).toBe(1)
503521
expect((actual.items[0] as DatasetPreview).title).toBe(expectedDatasetDescription)
504522
expect(actual.facets).toEqual(expectedFacetsFromDatasetOnly)
523+
expect(actual.countPerObjectType.dataverses).toBe(0)
524+
expect(actual.countPerObjectType.datasets).toBe(1)
525+
expect(actual.countPerObjectType.files).toBe(0)
505526

506527
// Test type file
507528
const collectionSearchCriteriaForFileType = new CollectionSearchCriteria().withItemTypes([
@@ -517,6 +538,9 @@ describe('CollectionsRepository', () => {
517538
expect(actual.totalItemCount).toBe(1)
518539
expect((actual.items[0] as FilePreview).name).toBe(expectedFileName)
519540
expect(actual.facets).toEqual(expectedFacetsFromFileOnly)
541+
expect(actual.countPerObjectType.dataverses).toBe(0)
542+
expect(actual.countPerObjectType.datasets).toBe(0)
543+
expect(actual.countPerObjectType.files).toBe(1)
520544

521545
// Test multiple types
522546
const collectionSearchCriteriaForMultiTypes = new CollectionSearchCriteria().withItemTypes([
@@ -534,6 +558,9 @@ describe('CollectionsRepository', () => {
534558
expect((actual.items[0] as FilePreview).name).toBe(expectedFileName)
535559
expect((actual.items[1] as CollectionPreview).name).toBe(expectedCollectionsName)
536560
expect(actual.facets).toEqual(expectedFacetsFromCollectionAndFile)
561+
expect(actual.countPerObjectType.dataverses).toBe(1)
562+
expect(actual.countPerObjectType.datasets).toBe(0)
563+
expect(actual.countPerObjectType.files).toBe(1)
537564

538565
// Test Sort by name ascending
539566
const collectionSearchCriteriaNameAscending = new CollectionSearchCriteria()
@@ -551,6 +578,9 @@ describe('CollectionsRepository', () => {
551578
expect((actual.items[0] as DatasetPreview).type).toBe(CollectionItemType.DATASET)
552579
expect((actual.items[1] as CollectionPreview).type).toBe(CollectionItemType.COLLECTION)
553580
expect((actual.items[2] as FilePreview).type).toBe(CollectionItemType.FILE)
581+
expect(actual.countPerObjectType.dataverses).toBe(1)
582+
expect(actual.countPerObjectType.datasets).toBe(1)
583+
expect(actual.countPerObjectType.files).toBe(1)
554584

555585
// Test Sort by name descending
556586
const collectionSearchCriteriaNameDescending = new CollectionSearchCriteria()
@@ -568,6 +598,9 @@ describe('CollectionsRepository', () => {
568598
expect((actual.items[0] as FilePreview).type).toBe(CollectionItemType.FILE)
569599
expect((actual.items[1] as CollectionPreview).type).toBe(CollectionItemType.COLLECTION)
570600
expect((actual.items[2] as DatasetPreview).type).toBe(CollectionItemType.DATASET)
601+
expect(actual.countPerObjectType.dataverses).toBe(1)
602+
expect(actual.countPerObjectType.datasets).toBe(1)
603+
expect(actual.countPerObjectType.files).toBe(1)
571604

572605
// Test Sort by date ascending
573606
const collectionSearchCriteriaDateAscending = new CollectionSearchCriteria()
@@ -585,6 +618,9 @@ describe('CollectionsRepository', () => {
585618
expect((actual.items[0] as CollectionPreview).type).toBe(CollectionItemType.COLLECTION)
586619
expect((actual.items[1] as DatasetPreview).type).toBe(CollectionItemType.DATASET)
587620
expect((actual.items[2] as FilePreview).type).toBe(CollectionItemType.FILE)
621+
expect(actual.countPerObjectType.dataverses).toBe(1)
622+
expect(actual.countPerObjectType.datasets).toBe(1)
623+
expect(actual.countPerObjectType.files).toBe(1)
588624

589625
// Test Sort by date descending
590626
const collectionSearchCriteriaDateDescending = new CollectionSearchCriteria()
@@ -602,6 +638,9 @@ describe('CollectionsRepository', () => {
602638
expect((actual.items[0] as FilePreview).type).toBe(CollectionItemType.FILE)
603639
expect((actual.items[1] as DatasetPreview).type).toBe(CollectionItemType.DATASET)
604640
expect((actual.items[2] as CollectionPreview).type).toBe(CollectionItemType.COLLECTION)
641+
expect(actual.countPerObjectType.dataverses).toBe(1)
642+
expect(actual.countPerObjectType.datasets).toBe(1)
643+
expect(actual.countPerObjectType.files).toBe(1)
605644

606645
// Test with Filter query related to the collection
607646
const collectionSearchCriteriaFilterQueryCollection =
@@ -617,6 +656,9 @@ describe('CollectionsRepository', () => {
617656
expect(actual.totalItemCount).toBe(1)
618657
expect((actual.items[0] as CollectionPreview).name).toBe(expectedCollectionsName)
619658
expect(actual.facets).toEqual(expectedFacetsFromCollectionOnly)
659+
expect(actual.countPerObjectType.dataverses).toBe(1)
660+
expect(actual.countPerObjectType.datasets).toBe(0)
661+
expect(actual.countPerObjectType.files).toBe(0)
620662

621663
// Test with Filter query related to the dataset
622664
const collectionSearchCriteriaFilterQueryDataset =
@@ -634,6 +676,9 @@ describe('CollectionsRepository', () => {
634676
expect(actual.totalItemCount).toBe(1)
635677
expect((actual.items[0] as DatasetPreview).title).toBe(expectedDatasetDescription)
636678
expect(actual.facets).toEqual(expectedFacetsFromDatasetOnly)
679+
expect(actual.countPerObjectType.dataverses).toBe(0)
680+
expect(actual.countPerObjectType.datasets).toBe(1)
681+
expect(actual.countPerObjectType.files).toBe(0)
637682

638683
// Test with Filter query related to the file
639684
const collectionSearchCriteriaFilterQuerieCollAndFile =
@@ -650,6 +695,9 @@ describe('CollectionsRepository', () => {
650695
expect(actual.totalItemCount).toBe(1)
651696
expect((actual.items[0] as FilePreview).name).toBe(expectedFileName)
652697
expect(actual.facets).toEqual(expectedFacetsFromFileOnly)
698+
expect(actual.countPerObjectType.dataverses).toBe(0)
699+
expect(actual.countPerObjectType.datasets).toBe(0)
700+
expect(actual.countPerObjectType.files).toBe(1)
653701
})
654702

655703
test('should return error when collection does not exist', async () => {

test/unit/collections/CollectionsRepository.test.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,17 @@ describe('CollectionsRepository', () => {
373373
]
374374
const testTotalCount = 2
375375
const testFacets = createCollectionItemsFacetsModel()
376+
const testCountPerObjectType = {
377+
dataverses: 0,
378+
datasets: 1,
379+
files: 1
380+
}
376381

377382
const testItemSubset: CollectionItemSubset = {
378383
items: testItems,
379384
facets: testFacets,
380-
totalItemCount: testTotalCount
385+
totalItemCount: testTotalCount,
386+
countPerObjectType: testCountPerObjectType
381387
}
382388

383389
const testItemPreviewsResponse = {
@@ -390,7 +396,12 @@ describe('CollectionsRepository', () => {
390396
createFilePreviewPayload(),
391397
createCollectionPreviewPayload()
392398
],
393-
facets: createCollectionItemsFacetsPayload()
399+
facets: createCollectionItemsFacetsPayload(),
400+
total_count_per_object_type: {
401+
Dataverses: 0,
402+
Datasets: 1,
403+
Files: 1
404+
}
394405
}
395406
}
396407
}
@@ -407,7 +418,8 @@ describe('CollectionsRepository', () => {
407418
[GetCollectionItemsQueryParams.QUERY]: '*',
408419
[GetCollectionItemsQueryParams.SHOW_FACETS]: 'true',
409420
[GetCollectionItemsQueryParams.SORT]: SortType.DATE,
410-
[GetCollectionItemsQueryParams.ORDER]: OrderType.DESC
421+
[GetCollectionItemsQueryParams.ORDER]: OrderType.DESC,
422+
[GetCollectionItemsQueryParams.SHOW_TYPE_COUNTS]: 'true'
411423
})
412424

413425
const expectedRequestConfigApiKey = {
@@ -452,6 +464,7 @@ describe('CollectionsRepository', () => {
452464
[GetCollectionItemsQueryParams.SHOW_FACETS]: 'true',
453465
[GetCollectionItemsQueryParams.SORT]: SortType.DATE,
454466
[GetCollectionItemsQueryParams.ORDER]: OrderType.DESC,
467+
[GetCollectionItemsQueryParams.SHOW_TYPE_COUNTS]: 'true',
455468
[GetCollectionItemsQueryParams.PER_PAGE]: testLimit.toString(),
456469
[GetCollectionItemsQueryParams.START]: testOffset.toString()
457470
})
@@ -499,6 +512,7 @@ describe('CollectionsRepository', () => {
499512
[GetCollectionItemsQueryParams.SHOW_FACETS]: 'true',
500513
[GetCollectionItemsQueryParams.SORT]: SortType.DATE,
501514
[GetCollectionItemsQueryParams.ORDER]: OrderType.DESC,
515+
[GetCollectionItemsQueryParams.SHOW_TYPE_COUNTS]: 'true',
502516
[GetCollectionItemsQueryParams.SUBTREE]: testCollectionId
503517
})
504518

@@ -542,7 +556,8 @@ describe('CollectionsRepository', () => {
542556
[GetCollectionItemsQueryParams.QUERY]: '*',
543557
[GetCollectionItemsQueryParams.SHOW_FACETS]: 'true',
544558
[GetCollectionItemsQueryParams.SORT]: SortType.DATE,
545-
[GetCollectionItemsQueryParams.ORDER]: OrderType.DESC
559+
[GetCollectionItemsQueryParams.ORDER]: OrderType.DESC,
560+
[GetCollectionItemsQueryParams.SHOW_TYPE_COUNTS]: 'true'
546561
})
547562

548563
const expectedRequestConfigApiKey = {

test/unit/collections/GetCollectionItems.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ describe('execute', () => {
1818
]
1919
const testTotalCount = 3
2020
const testFacets = createCollectionItemsFacetsModel()
21+
const testCountPerObjectType = {
22+
dataverses: 1,
23+
datasets: 1,
24+
files: 1
25+
}
2126

2227
const testItemSubset: CollectionItemSubset = {
2328
items: testItems,
2429
facets: testFacets,
25-
totalItemCount: testTotalCount
30+
totalItemCount: testTotalCount,
31+
countPerObjectType: testCountPerObjectType
2632
}
2733

2834
beforeEach(() => {

0 commit comments

Comments
 (0)