Skip to content

Commit 17e2d15

Browse files
committed
test: validating wrong password case when try login
1 parent 37a034e commit 17e2d15

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

backend/src/auth/__tests__/auth.service.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ describe('AuthService', () => {
5454
});
5555
});
5656

57+
it('should throw error when user login and password is wrong', async () => {
58+
const user = new UsersStub();
59+
const wrongPassword = 'errado';
60+
usersService.findByUsernameAndReturnPassword.mockResolvedValue({
61+
...user,
62+
password: wrongPassword,
63+
});
64+
65+
await expect(service.login(user as UserRegisterDto)).rejects.toThrow(
66+
'Senha inválida',
67+
);
68+
expect(usersService.findByUsernameAndReturnPassword).toHaveBeenCalledWith(
69+
user.username,
70+
);
71+
expect(jwtService.signAsync).toHaveBeenCalledTimes(0);
72+
});
73+
5774
it('should auth create user correctly', async () => {
5875
const user = new UsersStub();
5976
usersService.create.mockResolvedValue(user);

0 commit comments

Comments
 (0)