Skip to content

Commit

Permalink
add tests for AuthController#deleteAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBartusek committed Apr 11, 2024
1 parent a0a3798 commit 4ea61c7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions apps/api/src/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { mockUserRequest } from '../mocks/mock-user-request';
import { ChangePasswordDto } from './dto/change-password.dto';
import { MockUserRepository } from '../models/users/mocks/mock-user-repository';
import { UpdateEmailDto } from './dto/update-email.dto';
import { DeleteAccountDto } from './dto/delete-account.dto';

describe('AuthController', () => {
let controller: AuthController;
Expand All @@ -21,6 +22,7 @@ describe('AuthController', () => {
}),
validateUserByUserId: jest.fn(() => mockUserRepo.findOne()),
updateUserPassword: jest.fn(),
deleteUserAccount: jest.fn(),
updateUserEmail: jest.fn(async (id, email) => {
const user = await mockUserRepo.findOne();
return {
Expand Down Expand Up @@ -150,4 +152,25 @@ describe('AuthController', () => {
expect(result).rejects.toThrowError(BadRequestException);
});
});

describe('Delete account', () => {
it('should delete account with valid credentials', async () => {
const user = await mockUserRepo.findOne();
mockAuthService.validateUserByUserId.mockResolvedValue(user);

const dto: DeleteAccountDto = { password: 'test' };
const result = await controller.deleteAccount(mockUserRequest, dto);

expect(result.statusCode).toBe(200);
});

it('should throw on invalid credentials', async () => {
mockAuthService.validateUserByUserId.mockResolvedValue(null);

const dto: DeleteAccountDto = { password: 'test' };
const result = controller.deleteAccount(mockUserRequest, dto);

expect(result).rejects.toThrowError(BadRequestException);
});
});
});

0 comments on commit 4ea61c7

Please sign in to comment.