-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from IQSS/156-create-collection-second-part
Extended create collection use case
- Loading branch information
Showing
14 changed files
with
341 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
import { ICollectionsRepository } from '../repositories/ICollectionsRepository' | ||
import { ROOT_COLLECTION_ALIAS } from '../models/Collection' | ||
|
||
export class GetCollectionFacets implements UseCase<string[]> { | ||
private collectionsRepository: ICollectionsRepository | ||
|
||
constructor(collectionsRepository: ICollectionsRepository) { | ||
this.collectionsRepository = collectionsRepository | ||
} | ||
|
||
/** | ||
* Returns the names of the configured collection facets, given a collection identifier or alias. | ||
* | ||
* @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) | ||
* If this parameter is not set, the default value is: 'root' | ||
* @returns {Promise<string[]>} | ||
*/ | ||
async execute(collectionIdOrAlias: number | string = ROOT_COLLECTION_ALIAS): Promise<string[]> { | ||
return await this.collectionsRepository.getCollectionFacets(collectionIdOrAlias) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import { CreateCollection } from './domain/useCases/CreateCollection' | ||
import { GetCollection } from './domain/useCases/GetCollection' | ||
import { GetCollectionFacets } from './domain/useCases/GetCollectionFacets' | ||
|
||
import { CollectionsRepository } from './infra/repositories/CollectionsRepository' | ||
|
||
const collectionsRepository = new CollectionsRepository() | ||
|
||
const getCollection = new GetCollection(collectionsRepository) | ||
const createCollection = new CreateCollection(collectionsRepository) | ||
const getCollectionFacets = new GetCollectionFacets(collectionsRepository) | ||
|
||
export { getCollection, createCollection } | ||
export { Collection } from './domain/models/Collection' | ||
export { CollectionDTO } from './domain/dtos/CollectionDTO' | ||
export { getCollection, createCollection, getCollectionFacets } | ||
export { Collection, CollectionInputLevel } from './domain/models/Collection' | ||
export { CollectionDTO, CollectionInputLevelDTO } from './domain/dtos/CollectionDTO' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ApiConfig, ReadError, getCollectionFacets } from '../../../src' | ||
import { TestConstants } from '../../testHelpers/TestConstants' | ||
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' | ||
import { ROOT_COLLECTION_ALIAS } from '../../../src/collections/domain/models/Collection' | ||
|
||
describe('execute', () => { | ||
beforeEach(async () => { | ||
ApiConfig.init( | ||
TestConstants.TEST_API_URL, | ||
DataverseApiAuthMechanism.API_KEY, | ||
process.env.TEST_API_KEY | ||
) | ||
}) | ||
|
||
test('should return facets when a valid collection alias is provided', async () => { | ||
let actual: string[] = [] | ||
try { | ||
actual = await getCollectionFacets.execute(ROOT_COLLECTION_ALIAS) | ||
} catch (error) { | ||
throw new Error('Facets should be retrieved') | ||
} finally { | ||
expect(actual).toContain('authorName') | ||
expect(actual).toContain('subject') | ||
expect(actual).toContain('keywordValue') | ||
expect(actual).toContain('dateOfDeposit') | ||
} | ||
}) | ||
|
||
test('should throw an error when collection does not exist', async () => { | ||
expect.assertions(2) | ||
let readError: ReadError | ||
try { | ||
await getCollectionFacets.execute(TestConstants.TEST_DUMMY_COLLECTION_ID) | ||
throw new Error('Use case should throw an error') | ||
} catch (error) { | ||
readError = error | ||
} finally { | ||
expect(readError).toBeInstanceOf(ReadError) | ||
expect(readError.message).toEqual( | ||
`There was an error when reading the resource. Reason was: [404] Can't find dataverse with identifier='${TestConstants.TEST_DUMMY_COLLECTION_ID}'` | ||
) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.