-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(#191): playwright 설치하기 * feat(#191): playwright로 간단히 테스트해보기 * refactor(#191): mock 변경 사항 반영 및 불필요한 resolver 제거 및 resolver 함수명 통일하기 * refactor(#191): mock history 불필요한 함수 제거 및 DTO 적용하기 * refactor(#191): mock lotus 제목 검색 로직 추가하기 * refactor(#191): mocking 시에 페이지네이션 max 값도 계산하기 * refactor(#191): user에 대한 MockRepository 적용하기 * refactor(#191): 테스트를 위한 data-testid값을 부여 * fix(#191): lotus 삭제 시 오류 수정하기 * refactor(#191): app 레이어로 테스트 코드 이동 및 e2e 테스트 코드 작성완료 * refactor(#204): mock 코드를 controller와 repository로 분리하기 * refactor(#204): lotus 생성 mocking 시에 유저 레포지토리로 유저 데이터 관리하도록 변경하기 * refactor(#204): mocking 시에 findLotusDetail을 repository에서 controller로 변경하기 * fix(#204): fe ci 오류 해결하기
- Loading branch information
Showing
13 changed files
with
563 additions
and
625 deletions.
There are no files selected for viewing
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
File renamed without changes.
93 changes: 93 additions & 0 deletions
93
apps/frontend/src/app/mock/controller/historyController.ts
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { DefaultBodyType, HttpResponse, PathParams, StrictRequest } from 'msw'; | ||
import { historyRepository } from '@/app/mock/repository/historyRepository'; | ||
|
||
// Lotus History 목록 조회 | ||
export const getHistoryList = async ({ | ||
request, | ||
params | ||
}: { | ||
request: StrictRequest<DefaultBodyType>; | ||
params: PathParams; | ||
}) => { | ||
const { lotusId } = params; | ||
|
||
const url = new URL(request.url); | ||
const page = Number(url.searchParams.get('page')) || 1; | ||
|
||
if (!lotusId) { | ||
return new HttpResponse('Bad Request', { | ||
status: 400, | ||
headers: { | ||
'Content-Type': 'text/plain' | ||
} | ||
}); | ||
} | ||
const { data, maxPage: max } = await historyRepository.findMany({ page }); | ||
const list = data.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()); | ||
|
||
return HttpResponse.json({ | ||
list, | ||
page: { | ||
current: page, | ||
max | ||
} | ||
}); | ||
}; | ||
|
||
// 코드 실행 | ||
interface PostCodeRunBody { | ||
input?: string; | ||
execFileName: string; | ||
} | ||
|
||
export const postCodeRun = async ({ request }: { request: StrictRequest<DefaultBodyType> }) => { | ||
const body = (await request.json()) as PostCodeRunBody; | ||
|
||
if (!body?.execFileName) | ||
return new HttpResponse('Bad Request', { | ||
status: 400, | ||
headers: { | ||
'Content-Type': 'text/plain' | ||
} | ||
}); | ||
|
||
const newHistory = await historyRepository.create({ | ||
filename: body.execFileName, | ||
date: new Date().toISOString(), | ||
status: 'PENDING', | ||
input: body?.input ?? '', | ||
output: '' | ||
}); | ||
|
||
setTimeout(() => { | ||
historyRepository.update( | ||
{ id: newHistory.id }, | ||
{ | ||
status: 'SUCCESS', | ||
output: `입력한 값: ${newHistory.input} ` | ||
} | ||
); | ||
}, 2000); | ||
|
||
return HttpResponse.json({ | ||
status: newHistory.status | ||
}); | ||
}; | ||
|
||
// 해당 히스토리 정보 | ||
export const getHistory = async ({ params }: { params: PathParams }) => { | ||
const { lotusId, historyId } = params; | ||
|
||
if (!lotusId || !historyId) { | ||
return new HttpResponse('Bad Request', { | ||
status: 400, | ||
headers: { | ||
'Content-Type': 'text/plain' | ||
} | ||
}); | ||
} | ||
|
||
const history = await historyRepository.findOne({ id: historyId as string }); | ||
|
||
return HttpResponse.json(history); | ||
}; |
129 changes: 129 additions & 0 deletions
129
apps/frontend/src/app/mock/controller/lotusController.ts
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 |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { DefaultBodyType, HttpResponse, PathParams, StrictRequest } from 'msw'; | ||
import { lotusMockFileData, lotusRepository } from '@/app/mock/repository/lotusRepository'; | ||
import { userRepository } from '@/app/mock/repository/userRepository'; | ||
import { LotusDto } from '@/feature/lotus'; | ||
|
||
const MOCK_UUID = 'mock-uuid'; | ||
|
||
// 사용자의 Lotus 목록 조회 | ||
export const getUserLotusList = async ({ request }: { request: StrictRequest<DefaultBodyType> }) => { | ||
const authorization = request.headers.get('Authorization'); | ||
|
||
const [type, token] = authorization?.split(' ') || []; | ||
|
||
if (token !== MOCK_UUID || type !== 'Bearer') { | ||
return new HttpResponse('Unauthorized: Invalid or missing token', { | ||
status: 401, | ||
headers: { | ||
'Content-Type': 'text/plain' | ||
} | ||
}); | ||
} | ||
|
||
const url = new URL(request.url); | ||
const page = Number(url.searchParams.get('page')) || 1; | ||
const size = Number(url.searchParams.get('size')) || 5; | ||
|
||
const { data: lotuses, maxPage: max } = await lotusRepository.findMany({ page, size }); | ||
|
||
return HttpResponse.json({ | ||
lotuses, | ||
page: { | ||
current: page, | ||
max | ||
} | ||
}); | ||
}; | ||
|
||
// public lotus 목록 조회 | ||
export const getPublicLotusList = async ({ request }: { request: StrictRequest<DefaultBodyType> }) => { | ||
const url = new URL(request.url); | ||
const page = Number(url.searchParams.get('page')) || 1; | ||
const size = Number(url.searchParams.get('size')) || 5; | ||
const search = url.searchParams.get('search') || ''; | ||
|
||
const { data: lotuses, maxPage: max } = await lotusRepository.search({ | ||
query: { title: search, isPublic: true }, | ||
page, | ||
size | ||
}); | ||
|
||
return HttpResponse.json({ | ||
lotuses, | ||
page: { | ||
current: page, | ||
max | ||
} | ||
}); | ||
}; | ||
|
||
// public lotus 상세 조회 | ||
export const getLotusDetail = async ({ params }: { params: Record<string, string> }) => { | ||
const lotusId = params.lotusId; | ||
|
||
const lotus = await lotusRepository.findOne({ id: lotusId }); | ||
|
||
return HttpResponse.json({ ...lotus, ...lotusMockFileData }); | ||
}; | ||
|
||
type CreateLotusDto = { | ||
title: string; | ||
isPublic: false; | ||
tags: string[]; | ||
gistUuid: string; | ||
}; | ||
|
||
//lotus 생성 | ||
export const postCreateLotus = async ({ request }: { request: StrictRequest<DefaultBodyType> }) => { | ||
const body = (await request.json()) as CreateLotusDto; | ||
|
||
const author = await userRepository.findOne({ id: '0' }); | ||
|
||
const lotus = await lotusRepository.create({ | ||
...body, | ||
date: new Date().toISOString(), | ||
author, | ||
logo: '/image/exampleImage.jpeg', | ||
link: 'https://devblog.com/articles/1000000001', | ||
isPublic: false, | ||
gistUrl: '' | ||
}); | ||
|
||
return HttpResponse.json(lotus); | ||
}; | ||
|
||
// lotus 수정 | ||
export const patchLotus = async ({ | ||
params, | ||
request | ||
}: { | ||
params: PathParams; | ||
request: StrictRequest<DefaultBodyType>; | ||
}) => { | ||
const { id } = params; | ||
|
||
const body = (await request.json()) as Partial<LotusDto>; | ||
|
||
if (!id || typeof id !== 'string') return HttpResponse.json({ message: 'id is required' }); | ||
|
||
const lotus = await lotusRepository.findOne({ id }); | ||
|
||
const updatedLotus = await lotusRepository.update(lotus, body); | ||
|
||
return HttpResponse.json(updatedLotus); | ||
}; | ||
|
||
// lotus 삭제 | ||
export const deleteLotus = async ({ params }: { params: PathParams }) => { | ||
const { id } = params; | ||
|
||
if (!id || typeof id !== 'string') return HttpResponse.json({ message: 'id is required' }); | ||
|
||
const lotus = await lotusRepository.findOne({ | ||
id | ||
}); | ||
|
||
await lotusRepository.delete(lotus); | ||
|
||
return HttpResponse.json(lotus); | ||
}; |
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
Oops, something went wrong.