-
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.
Changed: separated adding uploaded file to dataset from file upload u…
…se case
- Loading branch information
Showing
9 changed files
with
148 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
import { IDirectUploadClient } from '../clients/IDirectUploadClient' | ||
|
||
export class AddUploadedFileToDataset implements UseCase<void> { | ||
private directUploadClient: IDirectUploadClient | ||
|
||
constructor(directUploadClient: IDirectUploadClient) { | ||
this.directUploadClient = directUploadClient | ||
} | ||
|
||
/** | ||
* TODO | ||
* @returns {Promise<void>} | ||
*/ | ||
async execute(datasetId: number | string, file: File, storageId: string): Promise<void> { | ||
await this.directUploadClient.addUploadedFileToDataset(datasetId, file, storageId) | ||
} | ||
} |
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,35 @@ | ||
import { createSinglepartFileBlob } from '../../testHelpers/files/filesHelper' | ||
import { IDirectUploadClient } from '../../../src/files/domain/clients/IDirectUploadClient' | ||
import { DirectUploadClientError } from '../../../src/files/domain/clients/DirectUploadClientError' | ||
import { AddUploadedFileToDataset } from '../../../src/files/domain/useCases/AddUploadedFileToDataset' | ||
|
||
describe('execute', () => { | ||
let testFile: File | ||
const testStorageId = 'test' | ||
|
||
beforeAll(async () => { | ||
testFile = await createSinglepartFileBlob() | ||
}) | ||
|
||
test('should return undefined on client success', async () => { | ||
const directUploadClientStub: IDirectUploadClient = {} as IDirectUploadClient | ||
directUploadClientStub.addUploadedFileToDataset = jest.fn().mockResolvedValue(undefined) | ||
|
||
const sut = new AddUploadedFileToDataset(directUploadClientStub) | ||
|
||
const actual = await sut.execute(1, testFile, testStorageId) | ||
|
||
expect(actual).toEqual(undefined) | ||
}) | ||
|
||
test('should return error on client error', async () => { | ||
const directUploadClientStub: IDirectUploadClient = {} as IDirectUploadClient | ||
directUploadClientStub.addUploadedFileToDataset = jest | ||
.fn() | ||
.mockRejectedValue(new DirectUploadClientError('test', 'test', 'test')) | ||
|
||
const sut = new AddUploadedFileToDataset(directUploadClientStub) | ||
|
||
await expect(sut.execute(1, testFile, testStorageId)).rejects.toThrow(DirectUploadClientError) | ||
}) | ||
}) |
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