-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add mock handlers for question API
- Loading branch information
1 parent
1eec860
commit 5984c8d
Showing
3 changed files
with
57 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,63 @@ | ||
//NOTE: 로그인 실패 -> 회원 가입 로직 | ||
// import {faker} from '@faker-js/faker'; | ||
import {http, HttpResponse} from 'msw'; | ||
import {http, HttpResponse, PathParams} from 'msw'; | ||
|
||
import {getApiUrl} from '../utils/api'; | ||
|
||
import {ResponseGetQuestion} from '@/api/quetion'; | ||
import { | ||
BodyPatchAnswer, | ||
BodyPostAnswer, | ||
ParamPatchAnswer, | ||
ResponseGetQuestion, | ||
} from '@/api/quetion'; | ||
import {questionApis} from '@/api/routes'; | ||
import {verifyFakeJWT} from '@/mocks/utils/token'; | ||
import {Answer, Question} from '@/types'; | ||
|
||
export default [ | ||
http.get(getApiUrl(questionApis.getQuestion), ({request}) => { | ||
const Authorized = request.headers.get('Authorization'); | ||
if (Authorized === null) { | ||
return new HttpResponse(null, { | ||
status: 401, | ||
statusText: 'Unauthorized', | ||
}); | ||
} | ||
|
||
const [, accessToken] = Authorized.split(' '); | ||
if (!verifyFakeJWT(accessToken)) { | ||
return new HttpResponse(null, { | ||
status: 403, | ||
statusText: 'Forbidden', | ||
}); | ||
} | ||
const question: Question[] = [ | ||
{questionHistoryId: 0, question: '지금 이 순간 제일 듣고 싶은 단어는?'}, | ||
]; | ||
const answer: Answer[] = []; | ||
|
||
return HttpResponse.json({ | ||
question: '오늘의 질문 입니다!', | ||
} as ResponseGetQuestion); | ||
export default [ | ||
http.get(getApiUrl(questionApis.getQuestion), () => { | ||
const response = { | ||
...question[0], | ||
isAnswered: false, | ||
}; | ||
return HttpResponse.json<ResponseGetQuestion>(response, {status: 200}); | ||
}), | ||
http.post<PathParams, BodyPostAnswer>( | ||
getApiUrl(questionApis.postAnswer), | ||
async ({request}) => { | ||
const body = await request.json(); | ||
answer[0] = { | ||
nickname: 'fake nickname', | ||
groupRole: 'SON', | ||
emoji: null, | ||
content: body.answer, | ||
createAt: new Date(), | ||
}; | ||
}, | ||
), | ||
http.get(getApiUrl(questionApis.getAnswer), () => { | ||
const response = { | ||
answer: answer, | ||
}; | ||
return HttpResponse.json(response, {status: 200}); | ||
}), | ||
http.patch<ParamPatchAnswer, BodyPatchAnswer>( | ||
getApiUrl(questionApis.patchAnser), | ||
async ({request}) => { | ||
const body = await request.json(); | ||
answer[0].content = body.answer; | ||
return HttpResponse.json(null, {status: 200}); | ||
}, | ||
), | ||
http.get(getApiUrl(questionApis.getList), () => { | ||
const response = { | ||
question, | ||
}; | ||
return HttpResponse.json(response, {status: 200}); | ||
}), | ||
http.post(getApiUrl(questionApis.cheerUp), () => { | ||
return HttpResponse.json(null, {status: 200}); | ||
}), | ||
]; |
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