Skip to content

Commit 1893050

Browse files
committed
refactor: move sut creation to a factory helper method
1 parent 190b0a1 commit 1893050

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/infra/criptography/bcrypt-adapter.spec.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ jest.mock('bcrypt', () => ({
66
}
77

88
}))
9+
10+
const salt = 12
11+
const makeSut = (): BcryptAdapter => {
12+
return new BcryptAdapter(salt)
13+
}
14+
915
describe('Bcrypt Adapter', () => {
1016
test('Should call bcrypt with correct values', async () => {
11-
const salt = 12
12-
const sut = new BcryptAdapter(salt)
17+
const sut = makeSut()
1318
const hashSpy = jest.spyOn(bcrypt, 'hash')
1419
await sut.encrypt('any_value')
1520
expect(hashSpy).toHaveBeenCalledWith('any_value', salt)
1621
})
1722
test('Should return a hash on success', async () => {
18-
const salt = 12
19-
const sut = new BcryptAdapter(salt)
23+
const sut = makeSut()
2024
const hash = await sut.encrypt('any_value')
2125
expect(hash).toBe('hash')
2226
})

0 commit comments

Comments
 (0)