Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 89032fd

Browse files
committedSep 23, 2024
test: AppController e2e 테스트 수정
모델 변경에 맞춰 수정
1 parent 7e05a37 commit 89032fd

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed
 

‎nestjs-BE/server/test/app.e2e-spec.ts

+11-28
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import { AppModule } from '../src/app.module';
55
import { PrismaService } from '../src/prisma/prisma.service';
66
import { sign } from 'jsonwebtoken';
77
import { ConfigService } from '@nestjs/config';
8+
import { v4 as uuid } from 'uuid';
89

910
describe('AppController (e2e)', () => {
1011
let app: INestApplication;
1112
let configService: ConfigService;
13+
let testUserUuid: string;
1214

1315
beforeAll(async () => {
1416
const moduleFixture: TestingModule = await Test.createTestingModule({
@@ -23,17 +25,12 @@ describe('AppController (e2e)', () => {
2325
const prisma: PrismaService =
2426
moduleFixture.get<PrismaService>(PrismaService);
2527

26-
const testUser = { email: 'test@email.com', provider: 'kakao' };
27-
prisma.user.upsert({
28-
where: {
29-
email_provider: { email: testUser.email, provider: testUser.provider },
30-
},
31-
update: {},
32-
create: {
33-
uuid: 'test uuid',
34-
email: testUser.email,
35-
provider: testUser.provider,
36-
},
28+
await prisma.kakaoUser.deleteMany({});
29+
await prisma.user.deleteMany({});
30+
31+
testUserUuid = uuid();
32+
await prisma.user.create({
33+
data: { uuid: testUserUuid },
3734
});
3835
});
3936

@@ -55,23 +52,9 @@ describe('AppController (e2e)', () => {
5552
.expect({ message: 'Unauthorized', statusCode: 401 });
5653
});
5754

58-
it('/login-test (GET) expired access token', () => {
59-
const invalidToken = sign(
60-
{ sub: 'test uuid' },
61-
configService.get<string>('JWT_ACCESS_SECRET'),
62-
{ expiresIn: '-5m' },
63-
);
64-
65-
return request(app.getHttpServer())
66-
.get('/login-test')
67-
.auth(invalidToken, { type: 'bearer' })
68-
.expect(HttpStatus.UNAUTHORIZED)
69-
.expect({ message: 'Unauthorized', statusCode: 401 });
70-
});
71-
7255
it('/login-test (GET) expired access token', () => {
7356
const expiredToken = sign(
74-
{ sub: 'test uuid' },
57+
{ sub: testUserUuid },
7558
configService.get<string>('JWT_ACCESS_SECRET'),
7659
{ expiresIn: '-5m' },
7760
);
@@ -99,7 +82,7 @@ describe('AppController (e2e)', () => {
9982
});
10083

10184
it('/login-test (GET) wrong secret access token', () => {
102-
const invalidToken = sign({ sub: 'test uuid' }, 'wrong jwt access token', {
85+
const invalidToken = sign({ sub: testUserUuid }, 'wrong jwt access token', {
10386
expiresIn: '5m',
10487
});
10588

@@ -112,7 +95,7 @@ describe('AppController (e2e)', () => {
11295

11396
it('/login-test (GET) logged in', async () => {
11497
const testToken = sign(
115-
{ sub: 'test uuid' },
98+
{ sub: testUserUuid },
11699
configService.get<string>('JWT_ACCESS_SECRET'),
117100
{ expiresIn: '5m' },
118101
);

0 commit comments

Comments
 (0)
Please sign in to comment.