Skip to content

Commit 87ea4ff

Browse files
committed
feat: add childCount property to Collection Model
1 parent f34ea3b commit 87ea4ff

File tree

9 files changed

+43
-7
lines changed

9 files changed

+43
-7
lines changed

src/collections/domain/models/Collection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface Collection {
1515
contacts?: CollectionContact[]
1616
isMetadataBlockRoot: boolean
1717
isFacetRoot: boolean
18+
childCount: number
1819
}
1920

2021
export interface CollectionInputLevel {

src/collections/infra/repositories/CollectionsRepository.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ export class CollectionsRepository extends ApiRepository implements ICollections
7070
collectionIdOrAlias: number | string = ROOT_COLLECTION_ID
7171
): Promise<Collection> {
7272
return this.doGet(`/${this.collectionsResourceName}/${collectionIdOrAlias}`, true, {
73-
returnOwners: true
73+
returnOwners: true,
74+
returnChildCount: true
7475
})
7576
.then((response) => transformCollectionResponseToCollection(response))
7677
.catch((error) => {

src/collections/infra/repositories/transformers/CollectionPayload.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface CollectionPayload {
1313
dataverseType: string
1414
isMetadataBlockRoot: boolean
1515
isFacetRoot: boolean
16+
childCount: number
1617
}
1718

1819
export interface CollectionInputLevelPayload {

src/collections/infra/repositories/transformers/collectionTransformers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col
5353
type: collectionPayload.dataverseType as CollectionType,
5454
isMetadataBlockRoot: collectionPayload.isMetadataBlockRoot,
5555
isFacetRoot: collectionPayload.isFacetRoot,
56+
childCount: collectionPayload.childCount,
5657
...(collectionPayload.description && {
5758
description: transformHtmlToMarkdown(collectionPayload.description)
5859
}),

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=11255-child-count-get-collection-ext
66
DATAVERSE_BOOTSTRAP_TIMEOUT=5m

test/integration/collections/CollectionsRepository.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,34 @@ describe('CollectionsRepository', () => {
128128
)
129129
})
130130
})
131+
132+
test('should return childCount correctly', async () => {
133+
const parentCollectionAlias = 'childCountTestCollection'
134+
const childCollectionAlias = 'childCountTestChildCollection'
135+
136+
await createCollectionViaApi(parentCollectionAlias, ROOT_COLLECTION_ALIAS)
137+
await createCollectionViaApi(childCollectionAlias, parentCollectionAlias)
138+
const { numericId: childDatasetNumericId } = await createDataset.execute(
139+
TestConstants.TEST_NEW_DATASET_DTO,
140+
parentCollectionAlias
141+
)
142+
143+
const actual = await sut.getCollection(parentCollectionAlias)
144+
145+
expect(actual.childCount).toBe(2)
146+
147+
await deleteCollectionViaApi(childCollectionAlias)
148+
149+
const actualAfterDeletion = await sut.getCollection(parentCollectionAlias)
150+
151+
expect(actualAfterDeletion.childCount).toBe(1)
152+
153+
await deleteUnpublishedDatasetViaApi(childDatasetNumericId)
154+
155+
const actualAfterDatasetDeletion = await sut.getCollection(parentCollectionAlias)
156+
157+
expect(actualAfterDatasetDeletion.childCount).toBe(0)
158+
})
131159
})
132160

133161
describe('publishCollection', () => {

test/testHelpers/collections/collectionHelper.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export const createCollectionModel = (): Collection => {
4747
}
4848
],
4949
isMetadataBlockRoot: true,
50-
isFacetRoot: true
50+
isFacetRoot: true,
51+
childCount: 0
5152
}
5253
return collectionModel
5354
}
@@ -76,7 +77,8 @@ export const createCollectionPayload = (): CollectionPayload => {
7677
}
7778
],
7879
isMetadataBlockRoot: true,
79-
isFacetRoot: true
80+
isFacetRoot: true,
81+
childCount: 0
8082
}
8183
return collectionPayload
8284
}

test/unit/auth/BearerTokenMechanism.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ describe('BearerTokenMechanism', () => {
4646
const expectedRequestConfigBearerToken = {
4747
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_BEARER_TOKEN.headers,
4848
params: {
49-
returnOwners: true
49+
returnOwners: true,
50+
returnChildCount: true
5051
}
5152
}
5253

test/unit/collections/CollectionsRepository.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ describe('CollectionsRepository', () => {
6666
describe('getCollection', () => {
6767
const expectedRequestConfigApiKey = {
6868
params: {
69-
returnOwners: true
69+
returnOwners: true,
70+
returnChildCount: true
7071
},
7172
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
7273
}

0 commit comments

Comments
 (0)