-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth.controller.spec.ts
More file actions
48 lines (40 loc) · 1.2 KB
/
auth.controller.spec.ts
File metadata and controls
48 lines (40 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Test, TestingModule } from '@nestjs/testing';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { UsersService } from '../users/users.service';
describe('AuthController', () => {
let controller: AuthController;
// Create mock implementations
const mockAuthService = {
signup: jest.fn(),
};
const mockUsersService = {
create: jest.fn(),
find: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AuthController],
providers: [
{
provide: AuthService,
useValue: mockAuthService,
},
{
provide: UsersService,
useValue: mockUsersService,
},
],
}).compile();
controller = module.get<AuthController>(AuthController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
it('rejects forgot password for unregistered email', async () => {
mockUsersService.find.mockResolvedValue([]);
await expect(
controller.forgotPassword({ email: 'random@example.com' } as any),
).rejects.toThrow('Account is not registered.');
});
});