-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NDD-103] Member API E2E 테스트 (1h / 1h) #29
Changes from 2 commits
871c263
c4b0fc7
3a1e356
01386ae
e68ac91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import {CorsOptions} from "@nestjs/common/interfaces/external/cors-options.interface"; | ||
import {CORS_HEADERS, CORS_ORIGIN} from "./cors.secure"; | ||
import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface'; | ||
import { CORS_HEADERS, CORS_ORIGIN } from './cors.secure'; | ||
|
||
export const CORS_CONFIG: CorsOptions = { | ||
origin: CORS_ORIGIN, | ||
credentials: true, | ||
exposedHeaders: CORS_HEADERS, | ||
} | ||
origin: CORS_ORIGIN, | ||
credentials: true, | ||
exposedHeaders: CORS_HEADERS, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import { Test } from '@nestjs/testing'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { MemberController } from './member.controller'; | ||
import { MemberResponse } from '../dto/memberResponse'; | ||
import { Request } from 'express'; | ||
import { Member } from '../entity/member'; | ||
import { ManipulatedTokenNotFiltered } from 'src/token/exception/token.exception'; | ||
import { INestApplication } from '@nestjs/common'; | ||
import { AppModule } from 'src/app.module'; | ||
import * as request from 'supertest'; | ||
import { TokenModule } from 'src/token/token.module'; | ||
import { TokenService } from 'src/token/service/token.service'; | ||
|
||
describe('MemberController', () => { | ||
let memberController: MemberController; | ||
|
@@ -47,3 +52,44 @@ describe('MemberController', () => { | |
).toThrow(ManipulatedTokenNotFiltered); | ||
}); | ||
}); | ||
|
||
describe('MemberController (E2E Test)', () => { | ||
let app: INestApplication; | ||
let tokenService: TokenService; | ||
|
||
beforeAll(async () => { | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
imports: [AppModule, TokenModule], | ||
}).compile(); | ||
|
||
app = moduleFixture.createNestApplication(); | ||
await app.init(); | ||
|
||
tokenService = moduleFixture.get<TokenService>(TokenService); | ||
}); | ||
|
||
it('GET /api/member (회원 정보 반환 성공)', async () => { | ||
const memberId = 1; // 항상 DB에 들어있는 회원의 ID로의 설정이 필요해보입니다. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분에 대한 고민이 많습니다... 이렇게 진행하면 DB에 영구적으로 1이라는 ID를 가지는 Member를 항상 넣어놔야 하는데.. 이게 말이 되나 싶구요.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그렇다면, 테스트시에 DB의 모든 데이터를 지우는 로직을 테스트 전체 후에 넣는 것은 어떨까요??? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이것도 좋은 생각입니다 고민 해보겠습니다!!! |
||
const validToken = await tokenService.assignToken(memberId); | ||
|
||
const response = await request(app.getHttpServer()) | ||
.get('/api/member') | ||
.set('Authorization', `Bearer ${validToken}`) | ||
.expect(200); | ||
|
||
expect(response.body.id).toBe(memberId); | ||
}); | ||
|
||
it('GET /api/member (유효하지 않은 토큰 사용으로 인한 회원 정보 반환 실패)', async () => { | ||
const invalidToken = 'INVALID_TOKEN'; | ||
|
||
await request(app.getHttpServer()) | ||
.get('/api/member') | ||
.set('Authorization', `Bearer ${invalidToken}`) | ||
.expect(401); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분의 반복구조를 빼낼 수 있을 것 같습니다!!!
이렇게 한 후에, 따로 const로 옵션들을 가져와서 테스트 app의 반복구조를 줄이는건 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 좋은 생각입니다 한번 시도해보겠습니다!!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e68ac91