-
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.
- Loading branch information
1 parent
c789d0f
commit 81255e0
Showing
9 changed files
with
162 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface UpdateFileMetadataDTO { | ||
description?: string | ||
prevFreeform?: string | ||
categories?: string[] | ||
dataFileTags?: string[] | ||
restrict?: boolean | ||
} |
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,25 @@ | ||
import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
import { IFilesRepository } from '../repositories/IFilesRepository' | ||
import { UpdateFileMetadataDTO } from '../dtos/UpdateFileMetadataDTO' | ||
|
||
export class UpdateFileMetadata implements UseCase<void> { | ||
private filesRepository: IFilesRepository | ||
|
||
constructor(filesRepository: IFilesRepository) { | ||
this.filesRepository = filesRepository | ||
} | ||
|
||
/** | ||
* Updates the metadata for a particular File. | ||
* | ||
* @param {number | string} [fileId] - The file identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers). | ||
* @param {UpdateFileMetadataDTO} [updateFileMetadataDTO] - The DTO containing the metadata updates. | ||
* @returns {Promise<void>} | ||
*/ | ||
async execute( | ||
fileId: number | string, | ||
updateFileMetadataDTO: UpdateFileMetadataDTO | ||
): Promise<void> { | ||
await this.filesRepository.updateFileMetadata(fileId, updateFileMetadataDTO) | ||
} | ||
} |
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
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,46 @@ | ||
import { UpdateFileMetadata } from '../../../src/files/domain/useCases/UpdateFileMetadata' | ||
import { IFilesRepository } from '../../../src/files/domain/repositories/IFilesRepository' | ||
import { WriteError } from '../../../src/core/domain/repositories/WriteError' | ||
import { createFileMetadataWithCategories } from '../../testHelpers/files/filesHelper' | ||
|
||
describe('UpdateFileMetadata', () => { | ||
const testFileMetadata = createFileMetadataWithCategories() | ||
test('should updated file metadata with correct parameters and id', async () => { | ||
const filesRepositoryStub: IFilesRepository = {} as IFilesRepository | ||
filesRepositoryStub.updateFileMetadata = jest.fn().mockResolvedValue(testFileMetadata) | ||
|
||
const sut = new UpdateFileMetadata(filesRepositoryStub) | ||
|
||
await sut.execute(1, testFileMetadata) | ||
|
||
expect(filesRepositoryStub.updateFileMetadata).toHaveBeenCalledWith(1, testFileMetadata) | ||
expect(filesRepositoryStub.updateFileMetadata).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
test('should return the updated file metadata with correct parameters and persisten Id', async () => { | ||
const filesRepositoryStub: IFilesRepository = { | ||
updateFileMetadata: jest.fn().mockResolvedValue(testFileMetadata) | ||
} as unknown as IFilesRepository | ||
|
||
const sut = new UpdateFileMetadata(filesRepositoryStub) | ||
|
||
await sut.execute('doi:10.5072/FK2/HC6KTB', testFileMetadata) | ||
|
||
expect(filesRepositoryStub.updateFileMetadata).toHaveBeenCalledWith( | ||
'doi:10.5072/FK2/HC6KTB', | ||
testFileMetadata | ||
) | ||
expect(filesRepositoryStub.updateFileMetadata).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
test('should throw an error if the repository throws an error', async () => { | ||
const filesRepositoryStub: IFilesRepository = { | ||
updateFileMetadata: jest.fn().mockRejectedValue(new WriteError()) | ||
} as unknown as IFilesRepository | ||
|
||
const sut = new UpdateFileMetadata(filesRepositoryStub) | ||
|
||
await expect(sut.execute(1, testFileMetadata)).rejects.toThrow(WriteError) | ||
expect(filesRepositoryStub.updateFileMetadata).toHaveBeenCalledWith(1, testFileMetadata) | ||
}) | ||
}) |