diff --git a/src/app/auth/auth.decorator.ts b/src/app/auth/auth.decorator.ts index b69b373..2eae262 100644 --- a/src/app/auth/auth.decorator.ts +++ b/src/app/auth/auth.decorator.ts @@ -1,3 +1,5 @@ import { Reflector } from '@nestjs/core'; -export const Roles = Reflector.createDecorator(); +import { Role } from '~/types/role.enum'; + +export const Roles = Reflector.createDecorator(); diff --git a/src/app/auth/tests/auth.controller.spec.ts b/src/app/auth/tests/auth.controller.spec.ts index bf9584f..22fe768 100644 --- a/src/app/auth/tests/auth.controller.spec.ts +++ b/src/app/auth/tests/auth.controller.spec.ts @@ -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: {}, @@ -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 = { diff --git a/src/app/auth/tests/auth.service.spec.ts b/src/app/auth/tests/auth.service.spec.ts index be92ec6..b86bddc 100644 --- a/src/app/auth/tests/auth.service.spec.ts +++ b/src/app/auth/tests/auth.service.spec.ts @@ -81,6 +81,23 @@ describe('AuthService', () => { }); }); + describe('signOut', () => { + const session = { + _id: expect.anything(), + } as unknown as Entity; + + 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(),