Skip to content

Commit

Permalink
refactor: create mock api url maker
Browse files Browse the repository at this point in the history
  • Loading branch information
timepresent95 committed Aug 20, 2024
1 parent f52c2c5 commit 4b4b59c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/mocks/handlers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RequestSignIn>;
const {OAuthProvider, AuthorizationCode} = body;
const oauthAgent = ['NATIVE', 'GOOGLE', 'NAVER', 'KAKAO', 'APPLE'];
Expand Down Expand Up @@ -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 (
!(
Expand Down
5 changes: 3 additions & 2 deletions src/mocks/handlers/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
5 changes: 5 additions & 0 deletions src/mocks/utils/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {API_BASE_URL} from '@/constants/api';

export function getApiUrl(path: string) {
return `${API_BASE_URL}/${path}`;
}

0 comments on commit 4b4b59c

Please sign in to comment.