File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { IFilesRepository } from '../../../src/files/domain/repositories/IFilesRepository'
2+ import { UploadedFileDTO } from '../../../src/files'
3+ import { ReplaceFile } from '../../../src/files/domain/useCases/ReplaceFile'
4+ import { WriteError } from '../../../src/core'
5+
6+ describe ( 'execute' , ( ) => {
7+ const testUploadedFileDTO : UploadedFileDTO = {
8+ fileName : 'testfile' ,
9+ storageId : 'testStorageId' ,
10+ checksumValue : 'testChecksumValue' ,
11+ checksumType : 'md5' ,
12+ mimeType : 'test/type'
13+ }
14+
15+ test ( 'should return undefined on client success' , async ( ) => {
16+ const filesRepositoryStub : IFilesRepository = { } as IFilesRepository
17+ filesRepositoryStub . replaceFile = jest . fn ( ) . mockResolvedValue ( undefined )
18+
19+ const sut = new ReplaceFile ( filesRepositoryStub )
20+
21+ const actual = await sut . execute ( 1 , testUploadedFileDTO )
22+
23+ expect ( actual ) . toEqual ( undefined )
24+ } )
25+
26+ test ( 'should return error on client error' , async ( ) => {
27+ const filesRepositoryStub : IFilesRepository = { } as IFilesRepository
28+ filesRepositoryStub . replaceFile = jest . fn ( ) . mockRejectedValue ( new WriteError ( 'Some error' ) )
29+
30+ const sut = new ReplaceFile ( filesRepositoryStub )
31+
32+ await expect ( sut . execute ( 1 , testUploadedFileDTO ) ) . rejects . toThrow ( WriteError )
33+ } )
34+ } )
You can’t perform that action at this time.
0 commit comments