Skip to content

Commit

Permalink
Testes Create Password
Browse files Browse the repository at this point in the history
  • Loading branch information
leafrse committed Feb 5, 2025
1 parent 7f08acc commit 61e26e5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ describe('AuthService', () => {
user.role = UserRoles.User;

jest.spyOn(userRepository, 'findOneBy').mockResolvedValueOnce(null);

jest.spyOn(userRepository, 'create').mockReturnValue(user);
jest.spyOn(userRepository, 'save').mockResolvedValue(user);
jest.spyOn(service, 'signIn').mockResolvedValue({
Expand Down
6 changes: 3 additions & 3 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class AuthService {
}: SignInDto & { keepLoggedIn?: boolean }): Promise<SignInResponseDto> {
const user = await this.usersRepository.findOneBy({ email, role });
if (!user || !(await bcrypt.compare(password, user.password))) {
throw new UnauthorizedException('E-mail ou senha inválidos.');
throw new BadRequestException('E-mail ou senha inválidos.');
}

const payload = { sub: user.id, email: user.email, role: user.role };
Expand Down Expand Up @@ -110,7 +110,7 @@ export class AuthService {

async recoverPassword(email: string): Promise<{ success: boolean }> {
const user = await this.usersRepository.findOneBy({ email });
if (!user) throw new UnauthorizedException('Usuário não encontrado.');
if (!user) throw new BadRequestException('Usuário não encontrado.');

const token = await this.jwtService.signAsync(
{ sub: user.id },
Expand Down Expand Up @@ -156,7 +156,7 @@ export class AuthService {
);

if (!passwordMatches) {
throw new UnauthorizedException('Senha atual incorreta.');
throw new BadRequestException('Senha atual incorreta.');
return;
}

Expand Down

0 comments on commit 61e26e5

Please sign in to comment.