From 9a34af55d61cde6a26b4ea3bc45878fb5c206837 Mon Sep 17 00:00:00 2001 From: Danna Date: Fri, 22 Jul 2022 23:35:42 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EB=A6=AC=ED=94=84=EB=A0=88=EC=8B=9C=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unit/services/AuthService.test.ts | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/unit/services/AuthService.test.ts diff --git a/test/unit/services/AuthService.test.ts b/test/unit/services/AuthService.test.ts new file mode 100644 index 0000000..1e81990 --- /dev/null +++ b/test/unit/services/AuthService.test.ts @@ -0,0 +1,45 @@ +import { UserRepository } from '../../../src/repositories/UserRepository'; +import { UserService } from '../../../src/services/UserService'; +import { AuthService } from '../../../src/services/AuthService'; +import { createMemoryDatabase } from '../../utils/CreateMemoryDatabase'; +import { UserSeed } from '../../utils/seeds/UserTestSeed'; +import { Connection } from 'typeorm'; +import { CreateUserDto } from '../../../src/dtos/UserDto'; +import { ReturnErrorType } from '../../../src/constants/ReturnErrorType'; +import { CreateTokenDto } from '../../../src/dtos/AuthDto'; + +describe('AuthService', () => { + let db: Connection; + let userRepository: UserRepository; + let authService: AuthService; + let userService: UserService; + + beforeAll(async () => { + db = await createMemoryDatabase(); + userRepository = db.getCustomRepository(UserRepository); + await userRepository.save(UserSeed); + userService = new UserService(userRepository); + authService = new AuthService(userRepository); + }); + + afterAll(() => db.close()); + + const request = { + accessToken: 'accessToken', + refreshToken: 'refreshToken', + }; + + it('유효하지 않은 리프레시 토큰이 오면 토큰을 발급하지 않는다.', async () => { + const isUser = await authService.validateUserBySnsId(request.accessToken); + + if (isUser) { + const accessToken = generateAccessToken(isUser); + } else { + expect(isUser).toBeNull(); + } + }); +}); + +function generateAccessToken(user: any) { + throw new Error('Function not implemented.'); +}