-
Notifications
You must be signed in to change notification settings - Fork 11
Use Case for Getting Available Dataset Types #366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
5cad35d
e4f09f9
a49c004
bf9c617
aaf41cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export interface DatasetType { | ||
| id: number | ||
| name: string | ||
| linkedMetadataBlocks?: string[] | ||
|
ChengShi-1 marked this conversation as resolved.
|
||
| availableLicenses?: string[] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { DatasetType } from '../models/DatasetType' | ||
| import { IDatasetsRepository } from '../repositories/IDatasetsRepository' | ||
|
|
||
| export class GetDatasetAvailableDatasetTypes implements UseCase<DatasetType[]> { | ||
| private datasetsRepository: IDatasetsRepository | ||
|
|
||
| constructor(datasetsRepository: IDatasetsRepository) { | ||
| this.datasetsRepository = datasetsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Returns the list of available dataset types that can be selected when creating a dataset. | ||
| * | ||
| * @returns {Promise<DatasetType[]>} | ||
| */ | ||
| async execute(): Promise<DatasetType[]> { | ||
| return await this.datasetsRepository.getDatasetAvailableDatasetTypes() | ||
| } | ||
| } |
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made this a functional test but I'd be happy to switch it to an integration test if that's more appropriate. I'm confused about which to use. They seem quite similar, both spinning up Docker containers. On my machine functional is faster, clocking in at around 20 seconds while integration takes almost 50 seconds.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good to keep a functional test here! Could you also add to integration test as well to test/integration/datasets/DatasetsRepository.test.ts?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ChengShi-1 I know in person I said I'd delete the functional test and add an integration test, but after looking at the code I decided to keep the functional test and add an integration test, which I did in a49c004. My reasoning was that I like how easy it is to run just the one test I added like this (because it's in its own file):
On the integration side, tests are all in one file (DatasetsRepository.test.ts). After adding a test, I tried to run just that test like this...
... but it didn't work. All tests in that file ran. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { ApiConfig, DatasetType, getDatasetAvailableDatasetTypes } from '../../../src' | ||
| import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' | ||
| import { TestConstants } from '../../testHelpers/TestConstants' | ||
|
|
||
| describe('getDatasetAvailableDatasetTypes', () => { | ||
| describe('execute', () => { | ||
| beforeAll(async () => { | ||
| ApiConfig.init( | ||
| TestConstants.TEST_API_URL, | ||
| DataverseApiAuthMechanism.API_KEY, | ||
| process.env.TEST_API_KEY | ||
| ) | ||
| }) | ||
|
|
||
| test('should return available dataset types', async () => { | ||
| const actualDatasetTypes: DatasetType[] = await getDatasetAvailableDatasetTypes.execute() | ||
| const expectedDatasetTypes = [ | ||
| { | ||
| id: 1, | ||
| name: 'dataset', | ||
| linkedMetadataBlocks: [], | ||
| availableLicenses: [] | ||
| } | ||
| ] | ||
|
|
||
| expect(actualDatasetTypes).toEqual(expectedDatasetTypes) | ||
| }) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { ReadError } from '../../../src' | ||
| import { DatasetType } from '../../../src' | ||
| import { IDatasetsRepository } from '../../../src/datasets/domain/repositories/IDatasetsRepository' | ||
| import { GetDatasetAvailableDatasetTypes } from '../../../src/datasets/domain/useCases/GetDatasetAvailableDatasetTypes' | ||
|
|
||
| describe('GetDatasetAvailableDatasetTypes', () => { | ||
| describe('execute', () => { | ||
| test('should return datasetTypes array on repository success', async () => { | ||
| const datasetTypesRepositoryStub: IDatasetsRepository = {} as IDatasetsRepository | ||
|
|
||
| const testDatasetTypes: DatasetType[] = [ | ||
| { | ||
| id: 1, | ||
| name: 'dataset', | ||
| linkedMetadataBlocks: [], | ||
| availableLicenses: [] | ||
| }, | ||
| { | ||
| id: 2, | ||
| name: 'software', | ||
| linkedMetadataBlocks: ['codeMeta20'], | ||
| availableLicenses: ['MIT', 'Apache-2.0'] | ||
| } | ||
| ] | ||
|
|
||
| datasetTypesRepositoryStub.getDatasetAvailableDatasetTypes = jest | ||
| .fn() | ||
| .mockResolvedValue(testDatasetTypes) | ||
| const sut = new GetDatasetAvailableDatasetTypes(datasetTypesRepositoryStub) | ||
|
|
||
| const actual = await sut.execute() | ||
|
|
||
| expect(actual).toEqual(testDatasetTypes) | ||
| expect(datasetTypesRepositoryStub.getDatasetAvailableDatasetTypes).toHaveBeenCalledTimes(1) | ||
| }) | ||
|
|
||
| test('should return error result on repository error', async () => { | ||
| const datasetsRepositoryStub: IDatasetsRepository = {} as IDatasetsRepository | ||
| const expectedError = new ReadError('Failed to fetch dataset types') | ||
| datasetsRepositoryStub.getDatasetAvailableDatasetTypes = jest | ||
| .fn() | ||
| .mockRejectedValue(expectedError) | ||
| const sut = new GetDatasetAvailableDatasetTypes(datasetsRepositoryStub) | ||
|
|
||
| await expect(sut.execute()).rejects.toThrow(ReadError) | ||
| expect(datasetsRepositoryStub.getDatasetAvailableDatasetTypes).toHaveBeenCalledTimes(1) | ||
| }) | ||
| }) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why there is a categories (404 copy-paste error ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! Yes, this was a copy/paste error. Fixed in e4f09f9.