From 4e57191cdc614f4cc0c7a9ff97036779b191b44d Mon Sep 17 00:00:00 2001 From: J_Coder Date: Mon, 13 Jan 2025 17:32:12 +0900 Subject: [PATCH 01/10] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20service?= =?UTF-8?q?=20=EA=B3=84=EC=B8=B5=20=EA=B0=9C=EB=B3=84=20=EC=9D=B8=EC=9E=90?= =?UTF-8?q?=20-\>=20DTO=20=EC=82=AC=EC=9A=A9,=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EB=AA=85=ED=99=95=ED=95=98=EA=B2=8C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/admin/controller/admin.controller.ts | 8 ++--- server/src/admin/service/admin.service.ts | 8 ++--- server/src/feed/controller/feed.controller.ts | 14 +++++---- server/src/feed/service/feed.service.ts | 23 ++++++++------- server/src/rss/controller/rss.controller.ts | 14 ++++----- server/src/rss/service/rss.service.ts | 29 ++++++++++++------- .../controller/statistic.controller.ts | 8 ++--- .../statistic/service/statistic.service.ts | 12 ++++---- 8 files changed, 65 insertions(+), 51 deletions(-) diff --git a/server/src/admin/controller/admin.controller.ts b/server/src/admin/controller/admin.controller.ts index f3a5fce..e65ecc6 100644 --- a/server/src/admin/controller/admin.controller.ts +++ b/server/src/admin/controller/admin.controller.ts @@ -30,11 +30,11 @@ export class AdminController { @Post('/login') @HttpCode(HttpStatus.OK) async loginAdmin( - @Body() loginAdminDto: LoginAdminRequestDto, + @Body() loginAdminBodyDto: LoginAdminRequestDto, @Res({ passthrough: true }) response: Response, @Req() request: Request, ) { - await this.adminService.loginAdmin(loginAdminDto, response, request); + await this.adminService.loginAdmin(loginAdminBodyDto, response, request); return ApiResponse.responseWithNoContent( '로그인이 성공적으로 처리되었습니다.', ); @@ -57,8 +57,8 @@ export class AdminController { @ApiCreateAdmin() @UseGuards(CookieAuthGuard) @Post('/register') - async createAdmin(@Body() registerAdminDto: RegisterAdminRequestDto) { - await this.adminService.createAdmin(registerAdminDto); + async createAdmin(@Body() registerAdminBodyDto: RegisterAdminRequestDto) { + await this.adminService.createAdmin(registerAdminBodyDto); return ApiResponse.responseWithNoContent( '성공적으로 관리자 계정이 생성되었습니다.', ); diff --git a/server/src/admin/service/admin.service.ts b/server/src/admin/service/admin.service.ts index bdd84ae..7550708 100644 --- a/server/src/admin/service/admin.service.ts +++ b/server/src/admin/service/admin.service.ts @@ -23,12 +23,12 @@ export class AdminService { ) {} async loginAdmin( - loginAdminDto: LoginAdminRequestDto, + loginAdminBodyDto: LoginAdminRequestDto, response: Response, request: Request, ) { const cookie = request.cookies['sessionId']; - const { loginId, password } = loginAdminDto; + const { loginId, password } = loginAdminBodyDto; const admin = await this.adminRepository.findOne({ where: { loginId }, @@ -90,8 +90,8 @@ export class AdminService { response.clearCookie('sessionId'); } - async createAdmin(registerAdminDto: RegisterAdminRequestDto) { - let { loginId, password } = registerAdminDto; + async createAdmin(registerAdminBodyDto: RegisterAdminRequestDto) { + let { loginId, password } = registerAdminBodyDto; const existingAdmin = await this.adminRepository.findOne({ where: { loginId }, diff --git a/server/src/feed/controller/feed.controller.ts b/server/src/feed/controller/feed.controller.ts index 53e1277..976f7b0 100644 --- a/server/src/feed/controller/feed.controller.ts +++ b/server/src/feed/controller/feed.controller.ts @@ -37,10 +37,12 @@ export class FeedController { @ApiReadFeedPagination() @Get('') @HttpCode(HttpStatus.OK) - async readFeedPagination(@Query() queryFeedDto: FeedPaginationRequestDto) { + async readFeedPagination( + @Query() feedPaginationQueryDto: FeedPaginationRequestDto, + ) { return ApiResponse.responseWithData( '피드 조회 완료', - await this.feedService.readFeedPagination(queryFeedDto), + await this.feedService.readFeedPagination(feedPaginationQueryDto), ); } @@ -75,10 +77,10 @@ export class FeedController { @ApiSearchFeedList() @Get('search') @HttpCode(HttpStatus.OK) - async searchFeedList(@Query() searchFeedReq: SearchFeedRequestDto) { + async searchFeedList(@Query() searchFeedQueryDto: SearchFeedRequestDto) { return ApiResponse.responseWithData( '검색 결과 조회 완료', - await this.feedService.searchFeedList(searchFeedReq), + await this.feedService.searchFeedList(searchFeedQueryDto), ); } @@ -86,12 +88,12 @@ export class FeedController { @Post('/:feedId') @HttpCode(HttpStatus.OK) async updateFeedViewCount( - @Param() params: FeedViewUpdateRequestDto, + @Param() viewUpdateParamDto: FeedViewUpdateRequestDto, @Req() request: Request, @Res({ passthrough: true }) response: Response, ) { await this.feedService.updateFeedViewCount( - params.feedId, + viewUpdateParamDto, request, response, ); diff --git a/server/src/feed/service/feed.service.ts b/server/src/feed/service/feed.service.ts index daf8a70..5a3d2b6 100644 --- a/server/src/feed/service/feed.service.ts +++ b/server/src/feed/service/feed.service.ts @@ -16,7 +16,6 @@ import { FeedTrendResponseDto, } from '../dto/response/feed-pagination.dto'; import { RedisService } from '../../common/redis/redis.service'; -import { EventEmitter2 } from '@nestjs/event-emitter'; import { SearchFeedRequestDto } from '../dto/request/search-feed.dto'; import { Response, Request } from 'express'; import { cookieConfig } from '../../common/cookie/cookie.config'; @@ -29,6 +28,7 @@ import { FeedRecentRedis, FeedRecentResponseDto, } from '../dto/response/recent.dto'; +import { FeedViewUpdateRequestDto } from '../dto/request/feed-update.dto'; @Injectable() export class FeedService { @@ -36,13 +36,13 @@ export class FeedService { private readonly feedRepository: FeedRepository, private readonly feedViewRepository: FeedViewRepository, private readonly redisService: RedisService, - private readonly eventService: EventEmitter2, ) {} - async readFeedPagination(queryFeedDto: FeedPaginationRequestDto) { - const feedList = - await this.feedViewRepository.findFeedPagination(queryFeedDto); - const hasMore = this.existNextFeed(feedList, queryFeedDto.limit); + async readFeedPagination(feedPaginationQueryDto: FeedPaginationRequestDto) { + const feedList = await this.feedViewRepository.findFeedPagination( + feedPaginationQueryDto, + ); + const hasMore = this.existNextFeed(feedList, feedPaginationQueryDto.limit); if (hasMore) feedList.pop(); const lastId = this.getLastIdFromFeedList(feedList); const newCheckFeedList = await this.checkNewFeeds(feedList); @@ -94,8 +94,8 @@ export class FeedService { ); } - async searchFeedList(searchFeedReq: SearchFeedRequestDto) { - const { find, page, limit, type } = searchFeedReq; + async searchFeedList(searchFeedQueryDto: SearchFeedRequestDto) { + const { find, page, limit, type } = searchFeedQueryDto; const offset = (page - 1) * limit; if (!this.validateSearchType(type)) { @@ -131,15 +131,18 @@ export class FeedService { } async updateFeedViewCount( - feedId: number, + viewUpdateParamDto: FeedViewUpdateRequestDto, request: Request, response: Response, ) { const cookie = request.headers.cookie; const ip = this.getIp(request); + const feedId = viewUpdateParamDto.feedId; if (ip && this.isString(ip)) { const [feed, hasCookie, hasIpFlag] = await Promise.all([ - this.feedRepository.findOne({ where: { id: feedId } }), + this.feedRepository.findOne({ + where: { id: feedId }, + }), Boolean(cookie?.includes(`View_count_${feedId}=${feedId}`)), this.redisService.sismember(`feed:${feedId}:ip`, ip), ]); diff --git a/server/src/rss/controller/rss.controller.ts b/server/src/rss/controller/rss.controller.ts index 1ccc438..02a7340 100644 --- a/server/src/rss/controller/rss.controller.ts +++ b/server/src/rss/controller/rss.controller.ts @@ -28,8 +28,8 @@ export class RssController { @ApiCreateRss() @Post() - async createRss(@Body() rssRegisterDto: RssRegisterRequestDto) { - await this.rssService.createRss(rssRegisterDto); + async createRss(@Body() rssRegisterBodyDto: RssRegisterRequestDto) { + await this.rssService.createRss(rssRegisterBodyDto); return ApiResponse.responseWithNoContent('신청이 완료되었습니다.'); } @@ -47,8 +47,8 @@ export class RssController { @UseGuards(CookieAuthGuard) @Post('accept/:id') @HttpCode(201) - async acceptRss(@Param() params: RssManagementRequestDto) { - await this.rssService.acceptRss(params.id); + async acceptRss(@Param() rssAcceptParamDto: RssManagementRequestDto) { + await this.rssService.acceptRss(rssAcceptParamDto); return ApiResponse.responseWithNoContent('승인이 완료되었습니다.'); } @@ -57,10 +57,10 @@ export class RssController { @Post('reject/:id') @HttpCode(201) async rejectRss( - @Body() body: RejectRssRequestDto, - @Param() params: RssManagementRequestDto, + @Body() rssRejectBodyDto: RejectRssRequestDto, + @Param() rssRejectParamDto: RssManagementRequestDto, ) { - await this.rssService.rejectRss(params.id, body.description); + await this.rssService.rejectRss(rssRejectParamDto, rssRejectBodyDto); return ApiResponse.responseWithNoContent('거절이 완료되었습니다.'); } diff --git a/server/src/rss/service/rss.service.ts b/server/src/rss/service/rss.service.ts index c5fb8c2..52b1bd8 100644 --- a/server/src/rss/service/rss.service.ts +++ b/server/src/rss/service/rss.service.ts @@ -16,6 +16,8 @@ import { FeedCrawlerService } from './feed-crawler.service'; import { RssReadResponseDto } from '../dto/response/rss-all.dto'; import { RssAcceptHistoryResponseDto } from '../dto/response/rss-accept-history.dto'; import { RssRejectHistoryResponseDto } from '../dto/response/rss-reject-history.dto'; +import { RssManagementRequestDto } from '../dto/request/rss-management.dto'; +import { RejectRssRequestDto } from '../dto/request/rss-reject.dto'; @Injectable() export class RssService { @@ -28,16 +30,16 @@ export class RssService { private readonly feedCrawlerService: FeedCrawlerService, ) {} - async createRss(rssRegisterDto: RssRegisterRequestDto) { + async createRss(rssRegisterBodyDto: RssRegisterRequestDto) { const [alreadyURLRss, alreadyURLBlog] = await Promise.all([ this.rssRepository.findOne({ where: { - rssUrl: rssRegisterDto.rssUrl, + rssUrl: rssRegisterBodyDto.rssUrl, }, }), this.rssAcceptRepository.findOne({ where: { - rssUrl: rssRegisterDto.rssUrl, + rssUrl: rssRegisterBodyDto.rssUrl, }, }), ]); @@ -50,7 +52,7 @@ export class RssService { ); } - await this.rssRepository.insertNewRss(rssRegisterDto); + await this.rssRepository.insertNewRss(rssRegisterBodyDto); } async readAllRss() { @@ -58,9 +60,10 @@ export class RssService { return RssReadResponseDto.toResponseDtoArray(rssList); } - async acceptRss(id: number) { + async acceptRss(rssAcceptParamDto: RssManagementRequestDto) { + const rssId = rssAcceptParamDto.id; const rss = await this.rssRepository.findOne({ - where: { id }, + where: { id: rssId }, }); if (!rss) { @@ -73,7 +76,7 @@ export class RssService { async (manager) => { const [rssAccept] = await Promise.all([ manager.save(RssAccept.fromRss(rss, blogPlatform)), - manager.delete(Rss, id), + manager.delete(Rss, rssId), ]); const feeds = await this.feedCrawlerService.loadRssFeeds( rssAccept.rssUrl, @@ -85,9 +88,13 @@ export class RssService { this.emailService.sendMail(rssAccept, true); } - async rejectRss(id: number, description: string) { + async rejectRss( + rssRejectParamDto: RssManagementRequestDto, + rssRejectBodyDto: RejectRssRequestDto, + ) { + const rssId = rssRejectParamDto.id; const rss = await this.rssRepository.findOne({ - where: { id }, + where: { id: rssId }, }); if (!rss) { @@ -99,12 +106,12 @@ export class RssService { manager.remove(rss), manager.save(RssReject, { ...rss, - description, + description: rssRejectBodyDto.description, }), ]); return rejectRss; }); - this.emailService.sendMail(rejectRss, false, description); + this.emailService.sendMail(rejectRss, false, rssRejectBodyDto.description); } async readAcceptHistory() { diff --git a/server/src/statistic/controller/statistic.controller.ts b/server/src/statistic/controller/statistic.controller.ts index d1c7354..149d0ce 100644 --- a/server/src/statistic/controller/statistic.controller.ts +++ b/server/src/statistic/controller/statistic.controller.ts @@ -13,19 +13,19 @@ export class StatisticController { @ApiStatistic('today') @Get('today') - async readTodayStatistic(@Query() queryObj: StatisticRequestDto) { + async readTodayStatistic(@Query() statisticQueryDto: StatisticRequestDto) { return ApiResponse.responseWithData( '금일 조회수 통계 조회 완료', - await this.statisticService.readTodayStatistic(queryObj.limit), + await this.statisticService.readTodayStatistic(statisticQueryDto), ); } @ApiStatistic('all') @Get('all') - async readAllStatistic(@Query() queryObj: StatisticRequestDto) { + async readAllStatistic(@Query() statisticQueryDto: StatisticRequestDto) { return ApiResponse.responseWithData( '전체 조회수 통계 조회 완료', - await this.statisticService.readAllStatistic(queryObj.limit), + await this.statisticService.readAllStatistic(statisticQueryDto), ); } diff --git a/server/src/statistic/service/statistic.service.ts b/server/src/statistic/service/statistic.service.ts index 62d62c3..b8ad7d3 100644 --- a/server/src/statistic/service/statistic.service.ts +++ b/server/src/statistic/service/statistic.service.ts @@ -7,6 +7,7 @@ import { redisKeys } from '../../common/redis/redis.constant'; import { StatisticPlatformResponseDto } from '../dto/response/platform.dto'; import { StatisticTodayResponseDto } from '../dto/response/today.dto'; import { Feed } from '../../feed/entity/feed.entity'; +import { StatisticRequestDto } from '../dto/request/statistic-query.dto'; @Injectable() export class StatisticService { @@ -16,11 +17,11 @@ export class StatisticService { private readonly rssAcceptRepository: RssAcceptRepository, ) {} - async readTodayStatistic(limit: number) { + async readTodayStatistic(statisticQueryDto: StatisticRequestDto) { const ranking = await this.redisService.zrevrange( redisKeys.FEED_TREND_KEY, 0, - limit - 1, + statisticQueryDto.limit - 1, 'WITHSCORES', ); const todayFeedViews: Partial[] = []; @@ -44,9 +45,10 @@ export class StatisticService { return StatisticTodayResponseDto.toResponseDtoArray(todayFeedViews); } - async readAllStatistic(limit: number) { - const ranking = - await this.feedRepository.findAllStatisticsOrderByViewCount(limit); + async readAllStatistic(statisticQueryDto: StatisticRequestDto) { + const ranking = await this.feedRepository.findAllStatisticsOrderByViewCount( + statisticQueryDto.limit, + ); return StatisticAllResponseDto.toResponseDtoArray(ranking); } From 2c8938aaa67923867e1884d1d4d88436128434fc Mon Sep 17 00:00:00 2001 From: J_Coder Date: Mon, 13 Jan 2025 21:52:31 +0900 Subject: [PATCH 02/10] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20admin=20?= =?UTF-8?q?toEntity=EB=A5=BC=20=EC=9D=B4=EC=9A=A9=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=ED=95=84=EC=9A=94=EC=97=86=EB=8A=94=20Repository=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/admin/dto/request/register-admin.dto.ts | 8 ++++++++ server/src/admin/repository/admin.repository.ts | 11 ----------- server/src/admin/service/admin.service.ts | 11 ++++++----- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/server/src/admin/dto/request/register-admin.dto.ts b/server/src/admin/dto/request/register-admin.dto.ts index 73c28f7..76317eb 100644 --- a/server/src/admin/dto/request/register-admin.dto.ts +++ b/server/src/admin/dto/request/register-admin.dto.ts @@ -1,5 +1,6 @@ import { IsString, Length, Matches } from 'class-validator'; import { ApiProperty } from '@nestjs/swagger'; +import { Admin } from '../../entity/admin.entity'; const PASSWORD_REG = /^(?=.*[!@#$%^&*()_+])[A-Za-z0-9!@#$%^&*()_+]+$/; @@ -32,4 +33,11 @@ export class RegisterAdminRequestDto { message: '패스워드의 길이는 6자 이상, 60자 이하로 작성해주세요.', }) password: string; + + toEntity() { + const admin = new Admin(); + admin.loginId = this.loginId; + admin.password = this.password; + return admin; + } } diff --git a/server/src/admin/repository/admin.repository.ts b/server/src/admin/repository/admin.repository.ts index 207ad64..a7531dd 100644 --- a/server/src/admin/repository/admin.repository.ts +++ b/server/src/admin/repository/admin.repository.ts @@ -1,21 +1,10 @@ import { Injectable } from '@nestjs/common'; import { DataSource, Repository } from 'typeorm'; import { Admin } from '../entity/admin.entity'; -import { RegisterAdminRequestDto } from '../dto/request/register-admin.dto'; @Injectable() export class AdminRepository extends Repository { constructor(private dataSource: DataSource) { super(Admin, dataSource.createEntityManager()); } - - async createAdmin(registerAdminDto: RegisterAdminRequestDto) { - const { loginId, password } = registerAdminDto; - const admin = this.create({ - loginId, - password, - }); - await this.save(admin); - return admin; - } } diff --git a/server/src/admin/service/admin.service.ts b/server/src/admin/service/admin.service.ts index 7550708..e67521d 100644 --- a/server/src/admin/service/admin.service.ts +++ b/server/src/admin/service/admin.service.ts @@ -91,10 +91,8 @@ export class AdminService { } async createAdmin(registerAdminBodyDto: RegisterAdminRequestDto) { - let { loginId, password } = registerAdminBodyDto; - const existingAdmin = await this.adminRepository.findOne({ - where: { loginId }, + where: { loginId: registerAdminBodyDto.loginId }, }); if (existingAdmin) { @@ -102,8 +100,11 @@ export class AdminService { } const saltRounds = 10; - password = await bcrypt.hash(password, saltRounds); + registerAdminBodyDto.password = await bcrypt.hash( + registerAdminBodyDto.password, + saltRounds, + ); - await this.adminRepository.createAdmin({ loginId, password }); + await this.adminRepository.save(registerAdminBodyDto.toEntity()); } } From b984b7efe44663d22c853385302adb93206c0ab6 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Mon, 13 Jan 2025 22:05:37 +0900 Subject: [PATCH 03/10] =?UTF-8?q?=F0=9F=93=A6=20chore:=20bcrypt=20types=20?= =?UTF-8?q?=EC=84=A4=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/package-lock.json | 11 +++++++++++ server/package.json | 1 + 2 files changed, 12 insertions(+) diff --git a/server/package-lock.json b/server/package-lock.json index 8039178..0079b63 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -46,6 +46,7 @@ "@nestjs/cli": "^10.0.0", "@nestjs/schematics": "^10.0.0", "@nestjs/testing": "^10.0.0", + "@types/bcrypt": "^5.0.2", "@types/cookie-parser": "^1.4.7", "@types/eventsource": "^1.1.15", "@types/express": "^5.0.0", @@ -2589,6 +2590,16 @@ "@babel/types": "^7.20.7" } }, + "node_modules/@types/bcrypt": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@types/bcrypt/-/bcrypt-5.0.2.tgz", + "integrity": "sha512-6atioO8Y75fNcbmj0G7UjI9lXN2pQ/IGJ2FWT4a/btd0Lk9lQalHLKhkgKVZ3r+spnmWUKfbMi1GEe9wyHQfNQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/body-parser": { "version": "1.19.5", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz", diff --git a/server/package.json b/server/package.json index ad53e2e..61e153d 100644 --- a/server/package.json +++ b/server/package.json @@ -58,6 +58,7 @@ "@nestjs/cli": "^10.0.0", "@nestjs/schematics": "^10.0.0", "@nestjs/testing": "^10.0.0", + "@types/bcrypt": "^5.0.2", "@types/cookie-parser": "^1.4.7", "@types/eventsource": "^1.1.15", "@types/express": "^5.0.0", From 363315203ed86c1a9c632a10eb1141f35d020f10 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Mon, 13 Jan 2025 22:06:19 +0900 Subject: [PATCH 04/10] =?UTF-8?q?=F0=9F=A7=BC=20clean:=20toEntity=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EB=B3=80=EC=88=98=20=EB=8C=80=EC=9E=85=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=20-\>=20assign=20=EB=B0=A9=EC=8B=9D=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/admin/dto/request/register-admin.dto.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/src/admin/dto/request/register-admin.dto.ts b/server/src/admin/dto/request/register-admin.dto.ts index 76317eb..ceccf32 100644 --- a/server/src/admin/dto/request/register-admin.dto.ts +++ b/server/src/admin/dto/request/register-admin.dto.ts @@ -36,8 +36,7 @@ export class RegisterAdminRequestDto { toEntity() { const admin = new Admin(); - admin.loginId = this.loginId; - admin.password = this.password; + Object.assign(admin, this); return admin; } } From 78f7bc3575290009108436894647aa4e0f3844f2 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Mon, 13 Jan 2025 22:08:46 +0900 Subject: [PATCH 05/10] =?UTF-8?q?=E2=9C=85=20test:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20admin=20=ED=94=BD=EC=8A=A4=EC=B2=98=20=EB=B9=84?= =?UTF-8?q?=EB=B0=80=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=EC=8B=9C=20?= =?UTF-8?q?=EC=95=94=ED=98=B8=ED=99=94=EB=90=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/test/fixture/admin.fixture.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/test/fixture/admin.fixture.ts b/server/test/fixture/admin.fixture.ts index 123c7ec..ec90c5e 100644 --- a/server/test/fixture/admin.fixture.ts +++ b/server/test/fixture/admin.fixture.ts @@ -1,13 +1,18 @@ import { Admin } from '../../src/admin/entity/admin.entity'; +import * as bcrypt from 'bcrypt'; export class AdminFixture { static readonly GENERAL_ADMIN = { loginId: 'test1234', - password: '$2b$10$TGsf41ADKaziH5NgaDwec.JLue60QHk8DIZrFnJ9S6dZObN5humAe', // test1234! + password: 'test1234!', }; - static createAdminFixture(overwrites: Partial = {}): Admin { + static async createAdminFixture( + overwrites: Partial = {}, + ): Promise { const admin = new Admin(); Object.assign(admin, this.GENERAL_ADMIN); - return Object.assign(admin, overwrites); + Object.assign(admin, overwrites); + admin.password = await bcrypt.hash(admin.password, 10); + return admin; } } From 53b5df4178a5319a27c110c10a1c5f921dce84d7 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Mon, 13 Jan 2025 22:10:23 +0900 Subject: [PATCH 06/10] =?UTF-8?q?=E2=9C=85=20test:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=ED=94=BD=EC=8A=A4=EC=B2=98=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD,=20DTO=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/test/admin/e2e/login.e2e-spec.ts | 23 ++++++------ server/test/admin/e2e/register.e2e-spec.ts | 40 +++++++-------------- server/test/admin/e2e/sessionId.e2e-spec.ts | 16 ++++----- 3 files changed, 30 insertions(+), 49 deletions(-) diff --git a/server/test/admin/e2e/login.e2e-spec.ts b/server/test/admin/e2e/login.e2e-spec.ts index e80c1ff..770c47d 100644 --- a/server/test/admin/e2e/login.e2e-spec.ts +++ b/server/test/admin/e2e/login.e2e-spec.ts @@ -1,26 +1,22 @@ import { INestApplication } from '@nestjs/common'; -import { AdminService } from '../../../src/admin/service/admin.service'; import { LoginAdminRequestDto } from '../../../src/admin/dto/request/login-admin.dto'; import * as request from 'supertest'; -import { RegisterAdminRequestDto } from '../../../src/admin/dto/request/register-admin.dto'; +import { AdminRepository } from '../../../src/admin/repository/admin.repository'; +import { AdminFixture } from '../../fixture/admin.fixture'; describe('POST api/admin/login E2E Test', () => { let app: INestApplication; - let adminService: AdminService; - const registerAdminDto: RegisterAdminRequestDto = { - loginId: 'testAdminId', - password: 'testAdminPassword!', - }; beforeAll(async () => { app = global.testApp; - adminService = app.get(AdminService); - await adminService.createAdmin(registerAdminDto); + const adminRepository = app.get(AdminRepository); + await adminRepository.insert(await AdminFixture.createAdminFixture()); }); + it('등록된 계정이면 정상적으로 로그인할 수 있다.', async () => { //given const loginAdminDto: LoginAdminRequestDto = { - loginId: 'testAdminId', - password: 'testAdminPassword!', + loginId: 'test1234', + password: 'test1234!', }; //when @@ -37,7 +33,7 @@ describe('POST api/admin/login E2E Test', () => { //given const loginWrongAdminIdDto: LoginAdminRequestDto = { loginId: 'testWrongAdminId', - password: 'testAdminPassword!', + password: 'test1234!', }; //when @@ -52,9 +48,10 @@ describe('POST api/admin/login E2E Test', () => { it('비밀번호가 다르다면 401 UnAuthorized 예외가 발생한다.', async () => { //given const loginWrongAdminPasswordDto: LoginAdminRequestDto = { - loginId: 'testAdminId', + loginId: 'test1234', password: 'testWrongAdminPassword!', }; + //when const response = await request(app.getHttpServer()) .post('/api/admin/login') diff --git a/server/test/admin/e2e/register.e2e-spec.ts b/server/test/admin/e2e/register.e2e-spec.ts index 49bd4ab..054d5c9 100644 --- a/server/test/admin/e2e/register.e2e-spec.ts +++ b/server/test/admin/e2e/register.e2e-spec.ts @@ -1,28 +1,26 @@ import { INestApplication } from '@nestjs/common'; -import { AdminService } from '../../../src/admin/service/admin.service'; import { LoginAdminRequestDto } from '../../../src/admin/dto/request/login-admin.dto'; import { RegisterAdminRequestDto } from '../../../src/admin/dto/request/register-admin.dto'; import * as request from 'supertest'; +import { AdminFixture } from '../../fixture/admin.fixture'; +import { AdminRepository } from '../../../src/admin/repository/admin.repository'; describe('POST api/admin/register E2E Test', () => { let app: INestApplication; - let adminService: AdminService; - //given const loginAdminDto: LoginAdminRequestDto = { - loginId: 'testAdminId', - password: 'testAdminPassword!', - }; - const registerAdminDto: RegisterAdminRequestDto = { - loginId: 'testNewAdminId', - password: 'testNewAdminPassword!', + loginId: 'test1234', + password: 'test1234!', }; + const newAdminDto = new RegisterAdminRequestDto(); + newAdminDto.loginId = 'testNewAdminId'; + newAdminDto.password = 'testNewAdminPassword!'; + beforeAll(async () => { app = global.testApp; - adminService = app.get(AdminService); - - await adminService.createAdmin(loginAdminDto); + const adminRepository = app.get(AdminRepository); + await adminRepository.insert(await AdminFixture.createAdminFixture()); }); it('관리자가 로그인되어 있으면 다른 관리자 계정 회원가입을 할 수 있다.', async () => { @@ -31,9 +29,7 @@ describe('POST api/admin/register E2E Test', () => { //when await agent.post('/api/admin/login').send(loginAdminDto); - const response = await agent - .post('/api/admin/register') - .send(registerAdminDto); + const response = await agent.post('/api/admin/register').send(newAdminDto); //then expect(response.status).toBe(201); @@ -45,27 +41,17 @@ describe('POST api/admin/register E2E Test', () => { //when await agent.post('/api/admin/login').send(loginAdminDto); - const response = await agent - .post('/api/admin/register') - .send(registerAdminDto); + const response = await agent.post('/api/admin/register').send(newAdminDto); //then expect(response.status).toBe(409); }); it('관리자가 로그아웃 상태면 401 UnAuthorized 예외가 발생한다.', async () => { - //given - const registerAdminDto: RegisterAdminRequestDto = { - loginId: 'testNewAdminId', - password: 'testNewAdminPassword!', - }; - const agent = request.agent(app.getHttpServer()); //when - const response = await agent - .post('/api/admin/register') - .send(registerAdminDto); + const response = await agent.post('/api/admin/register').send(newAdminDto); //then expect(response.status).toBe(401); diff --git a/server/test/admin/e2e/sessionId.e2e-spec.ts b/server/test/admin/e2e/sessionId.e2e-spec.ts index ce7c4f1..2298975 100644 --- a/server/test/admin/e2e/sessionId.e2e-spec.ts +++ b/server/test/admin/e2e/sessionId.e2e-spec.ts @@ -1,24 +1,22 @@ import { INestApplication } from '@nestjs/common'; -import { AdminService } from '../../../src/admin/service/admin.service'; -import { LoginAdminRequestDto } from '../../../src/admin/dto/request/login-admin.dto'; import * as request from 'supertest'; import { v4 as uuidv4 } from 'uuid'; +import { LoginAdminRequestDto } from '../../../src/admin/dto/request/login-admin.dto'; +import { AdminRepository } from '../../../src/admin/repository/admin.repository'; +import { AdminFixture } from '../../fixture/admin.fixture'; describe('GET api/admin/sessionId E2E Test', () => { let app: INestApplication; - let adminService: AdminService; - //given const loginAdminDto: LoginAdminRequestDto = { - loginId: 'testAdminId', - password: 'testAdminPassword!', + loginId: 'test1234', + password: 'test1234!', }; beforeAll(async () => { app = global.testApp; - adminService = app.get(AdminService); - - await adminService.createAdmin(loginAdminDto); + const adminRepository = app.get(AdminRepository); + await adminRepository.insert(await AdminFixture.createAdminFixture()); }); it('쿠키의 session id가 유효하다면 관리자를 로그인 상태로 취급한다.', async () => { From f1c3c7070bf138dc92fa5bf1dac1d3d31fcec937 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Mon, 13 Jan 2025 23:52:17 +0900 Subject: [PATCH 07/10] =?UTF-8?q?=E2=9C=85=20test:=20admin=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=ED=94=BD=EC=8A=A4=EC=B2=98=20=EC=95=94?= =?UTF-8?q?=ED=98=B8=ED=99=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/test/fixture/admin.fixture.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/test/fixture/admin.fixture.ts b/server/test/fixture/admin.fixture.ts index ec90c5e..94a91cb 100644 --- a/server/test/fixture/admin.fixture.ts +++ b/server/test/fixture/admin.fixture.ts @@ -6,13 +6,18 @@ export class AdminFixture { loginId: 'test1234', password: 'test1234!', }; - static async createAdminFixture( - overwrites: Partial = {}, - ): Promise { + static async createAdminCryptFixture(overwrites: Partial = {}) { const admin = new Admin(); Object.assign(admin, this.GENERAL_ADMIN); Object.assign(admin, overwrites); admin.password = await bcrypt.hash(admin.password, 10); return admin; } + + static createAdminFixture(overwrites: Partial = {}) { + const admin = new Admin(); + Object.assign(admin, this.GENERAL_ADMIN); + Object.assign(admin, overwrites); + return admin; + } } From 242994cf6c45a67c31c501bc391e6dd8ebf793f3 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Mon, 13 Jan 2025 23:52:44 +0900 Subject: [PATCH 08/10] =?UTF-8?q?=E2=9C=85=20test:=20admin=20fixture=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=84=B1=20=EB=86=92=EC=9D=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/admin/dto/request/login-admin.dto.ts | 4 ++ .../admin/dto/request/register-admin.dto.ts | 4 ++ server/test/admin/dto/login-admin.dto.spec.ts | 23 +++++---- .../test/admin/dto/register-admin.dto.spec.ts | 47 ++++++++++++------- server/test/admin/e2e/login.e2e-spec.ts | 27 +++++------ server/test/admin/e2e/register.e2e-spec.ts | 18 +++---- server/test/admin/e2e/sessionId.e2e-spec.ts | 10 ++-- 7 files changed, 79 insertions(+), 54 deletions(-) diff --git a/server/src/admin/dto/request/login-admin.dto.ts b/server/src/admin/dto/request/login-admin.dto.ts index fb9facf..3b48b54 100644 --- a/server/src/admin/dto/request/login-admin.dto.ts +++ b/server/src/admin/dto/request/login-admin.dto.ts @@ -25,4 +25,8 @@ export class LoginAdminRequestDto { message: '문자열을 입력해주세요', }) password: string; + + constructor(partial: Partial) { + Object.assign(this, partial); + } } diff --git a/server/src/admin/dto/request/register-admin.dto.ts b/server/src/admin/dto/request/register-admin.dto.ts index ceccf32..7d2e58d 100644 --- a/server/src/admin/dto/request/register-admin.dto.ts +++ b/server/src/admin/dto/request/register-admin.dto.ts @@ -34,6 +34,10 @@ export class RegisterAdminRequestDto { }) password: string; + constructor(partial: Partial) { + Object.assign(this, partial); + } + toEntity() { const admin = new Admin(); Object.assign(admin, this); diff --git a/server/test/admin/dto/login-admin.dto.spec.ts b/server/test/admin/dto/login-admin.dto.spec.ts index e11335e..77a13bd 100644 --- a/server/test/admin/dto/login-admin.dto.spec.ts +++ b/server/test/admin/dto/login-admin.dto.spec.ts @@ -1,17 +1,16 @@ import { LoginAdminRequestDto } from '../../../src/admin/dto/request/login-admin.dto'; import { validate } from 'class-validator'; +import { AdminFixture } from '../../fixture/admin.fixture'; describe('LoginAdminDto Test', () => { - let loginAdminDto: LoginAdminRequestDto; - - beforeEach(() => { - loginAdminDto = new LoginAdminRequestDto(); - }); - it('ID에 null이 입력되면 유효성 검사에 실패한다.', async () => { //given - loginAdminDto.loginId = null; - loginAdminDto.password = 'testAdminPassword'; + const loginAdminDto = new LoginAdminRequestDto( + AdminFixture.createAdminFixture({ + loginId: null, + password: 'testAdminPassword', + }), + ); //when const errors = await validate(loginAdminDto); @@ -23,8 +22,12 @@ describe('LoginAdminDto Test', () => { }); it('패스워드에 null이 입력되면 유효성 검사에 실패한다.', async () => { //given - loginAdminDto.loginId = 'testAdminId'; - loginAdminDto.password = null; + const loginAdminDto = new LoginAdminRequestDto( + AdminFixture.createAdminFixture({ + loginId: 'testAdminId', + password: null, + }), + ); //when const errors = await validate(loginAdminDto); diff --git a/server/test/admin/dto/register-admin.dto.spec.ts b/server/test/admin/dto/register-admin.dto.spec.ts index f8ab6fc..be26e62 100644 --- a/server/test/admin/dto/register-admin.dto.spec.ts +++ b/server/test/admin/dto/register-admin.dto.spec.ts @@ -1,17 +1,16 @@ import { RegisterAdminRequestDto } from '../../../src/admin/dto/request/register-admin.dto'; import { validate } from 'class-validator'; +import { AdminFixture } from '../../fixture/admin.fixture'; describe('LoginAdminDto Test', () => { - let registerAdminDto: RegisterAdminRequestDto; - - beforeEach(() => { - registerAdminDto = new RegisterAdminRequestDto(); - }); - it('ID의 길이가 6 이상, 255 이하가 아니라면 유효성 검사에 실패한다.', async () => { //given - registerAdminDto.loginId = 'test'; - registerAdminDto.password = 'testAdminPassword!'; + const registerAdminDto = new RegisterAdminRequestDto( + AdminFixture.createAdminFixture({ + loginId: 'test', + password: 'testAdminPassword!', + }), + ); //when const errors = await validate(registerAdminDto); @@ -23,8 +22,12 @@ describe('LoginAdminDto Test', () => { it('패스워드의 길이가 6 이상, 60 이하가 아니라면 유효성 검사에 실패한다.', async () => { //given - registerAdminDto.loginId = 'testId'; - registerAdminDto.password = 'test'; + const registerAdminDto = new RegisterAdminRequestDto( + AdminFixture.createAdminFixture({ + loginId: 'testId', + password: 'test', + }), + ); //when const errors = await validate(registerAdminDto); @@ -36,8 +39,12 @@ describe('LoginAdminDto Test', () => { it('패스워드에 특수문자가 하나 이상 없다면 유효성 검사에 실패한다.', async () => { //given - registerAdminDto.loginId = 'testAdminId'; - registerAdminDto.password = 'testAdminPassword'; + const registerAdminDto = new RegisterAdminRequestDto( + AdminFixture.createAdminFixture({ + loginId: 'testAdminId', + password: 'testAdminPassword', + }), + ); //when const errors = await validate(registerAdminDto); @@ -49,8 +56,12 @@ describe('LoginAdminDto Test', () => { it('ID에 null이 입력되면 유효성 검사에 실패한다.', async () => { //given - registerAdminDto.loginId = null; - registerAdminDto.password = 'testAdminPassword!'; + const registerAdminDto = new RegisterAdminRequestDto( + AdminFixture.createAdminFixture({ + loginId: null, + password: 'testAdminPassword!', + }), + ); //when const errors = await validate(registerAdminDto); @@ -62,8 +73,12 @@ describe('LoginAdminDto Test', () => { it('패스워드에 null이 입력되면 유효성 검사에 실패한다.', async () => { //given - registerAdminDto.loginId = 'testAdminId'; - registerAdminDto.password = null; + const registerAdminDto = new RegisterAdminRequestDto( + AdminFixture.createAdminFixture({ + loginId: 'testAdminId', + password: null, + }), + ); //when const errors = await validate(registerAdminDto); diff --git a/server/test/admin/e2e/login.e2e-spec.ts b/server/test/admin/e2e/login.e2e-spec.ts index 770c47d..13ac02b 100644 --- a/server/test/admin/e2e/login.e2e-spec.ts +++ b/server/test/admin/e2e/login.e2e-spec.ts @@ -1,23 +1,22 @@ +import { AdminFixture } from './../../fixture/admin.fixture'; import { INestApplication } from '@nestjs/common'; import { LoginAdminRequestDto } from '../../../src/admin/dto/request/login-admin.dto'; import * as request from 'supertest'; import { AdminRepository } from '../../../src/admin/repository/admin.repository'; -import { AdminFixture } from '../../fixture/admin.fixture'; describe('POST api/admin/login E2E Test', () => { let app: INestApplication; beforeAll(async () => { app = global.testApp; const adminRepository = app.get(AdminRepository); - await adminRepository.insert(await AdminFixture.createAdminFixture()); + await adminRepository.insert(await AdminFixture.createAdminCryptFixture()); }); it('등록된 계정이면 정상적으로 로그인할 수 있다.', async () => { //given - const loginAdminDto: LoginAdminRequestDto = { - loginId: 'test1234', - password: 'test1234!', - }; + const loginAdminDto = new LoginAdminRequestDto( + AdminFixture.createAdminFixture(), + ); //when const response = await request(app.getHttpServer()) @@ -31,10 +30,9 @@ describe('POST api/admin/login E2E Test', () => { it('등록되지 않은 ID로 로그인을 시도하면 401 UnAuthorized 예외가 발생한다.', async () => { //given - const loginWrongAdminIdDto: LoginAdminRequestDto = { - loginId: 'testWrongAdminId', - password: 'test1234!', - }; + const loginWrongAdminIdDto = new LoginAdminRequestDto( + AdminFixture.createAdminFixture({ loginId: 'testWrongAdminId' }), + ); //when const response = await request(app.getHttpServer()) @@ -47,10 +45,11 @@ describe('POST api/admin/login E2E Test', () => { it('비밀번호가 다르다면 401 UnAuthorized 예외가 발생한다.', async () => { //given - const loginWrongAdminPasswordDto: LoginAdminRequestDto = { - loginId: 'test1234', - password: 'testWrongAdminPassword!', - }; + const loginWrongAdminPasswordDto = new LoginAdminRequestDto( + AdminFixture.createAdminFixture({ + password: 'testWrongAdminPassword!', + }), + ); //when const response = await request(app.getHttpServer()) diff --git a/server/test/admin/e2e/register.e2e-spec.ts b/server/test/admin/e2e/register.e2e-spec.ts index 054d5c9..32b5133 100644 --- a/server/test/admin/e2e/register.e2e-spec.ts +++ b/server/test/admin/e2e/register.e2e-spec.ts @@ -8,19 +8,21 @@ import { AdminRepository } from '../../../src/admin/repository/admin.repository' describe('POST api/admin/register E2E Test', () => { let app: INestApplication; - const loginAdminDto: LoginAdminRequestDto = { - loginId: 'test1234', - password: 'test1234!', - }; + const loginAdminDto = new LoginAdminRequestDto( + AdminFixture.createAdminFixture(), + ); - const newAdminDto = new RegisterAdminRequestDto(); - newAdminDto.loginId = 'testNewAdminId'; - newAdminDto.password = 'testNewAdminPassword!'; + const newAdminDto = new RegisterAdminRequestDto( + AdminFixture.createAdminFixture({ + loginId: 'testNewAdminId', + password: 'testNewAdminPassword!', + }), + ); beforeAll(async () => { app = global.testApp; const adminRepository = app.get(AdminRepository); - await adminRepository.insert(await AdminFixture.createAdminFixture()); + await adminRepository.insert(await AdminFixture.createAdminCryptFixture()); }); it('관리자가 로그인되어 있으면 다른 관리자 계정 회원가입을 할 수 있다.', async () => { diff --git a/server/test/admin/e2e/sessionId.e2e-spec.ts b/server/test/admin/e2e/sessionId.e2e-spec.ts index 2298975..06cace0 100644 --- a/server/test/admin/e2e/sessionId.e2e-spec.ts +++ b/server/test/admin/e2e/sessionId.e2e-spec.ts @@ -8,20 +8,18 @@ import { AdminFixture } from '../../fixture/admin.fixture'; describe('GET api/admin/sessionId E2E Test', () => { let app: INestApplication; - const loginAdminDto: LoginAdminRequestDto = { - loginId: 'test1234', - password: 'test1234!', - }; - beforeAll(async () => { app = global.testApp; const adminRepository = app.get(AdminRepository); - await adminRepository.insert(await AdminFixture.createAdminFixture()); + await adminRepository.insert(await AdminFixture.createAdminCryptFixture()); }); it('쿠키의 session id가 유효하다면 관리자를 로그인 상태로 취급한다.', async () => { //given const agent = request.agent(app.getHttpServer()); + const loginAdminDto = new LoginAdminRequestDto( + AdminFixture.createAdminFixture(), + ); //when await agent.post('/api/admin/login').send(loginAdminDto); From 2229629016c870fedfe1fa8f30d30611b02362d6 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Tue, 14 Jan 2025 15:33:02 +0900 Subject: [PATCH 09/10] =?UTF-8?q?=E2=9C=85=20test:=20admin=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=ED=94=BD=EC=8A=A4=EC=B2=98=20hash=20round?= =?UTF-8?q?=201=ED=9A=8C=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/test/fixture/admin.fixture.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/test/fixture/admin.fixture.ts b/server/test/fixture/admin.fixture.ts index 94a91cb..1c305bd 100644 --- a/server/test/fixture/admin.fixture.ts +++ b/server/test/fixture/admin.fixture.ts @@ -10,7 +10,7 @@ export class AdminFixture { const admin = new Admin(); Object.assign(admin, this.GENERAL_ADMIN); Object.assign(admin, overwrites); - admin.password = await bcrypt.hash(admin.password, 10); + admin.password = await bcrypt.hash(admin.password, 1); return admin; } From 16a182b02cc1bad97e0c93bfa50cfb1a152fba49 Mon Sep 17 00:00:00 2001 From: J_Coder Date: Tue, 14 Jan 2025 18:34:54 +0900 Subject: [PATCH 10/10] =?UTF-8?q?=E2=9C=85=20test:=20dto=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20object=20literal=20=EB=B0=A9=EC=8B=9D=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/test/admin/e2e/login.e2e-spec.ts | 23 +++++++++++---------- server/test/admin/e2e/register.e2e-spec.ts | 19 ++++++++--------- server/test/admin/e2e/sessionId.e2e-spec.ts | 7 ++++--- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/server/test/admin/e2e/login.e2e-spec.ts b/server/test/admin/e2e/login.e2e-spec.ts index 13ac02b..ba0546a 100644 --- a/server/test/admin/e2e/login.e2e-spec.ts +++ b/server/test/admin/e2e/login.e2e-spec.ts @@ -14,9 +14,10 @@ describe('POST api/admin/login E2E Test', () => { it('등록된 계정이면 정상적으로 로그인할 수 있다.', async () => { //given - const loginAdminDto = new LoginAdminRequestDto( - AdminFixture.createAdminFixture(), - ); + const loginAdminDto = new LoginAdminRequestDto({ + loginId: 'test1234', + password: 'test1234!', + }); //when const response = await request(app.getHttpServer()) @@ -30,9 +31,10 @@ describe('POST api/admin/login E2E Test', () => { it('등록되지 않은 ID로 로그인을 시도하면 401 UnAuthorized 예외가 발생한다.', async () => { //given - const loginWrongAdminIdDto = new LoginAdminRequestDto( - AdminFixture.createAdminFixture({ loginId: 'testWrongAdminId' }), - ); + const loginWrongAdminIdDto = new LoginAdminRequestDto({ + loginId: 'testWrongAdminId', + password: 'test1234!', + }); //when const response = await request(app.getHttpServer()) @@ -45,11 +47,10 @@ describe('POST api/admin/login E2E Test', () => { it('비밀번호가 다르다면 401 UnAuthorized 예외가 발생한다.', async () => { //given - const loginWrongAdminPasswordDto = new LoginAdminRequestDto( - AdminFixture.createAdminFixture({ - password: 'testWrongAdminPassword!', - }), - ); + const loginWrongAdminPasswordDto = new LoginAdminRequestDto({ + loginId: 'test1234', + password: 'testWrongAdminPassword!', + }); //when const response = await request(app.getHttpServer()) diff --git a/server/test/admin/e2e/register.e2e-spec.ts b/server/test/admin/e2e/register.e2e-spec.ts index 32b5133..ebf40aa 100644 --- a/server/test/admin/e2e/register.e2e-spec.ts +++ b/server/test/admin/e2e/register.e2e-spec.ts @@ -8,16 +8,15 @@ import { AdminRepository } from '../../../src/admin/repository/admin.repository' describe('POST api/admin/register E2E Test', () => { let app: INestApplication; - const loginAdminDto = new LoginAdminRequestDto( - AdminFixture.createAdminFixture(), - ); - - const newAdminDto = new RegisterAdminRequestDto( - AdminFixture.createAdminFixture({ - loginId: 'testNewAdminId', - password: 'testNewAdminPassword!', - }), - ); + const loginAdminDto = new LoginAdminRequestDto({ + loginId: 'test1234', + password: 'test1234!', + }); + + const newAdminDto = new RegisterAdminRequestDto({ + loginId: 'testNewAdminId', + password: 'testNewAdminPassword!', + }); beforeAll(async () => { app = global.testApp; diff --git a/server/test/admin/e2e/sessionId.e2e-spec.ts b/server/test/admin/e2e/sessionId.e2e-spec.ts index 06cace0..378ecb9 100644 --- a/server/test/admin/e2e/sessionId.e2e-spec.ts +++ b/server/test/admin/e2e/sessionId.e2e-spec.ts @@ -17,9 +17,10 @@ describe('GET api/admin/sessionId E2E Test', () => { it('쿠키의 session id가 유효하다면 관리자를 로그인 상태로 취급한다.', async () => { //given const agent = request.agent(app.getHttpServer()); - const loginAdminDto = new LoginAdminRequestDto( - AdminFixture.createAdminFixture(), - ); + const loginAdminDto = new LoginAdminRequestDto({ + loginId: 'test1234', + password: 'test1234!', + }); //when await agent.post('/api/admin/login').send(loginAdminDto);