Skip to content

Commit

Permalink
test: signout controller (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan2slime authored Jul 13, 2024
1 parent 7bd9de5 commit 1020710
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/app/auth/auth.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Reflector } from '@nestjs/core';

export const Roles = Reflector.createDecorator<string[]>();
import { Role } from '~/types/role.enum';

export const Roles = Reflector.createDecorator<Role[]>();
11 changes: 11 additions & 0 deletions src/app/auth/tests/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('AuthController', () => {
status: jest.fn().mockReturnThis(),
json: jest.fn(data => data),
cookie: jest.fn(),
send: jest.fn().mockReturnThis(),
} as unknown as Response;
const req = {
user: {},
Expand Down Expand Up @@ -99,6 +100,16 @@ describe('AuthController', () => {
});
});

describe('signOut', () => {
it('should expire session and sign out user ', async () => {
jest.spyOn(authService, 'signOut').mockResolvedValue(null);

await authController.signOut(req, res);

expect(authService.signOut).toHaveBeenCalled();
});
});

describe('refresh', () => {
it('must return user passed by guard', async () => {
const data = {
Expand Down
17 changes: 17 additions & 0 deletions src/app/auth/tests/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ describe('AuthService', () => {
});
});

describe('signOut', () => {
const session = {
_id: expect.anything(),
} as unknown as Entity<Session>;

it('must expire session by passed id', async () => {
jest
.spyOn(sessionService, 'expireSession')
.mockImplementation(async () => {});

await authService.signOut(session);

expect(sessionService.expireSession).toHaveBeenCalledTimes(1);
expect(sessionService.expireSession).toHaveBeenCalledWith(session._id);
});
});

describe('signIn', () => {
const payload: SignInDto = {
email: expect.anything(),
Expand Down

0 comments on commit 1020710

Please sign in to comment.