-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsession.controller.spec.ts
37 lines (27 loc) · 1.13 KB
/
session.controller.spec.ts
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
import { Test, TestingModule } from '@nestjs/testing';
import { SessionController } from './session.controller';
import { UserInfo } from './user-auth.dto';
import { authGuardMockProviders } from '../../auth/auth-guard-mock.providers';
describe('SessionController', () => {
let controller: SessionController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [SessionController],
providers: [...authGuardMockProviders],
}).compile();
controller = module.get<SessionController>(SessionController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
it('should return the user object on the request', () => {
const user = new UserInfo('user-id', 'user', ['user_app']);
const response = controller.login(user);
expect(response).toBe(user);
});
it('should return user object from combinedAuth middleware if user is authenticated', async () => {
const user = new UserInfo('user-id', 'user', ['user_app']);
const res = await controller.session(user);
expect(res).toEqual({ ok: true, userCtx: user });
});
});