一键导入
ballog-msw-template
Ballog MSW handler/data 생성 템플릿과 handlers.ts 레지스트리 삽입 규칙. /feat-new 가 참조.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Ballog MSW handler/data 생성 템플릿과 handlers.ts 레지스트리 삽입 규칙. /feat-new 가 참조.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Ballog entity 슬라이스 생성 템플릿. ky API 그룹, query-key-factory 등록, query/mutation 훅 네이밍과 invalidation 규칙. /feat-new 가 참조.
Ballog(apps/web) FSD 레이어 규칙. 의존 방향, public API, import 순서, 네이밍. 파일 생성/리뷰 시 경계 위반 검증에 사용.
Ballog 커밋 및 PR 메시지 컨벤션. 이모지 prefix(✨Feat/💄Style/✏️Fix)와 fix:/feat: 간결 스타일 혼용 규칙, 한국어 PR 본문 작성 틀. /review-pr 이 참조.
/feat-new 가 읽는 Ballog API 명세 MD의 YAML 스키마 정의. endpoints/types/msw/figma 필드와 작성 규칙. spec 파일 작성이나 파싱할 때 참조.
Ballog 프로젝트의 Tailwind + cn() 사용 규칙. 조건부 클래스 가독성, twMerge 충돌 회피, 반복 유틸 추출 기준. className을 작성하거나 리뷰할 때 참조.
| name | ballog-msw-template |
| description | Ballog MSW handler/data 생성 템플릿과 handlers.ts 레지스트리 삽입 규칙. /feat-new 가 참조. |
기준 파일: apps/web/src/mocks/handlers/authHandlers.ts, apps/web/src/mocks/data/auth.ts
apps/web/src/mocks/
├── handlers.ts (수정 — 레지스트리)
├── handlers/
│ └── <camel>Handlers.ts (생성)
└── data/
└── <camel>.ts (생성)
handlers/<camel>Handlers.tsimport { http, HttpResponse, delay } from 'msw'
import type {
CreateEmotionRequestDTO,
EmotionResponseDTO,
} from '@/entities/emotion/model/emotion.type'
import type { ApiErrorMessage } from '@/types/api/common'
import { emotion } from '@/mocks/data/emotion'
const EMOTION_API_PREFIX = `${import.meta.env.VITE_PUBLIC_API_URL}/api/v1/emotion`
export const emotionHandlers = [
http.get<
{ matchRecordId: string },
never,
EmotionResponseDTO | ApiErrorMessage
>(`${EMOTION_API_PREFIX}/:matchRecordId`, async () => {
await delay(emotion.delay)
return HttpResponse.json<EmotionResponseDTO>({ data: emotion.records })
}),
http.post<
never,
CreateEmotionRequestDTO,
EmotionResponseDTO | ApiErrorMessage
>(EMOTION_API_PREFIX, async ({ request }) => {
const body = await request.json()
await delay(emotion.delay)
// msw.scenarios[*] 의 when 분기
if (body.matchRecordId === 0) {
return HttpResponse.json<ApiErrorMessage>(
{
error: 'invalid match',
status: 400,
code: 'INVALID_MATCH',
message: 'invalid match',
},
{ status: 400 },
)
}
return HttpResponse.json<EmotionResponseDTO>({ data: emotion.records })
}),
]
핵심:
<camel>Handlershttp.<method> 제네릭: <PathParams, RequestBody, ResponseBody>${VITE_PUBLIC_API_URL}/api/v1/<path-root>delay 는 data 파일의 delay 필드를 참조 (일관성)data/<camel>.tsimport type { Emotion } from '@/entities/emotion/model/emotion.type'
export const emotion: {
delay: number
records: Emotion[]
} = {
delay: 1500,
records: [
{ id: 1, type: 'HAPPY', createdAt: '2024-01-01T00:00:00Z' },
],
}
<camel> (도메인명 그대로)handlers.ts 레지스트리 수정실제 파일 예시 (순서는 append-order, 알파벳 아님):
import { authHandlers } from './handlers/authHandlers'
import { matchHandlers } from './handlers/matchHandlers'
import { emotionHandlers } from './handlers/emotionHandlers'
import { userHandlers } from './handlers/userHandlers'
// ...
export const handlers = [
...authHandlers,
...matchHandlers,
...emotionHandlers,
// ...
]
삽입 규칙:
import { ...Handlers } from './handlers/...' 줄 다음에 import { <camel>Handlers } from './handlers/<camel>Handlers' 추가...xxxHandlers, 줄 다음에 ...<camel>Handlers, 추가pnpm lint --fix — import 순서는 이 파일 형태상 재정렬되지 않음 (동일 상대경로 그룹). 안전.구현은 AST 아닌 Edit 기반 문자열 삽입으로. 마지막 import 줄 / export const handlers = [ 블록 닫는 ] 을 anchor로 잡아 말미 삽입.
handlers.ts 에 등록 누락 → mock 동작 안 함http.get<...>) → 타입 안전성 손실delay 하드코딩 (data 파일 참조 없이) → 일관성 깨짐