-
Notifications
You must be signed in to change notification settings - Fork 11
Export Metadata Use Case #463
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 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 ExportedDatasetMetadata = { | ||
| 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
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,28 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { DatasetNotNumberedVersion } from '../models/DatasetNotNumberedVersion' | ||
| import { ExportedDatasetMetadata } from '../models/ExportedDatasetMetadata' | ||
| import { IDatasetsRepository } from '../repositories/IDatasetsRepository' | ||
|
|
||
| export class ExportDatasetMetadata implements UseCase<ExportedDatasetMetadata> { | ||
| private datasetsRepository: IDatasetsRepository | ||
|
|
||
| constructor(datasetsRepository: IDatasetsRepository) { | ||
| this.datasetsRepository = datasetsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Exports dataset metadata in the specified metadata export format. | ||
| * | ||
| * @param {number | string} datasetId - The dataset identifier, which can be a string for persistent identifiers or a number for numeric identifiers. | ||
| * @param {string} exporter - The metadata exporter format name. | ||
| * @param {DatasetNotNumberedVersion.LATEST_PUBLISHED | DatasetNotNumberedVersion.DRAFT} [version] - The dataset version to export. If omitted, Dataverse defaults to :latest-published. | ||
| * @returns {Promise<ExportedDatasetMetadata>} The exported metadata content and content type. | ||
| */ | ||
| async execute( | ||
| datasetId: number | string, | ||
| exporter: string, | ||
| version?: DatasetNotNumberedVersion.LATEST_PUBLISHED | DatasetNotNumberedVersion.DRAFT | ||
| ): Promise<ExportedDatasetMetadata> { | ||
| return await this.datasetsRepository.exportDatasetMetadata(datasetId, exporter, version) | ||
| } | ||
| } |
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
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,42 @@ | ||
| import { ExportDatasetMetadata } from '../../../src/datasets/domain/useCases/ExportDatasetMetadata' | ||
| import { IDatasetsRepository } from '../../../src/datasets/domain/repositories/IDatasetsRepository' | ||
| import { ReadError } from '../../../src/core/domain/repositories/ReadError' | ||
| import { ExportedDatasetMetadata } from '../../../src/datasets/domain/models/ExportedDatasetMetadata' | ||
| import { DatasetNotNumberedVersion } from '../../../src/datasets/domain/models/DatasetNotNumberedVersion' | ||
|
|
||
| describe('ExportDatasetMetadata.execute', () => { | ||
| const testDatasetId = 1 | ||
| const testExporter = 'ddi' | ||
|
|
||
| test('should return exported dataset metadata on repository success', async () => { | ||
| const expectedMetadata: ExportedDatasetMetadata = { | ||
| content: '<codeBook></codeBook>', | ||
| contentType: 'application/xml' | ||
| } | ||
|
|
||
| const datasetsRepositoryStub: IDatasetsRepository = { | ||
| exportDatasetMetadata: jest.fn().mockResolvedValue(expectedMetadata) | ||
| } as unknown as IDatasetsRepository | ||
|
|
||
| const sut = new ExportDatasetMetadata(datasetsRepositoryStub) | ||
|
|
||
| const actual = await sut.execute(testDatasetId, testExporter, DatasetNotNumberedVersion.DRAFT) | ||
|
|
||
| expect(actual).toEqual(expectedMetadata) | ||
| expect(datasetsRepositoryStub.exportDatasetMetadata).toHaveBeenCalledWith( | ||
| testDatasetId, | ||
| testExporter, | ||
| DatasetNotNumberedVersion.DRAFT | ||
| ) | ||
| }) | ||
|
|
||
| test('should throw ReadError on repository failure', async () => { | ||
| const datasetsRepositoryStub: IDatasetsRepository = { | ||
| exportDatasetMetadata: jest.fn().mockRejectedValue(new ReadError()) | ||
| } as unknown as IDatasetsRepository | ||
|
|
||
| const sut = new ExportDatasetMetadata(datasetsRepositoryStub) | ||
|
|
||
| await expect(sut.execute(testDatasetId, testExporter)).rejects.toThrow(ReadError) | ||
| }) | ||
| }) |
Oops, something went wrong.
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.