Skip to content

Commit 0d63f4b

Browse files
author
Matt Mangan
committed
changed Collection attributes and renamed collection identifier
1 parent c29ad95 commit 0d63f4b

File tree

7 files changed

+15
-25
lines changed

7 files changed

+15
-25
lines changed

docs/useCases.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import { getCollection } from '@iqss/dataverse-client-javascript'
6060

6161
/* ... */
6262
// Case 1: Fetch Collection by its numerical ID
63-
const collectionObjectParameter = 12345
63+
const collectionIdOrAlias = 12345
6464

6565
getCollection
6666
.execute(collectionId)
@@ -74,7 +74,7 @@ getCollection
7474
/* ... */
7575

7676
// Case 2: Fetch Collection by its alias
77-
const collectionObjectParameter = 'classicLiterature'
77+
const collectionIdOrAlias = 'classicLiterature'
7878
getCollection
7979
.execute(collectionAlias)
8080
.then((collection: Collection) => {
@@ -89,7 +89,7 @@ getCollection
8989

9090
_See [use case](../src/collections/domain/useCases/GetCollection.ts)_ definition.
9191

92-
The `collectionObjectParameter` is a generic collection identifier, which can be either a string (for queries by CollectionAlias), or a number (for queries by CollectionId).
92+
The `collectionIdOrAlias` is a generic collection identifier, which can be either a string (for queries by CollectionAlias), or a number (for queries by CollectionId).
9393

9494
If no collection identifier is specified, the default collection identifier; `root` will be used. If you want to search for a different collection, you must add the collection identifier as a parameter in the use case call.
9595

src/collections/domain/models/Collection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export interface Collection {
33
id: number
44
alias: string
55
name: string
6-
affiliation: string
7-
description: string
6+
affiliation?: string
7+
description?: string
88
isPartOf: DvObjectOwnerNode
99
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { Collection } from '../models/Collection'
22
export interface ICollectionsRepository {
3-
getCollection(collectionObjectParameter: number | string): Promise<Collection>
3+
getCollection(collectionIdOrAlias: number | string): Promise<Collection>
44
}

src/collections/domain/useCases/GetCollection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export class GetCollection implements UseCase<Collection> {
1212
/**
1313
* Returns a Collection instance, given the search parameters to identify it.
1414
*
15-
* @param {number | string} [collectionObjectParameter = 'root'] - A generic collection identifier, which can be either a string (for queries by CollectionAlias), or a number (for queries by CollectionId)
15+
* @param {number | string} [collectionIdOrAlias = 'root'] - A generic collection identifier, which can be either a string (for queries by CollectionAlias), or a number (for queries by CollectionId)
1616
* If this parameter is not set, the default value is: 'root'
1717
* @returns {Promise<Collection>}
1818
*/
19-
async execute(collectionObjectParameter: number | string = 'root'): Promise<Collection> {
20-
return await this.collectionsRepository.getCollection(collectionObjectParameter)
19+
async execute(collectionIdOrAlias: number | string = 'root'): Promise<Collection> {
20+
return await this.collectionsRepository.getCollection(collectionIdOrAlias)
2121
}
2222
}

src/collections/infra/repositories/CollectionsRepository.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ export class CollectionsRepository extends ApiRepository implements ICollections
66
private readonly collectionsResourceName: string = 'dataverses'
77
private readonly collectionsDefaultOperationType: string = 'get'
88

9-
public async getCollection(
10-
collectionObjectParameter: number | string = 'root'
11-
): Promise<Collection> {
9+
public async getCollection(collectionIdOrAlias: number | string = 'root'): Promise<Collection> {
1210
return this.doGet(
1311
this.buildApiEndpoint(
1412
this.collectionsResourceName,
1513
this.collectionsDefaultOperationType,
16-
collectionObjectParameter
14+
collectionIdOrAlias
1715
),
1816
true,
1917
{ returnOwners: true }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export interface CollectionPayload {
33
id: number
44
alias: string
55
name: string
6-
affiliation: string
7-
description: string
6+
affiliation?: string
7+
description?: string
88
isPartOf: OwnerNodePayload
99
}

test/unit/collections/CollectionsRepository.test.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,10 @@ describe('CollectionsRepository', () => {
4242
const expectedApiEndpoint = `${TestConstants.TEST_API_URL}/dataverses/${testCollectionModel.id}`
4343

4444
// API Key auth
45-
let actual = await sut.getCollection(testCollectionModel.id)
45+
const actual = await sut.getCollection(testCollectionModel.id)
4646

4747
expect(axios.get).toHaveBeenCalledWith(expectedApiEndpoint, expectedRequestConfigApiKey)
4848
expect(actual).toStrictEqual(testCollectionModel)
49-
50-
actual = await sut.getCollection(testCollectionModel.id)
51-
expect(axios.get).toHaveBeenCalledWith(expectedApiEndpoint, expectedRequestConfigApiKey)
52-
expect(actual).toStrictEqual(testCollectionModel)
5349
})
5450

5551
test('should return error on repository read error', async () => {
@@ -69,12 +65,8 @@ describe('CollectionsRepository', () => {
6965
const expectedApiEndpoint = `${TestConstants.TEST_API_URL}/dataverses/${testCollectionModel.alias}`
7066

7167
// API Key auth
72-
let actual = await sut.getCollection(testCollectionModel.alias)
73-
74-
expect(axios.get).toHaveBeenCalledWith(expectedApiEndpoint, expectedRequestConfigApiKey)
75-
expect(actual).toStrictEqual(testCollectionModel)
68+
const actual = await sut.getCollection(testCollectionModel.alias)
7669

77-
actual = await sut.getCollection(testCollectionModel.alias)
7870
expect(axios.get).toHaveBeenCalledWith(expectedApiEndpoint, expectedRequestConfigApiKey)
7971
expect(actual).toStrictEqual(testCollectionModel)
8072
})

0 commit comments

Comments
 (0)