diff --git a/src/mocks/handlers/auth.ts b/src/mocks/handlers/auth.ts index 5f2a347..1f2d0e4 100644 --- a/src/mocks/handlers/auth.ts +++ b/src/mocks/handlers/auth.ts @@ -2,14 +2,15 @@ // import {faker} from '@faker-js/faker'; import {http, HttpResponse} from 'msw'; +import {getApiUrl} from '../utils/api'; + import {RequestSignIn, RequestSignUp, ResponseToken} from '@/api/auth'; import {authApis} from '@/api/routes'; -import {API_BASE_URL} from '@/constants/api'; import {createUser} from '@/mocks/fakers'; import {createFakeJWT} from '@/mocks/utils/token'; export default [ - http.post(API_BASE_URL + authApis.signIn, async ({request}) => { + http.post(getApiUrl(authApis.signIn), async ({request}) => { const body = (await request.json()) as Partial; const {OAuthProvider, AuthorizationCode} = body; const oauthAgent = ['NATIVE', 'GOOGLE', 'NAVER', 'KAKAO', 'APPLE']; @@ -48,13 +49,13 @@ export default [ grantType: 'Bearer', } as ResponseToken); }), - http.get(API_BASE_URL + authApis.signOut, () => { + http.get(getApiUrl(authApis.signOut), () => { return new HttpResponse(null, { status: 204, statusText: 'No Content', }); }), - http.post(API_BASE_URL + authApis.signUp, async ({request}) => { + http.post(getApiUrl(authApis.signUp), async ({request}) => { const body = (await request.json()) as RequestSignUp; if ( !( diff --git a/src/mocks/handlers/question.ts b/src/mocks/handlers/question.ts index 27cd777..617c974 100644 --- a/src/mocks/handlers/question.ts +++ b/src/mocks/handlers/question.ts @@ -2,13 +2,14 @@ // import {faker} from '@faker-js/faker'; import {http, HttpResponse} from 'msw'; +import {getApiUrl} from '../utils/api'; + import {ResponseGetQuestion} from '@/api/quetion'; import {questionApis} from '@/api/routes'; -import {API_BASE_URL} from '@/constants/api'; import {verifyFakeJWT} from '@/mocks/utils/token'; export default [ - http.get(API_BASE_URL + questionApis.getQuestion, ({request}) => { + http.get(getApiUrl(questionApis.getQuestion), ({request}) => { const Authorized = request.headers.get('Authorization'); if (Authorized === null) { return new HttpResponse(null, { diff --git a/src/mocks/utils/api.ts b/src/mocks/utils/api.ts new file mode 100644 index 0000000..e0d9ccc --- /dev/null +++ b/src/mocks/utils/api.ts @@ -0,0 +1,5 @@ +import {API_BASE_URL} from '@/constants/api'; + +export function getApiUrl(path: string) { + return `${API_BASE_URL}/${path}`; +}