-
Notifications
You must be signed in to change notification settings - Fork 10
Get Citation In Other Format Use Case #340
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b9604c6
feat: update get citation in other format
ChengShi-1 b107eda
Merge branch 'develop' into Citation-in-other-format
ChengShi-1 7678460
fix: update the response format
ChengShi-1 5e59c9f
Merge branch 'develop' into Citation-in-other-format
ChengShi-1 997a4fb
Revert "fix RolesRepository integration test"
ChengShi-1 a3abce0
fix: test
ChengShi-1 e9c4f98
fix: change the names and stringify json object
ChengShi-1 3f01e90
fix: update to dataset index.tx
ChengShi-1 a957946
fix: update datasetID to allow persistent id
ChengShi-1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,7 @@ | ||
| export enum CitationFormat { | ||
| Internal = 'Internal', | ||
| EndNote = 'EndNote', | ||
| RIS = 'RIS', | ||
| BibTeX = 'BibTeX', | ||
| CSLJson = 'CSL' | ||
| } |
This file contains hidden or 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,4 @@ | ||
| export type FormattedCitation = { | ||
| content: string | ||
| contentType: string | ||
| } |
This file contains hidden or 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
36 changes: 36 additions & 0 deletions
36
src/datasets/domain/useCases/GetDatasetCitationInOtherFormats.ts
This file contains hidden or 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,36 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { IDatasetsRepository } from '../repositories/IDatasetsRepository' | ||
| import { DatasetNotNumberedVersion } from '../models/DatasetNotNumberedVersion' | ||
| import { FormattedCitation } from '../models/FormattedCitation' | ||
| import { CitationFormat } from '../models/CitationFormat' | ||
|
|
||
| export class GetDatasetCitationInOtherFormats implements UseCase<FormattedCitation> { | ||
| private datasetsRepository: IDatasetsRepository | ||
|
|
||
| constructor(datasetsRepository: IDatasetsRepository) { | ||
| this.datasetsRepository = datasetsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Returns the dataset citation in the specified format. | ||
| * | ||
| * @param {number | string} datasetId - The dataset identifier. | ||
| * @param {string | DatasetNotNumberedVersion} [datasetVersionId=DatasetNotNumberedVersion.LATEST] - The dataset version identifier, which can be a version-specific string (e.g., '1.0') or a DatasetNotNumberedVersion enum value. Defaults to LATEST. | ||
| * @param {CitationFormat} format - The citation format to return. One of: 'EndNote', 'RIS', 'BibTeX', 'CSLJson', 'Internal'. | ||
| * @param {boolean} [includeDeaccessioned=false] - Whether to include deaccessioned versions in the search. Defaults to false. | ||
| * @returns {Promise<FormattedCitation>} The citation content, format, and content type. | ||
| */ | ||
| async execute( | ||
| datasetId: number | string, | ||
| datasetVersionId: string | DatasetNotNumberedVersion = DatasetNotNumberedVersion.LATEST, | ||
| format: CitationFormat, | ||
| includeDeaccessioned = false | ||
| ): Promise<FormattedCitation> { | ||
| return await this.datasetsRepository.getDatasetCitationInOtherFormats( | ||
| datasetId, | ||
| datasetVersionId, | ||
| format, | ||
| includeDeaccessioned | ||
| ) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
38 changes: 38 additions & 0 deletions
38
test/unit/datasets/GetDatasetCitationInOtherFormats.test.ts
This file contains hidden or 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,38 @@ | ||
| import { GetDatasetCitationInOtherFormats } from '../../../src/datasets/domain/useCases/GetDatasetCitationInOtherFormats' | ||
| import { IDatasetsRepository } from '../../../src/datasets/domain/repositories/IDatasetsRepository' | ||
| import { ReadError } from '../../../src/core/domain/repositories/ReadError' | ||
| import { CitationFormat } from '../../../src/datasets/domain/models/CitationFormat' | ||
| import { DatasetNotNumberedVersion } from '../../../src/datasets/domain/models/DatasetNotNumberedVersion' | ||
| import { FormattedCitation } from '../../../src/datasets/domain/models/FormattedCitation' | ||
|
|
||
| describe('GetDatasetCitationInOtherFormats.execute', () => { | ||
| const testDatasetId = 1 | ||
| const testFormat: CitationFormat = CitationFormat.BibTeX | ||
| const testVersion: DatasetNotNumberedVersion = DatasetNotNumberedVersion.LATEST | ||
|
|
||
| test('should return citation response on repository success', async () => { | ||
| const expectedCitation: FormattedCitation = { | ||
| content: '@data{example, ...}', | ||
| contentType: 'text/plain' | ||
| } | ||
|
|
||
| const datasetsRepositoryStub: IDatasetsRepository = { | ||
| getDatasetCitationInOtherFormats: jest.fn().mockResolvedValue(expectedCitation) | ||
| } as unknown as IDatasetsRepository | ||
|
|
||
| const sut = new GetDatasetCitationInOtherFormats(datasetsRepositoryStub) | ||
|
|
||
| const actual = await sut.execute(testDatasetId, testVersion, testFormat as CitationFormat) | ||
| expect(actual).toEqual(expectedCitation) | ||
| }) | ||
|
|
||
| test('should throw ReadError on repository failure', async () => { | ||
| const datasetsRepositoryStub: IDatasetsRepository = { | ||
| getDatasetCitationInOtherFormats: jest.fn().mockRejectedValue(new ReadError()) | ||
| } as unknown as IDatasetsRepository | ||
|
|
||
| const sut = new GetDatasetCitationInOtherFormats(datasetsRepositoryStub) | ||
|
|
||
| await expect(sut.execute(testDatasetId, testVersion, testFormat)).rejects.toThrow(ReadError) | ||
| }) | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.