Skip to content

Commit 70c0469

Browse files
committed
test: add unit
1 parent 8faf1ba commit 70c0469

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { WriteError } from '../../../src'
2+
import { IFilesRepository } from '../../../src/files/domain/repositories/IFilesRepository'
3+
import { RestrictFile } from '../../../src/files/domain/useCases/RestrictFile'
4+
5+
describe('execute', () => {
6+
test('should return undefined when repository call is successful', async () => {
7+
const filesRepositoryStub: IFilesRepository = {} as IFilesRepository
8+
filesRepositoryStub.restrictFile = jest.fn().mockResolvedValue(undefined)
9+
10+
const sut = new RestrictFile(filesRepositoryStub)
11+
12+
const actual = await sut.execute(1)
13+
14+
expect(actual).toEqual(undefined)
15+
})
16+
17+
test('should return error result on repository error', async () => {
18+
const filesRepositoryStub: IFilesRepository = {} as IFilesRepository
19+
filesRepositoryStub.restrictFile = jest.fn().mockRejectedValue(new WriteError())
20+
21+
const sut = new RestrictFile(filesRepositoryStub)
22+
23+
await expect(sut.execute(1)).rejects.toThrow(WriteError)
24+
})
25+
})

0 commit comments

Comments
 (0)