-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from LocalMingle/dev
[완료] 이미지 업로드 사이즈, 확장자 유효성 검사 + [작업 중] unit, integration test 작업들
- Loading branch information
Showing
7 changed files
with
197 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,180 @@ | ||
// users.controller.spec.ts | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { UsersController } from './users.controller'; | ||
import { UsersService } from './users.service'; | ||
// import { INestApplication } from '@nestjs/common'; | ||
import * as request from 'supertest'; | ||
import { UsersModule } from './users.module'; | ||
import { PrismaService } from '../prisma/prisma.service'; | ||
|
||
describe('UsersController', () => { | ||
describe('UsersController unit test', () => { | ||
// let app: INestApplication; | ||
let controller: UsersController; | ||
|
||
beforeEach(async () => { | ||
// const userServiceTest = { findAll: () => ['test1', 'test2'] }; | ||
// console.log('userServiceTest:', userServiceTest); | ||
|
||
let requestMock = {}; | ||
let responseMock = {}; | ||
|
||
beforeAll(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [UsersController], | ||
imports: [UsersModule], | ||
providers: [UsersService], | ||
}).compile(); | ||
}) | ||
// .overrideProvider(UsersService) | ||
// .useValue(userServiceTest) | ||
.compile(); | ||
|
||
controller = module.get<UsersController>(UsersController); | ||
// app = module.createNestApplication(); | ||
// await app.init(); | ||
}); | ||
|
||
// jest test | ||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
|
||
describe('Unit Tests', () => { | ||
|
||
// 3. userId를 통한 유저 조회 | ||
// @Get(':id') | ||
// @UseGuards(JwtAccessAuthGuard) // passport를 사용하여 인증 확인 | ||
// @ApiBearerAuth() // Swagger 문서에 Bearer 토큰 인증 추가 | ||
// @ApiOperation({ summary: 'ID로 회원 조회' }) | ||
// @ApiResponse({ status: 200, description: '유저 정보 조회 성공' }) | ||
// async findOne(@Param('id') id: string) { | ||
// const user = this.usersService.findOne(+id); | ||
// if (!user) { | ||
// throw new NotFoundException('User does not exist'); | ||
// } | ||
// return user; | ||
// } | ||
it('should return a status of 200', () => { | ||
controller.findOne('1'); | ||
expect(controller.findOne('1')).toBe('1'); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
/* | ||
// supertest | ||
describe('User Signup Tests', () => { | ||
const validUser = { | ||
email: '[email protected]', | ||
password: 'password', | ||
confirmPassword: 'password', | ||
nickname: 'nicknameDTO', | ||
intro: 'introDTO', | ||
}; | ||
// TestCase 01: 회원가입 테스트 - 유효한 CreateUserDto | ||
it('should create a user if CreateUserDto is valid', async () => { | ||
await request(app.getHttpServer()) | ||
.post('/users/signup') | ||
.send(validUser) | ||
.expect(201); | ||
}); | ||
// TestCase 02: 회원가입 테스트 - 비밀번호와 비밀번호 확인이 일치하지 않을 때 | ||
it('should not create a user if password and confirmPassword do not match', async () => { | ||
const invalidUser = { ...validUser, confirmPassword: 'wrongPassword' }; | ||
await request(app.getHttpServer()) | ||
.post('/users/signup') | ||
.send(invalidUser) | ||
.expect(400); | ||
}); | ||
// TestCase 03: 회원가입 테스트 - 이메일 중복 테스트 | ||
it('should not create a user if email is invalid', async () => { | ||
const invalidUser = { ...validUser, email: 'invalidEmail' }; | ||
await request(app.getHttpServer()) | ||
.post('/users/signup') | ||
.send(invalidUser) | ||
.expect(400); | ||
}); | ||
// TestCase 04: 회원가입 테스트 - 닉네임 중복 테스트 | ||
it('should not create a user if nickname is already taken', async () => { | ||
const invalidUser = { ...validUser, nickname: 'existingNickname' }; | ||
await request(app.getHttpServer()) | ||
.post('/users/signup') | ||
.send(invalidUser) | ||
.expect(400); | ||
}); | ||
// TestCase 05: 회원가입 테스트 - 회원가입 성공 테스트 create(createUserDto: CreateUserDto) | ||
it('should successfully create a user', async () => { | ||
const newUser = { | ||
email: '[email protected]', | ||
password: 'newPassword', | ||
confirmPassword: 'newPassword', | ||
nickname: 'newNickname', | ||
intro: 'newIntro', | ||
}; | ||
await request(app.getHttpServer()) | ||
.post('/users/signup') | ||
.send(newUser) | ||
.expect(201); | ||
}); | ||
}); | ||
describe('User Operations Tests', () => { | ||
// TestCase 06: 사용자 ID로 사용자 조회 테스트 findOne(id: number) | ||
it('should find a user by ID', async () => { | ||
const userId = 1; // 예시 ID | ||
await request(app.getHttpServer()).get(`/users/${userId}`).expect(200); | ||
}); | ||
// TestCase 07: 유저 본인 조회 테스트 (users/me) findMe | ||
it('should find the current user', async () => { | ||
await request(app.getHttpServer()).get('/users/me').expect(200); | ||
}); | ||
// TestCase 08: 유저 정보 수정 테스트 update(id: number, updateUserDto: UpdateUserDto) | ||
it('should update user information', async () => { | ||
const userId = 1; // 예시 ID | ||
const updateUserDto = { | ||
nickname: 'newNickname', | ||
intro: 'newIntro', | ||
}; | ||
await request(app.getHttpServer()) | ||
.put(`/users/${userId}`) | ||
.send(updateUserDto) | ||
.expect(200); | ||
}); | ||
// TestCase 09: 회원 탈퇴 테스트 remove(userId: number, password: string) | ||
it('should remove a user', async () => { | ||
const userId = 1; // 예시 ID | ||
const password = 'password'; // 예시 비밀번호 | ||
await request(app.getHttpServer()) | ||
.delete(`/users/${userId}`) | ||
.send({ password }) | ||
.expect(200); | ||
}); | ||
// TestCase 10: 사용자가 생성한 모임(Event) 리스트를 조회한다. findHostedEvents(id: number) | ||
it('should find hosted events by user ID', async () => { | ||
const userId = 1; // 예시 ID | ||
await request(app.getHttpServer()) | ||
.get(`/users/${userId}/hosted-events`) | ||
.expect(200); | ||
}); | ||
// TestCase 11: 사용자가 참여한 모임(Event) 리스트를 조회한다. findJoinedEvents(id: number) | ||
it('should find joined events by user ID', async () => { | ||
const userId = 1; // 예시 ID | ||
await request(app.getHttpServer()) | ||
.get(`/users/${userId}/joined-events`) | ||
.expect(200); | ||
}); | ||
}); | ||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters