Skip to content

Commit

Permalink
test: 리프레시 토큰 테스트 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
dannaward committed Jul 22, 2022
1 parent 3a77233 commit 9a34af5
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/unit/services/AuthService.test.ts
Original file line number Diff line number Diff line change
@@ -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.');
}

0 comments on commit 9a34af5

Please sign in to comment.