Skip to content

Commit

Permalink
feat: 온보딩 mock api 생성 (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
suwonthugger committed Jan 19, 2025
1 parent b8ad72a commit c55c06d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/mocks/common/common.resolvers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { HttpResponse, http } from 'msw';

import { COMMON_RES } from './common.responses';

export const COMMON_MOCK_URL = {
GET_URL_NAME: 'api/v2/tabName',
};

export const commonResolvers = [
http.get(COMMON_MOCK_URL.GET_URL_NAME, async ({ request }) => {
const url = new URL(request.url);
const tabName = url.searchParams.get('tabName');

if (!tabName) {
console.error('경로 파라미터에 tabName이 없습니다.');
throw new HttpResponse(null, { status: 400 });
}

return HttpResponse.json(COMMON_RES.GET_URL_NAME);
}),
];
9 changes: 9 additions & 0 deletions src/mocks/common/common.responses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const COMMON_RES = {
GET_URL_NAME: {
status: 200,
message: '요청이 성공했습니다.',
data: {
tabName: 'NAVER',
},
},
};
4 changes: 3 additions & 1 deletion src/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { commonResolvers } from './common/common.resolvers';
import { homeResolvers } from './home/resolvers/homeResolvers';
import { onboardingResolvers } from './onboarding/onboarding.resolvers';

export const handlers = [...homeResolvers];
export const handlers = [...homeResolvers, ...onboardingResolvers, ...commonResolvers];
31 changes: 31 additions & 0 deletions src/mocks/onboarding/onboarding.resolvers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { HttpResponse, http } from 'msw';

import { ONBOARDING_RES } from './onboarding.responses';

export const ONBOARDING_MOCK_URL = {
POST_INTEREST_AREA: 'api/v2/onboard',
};

export const onboardingResolvers = [
http.post<never, { siteName: string; siteUrl: string }[]>(
ONBOARDING_MOCK_URL.POST_INTEREST_AREA,
async ({ request }) => {
const url = new URL(request.url);
const interestArea = url.searchParams.get('interestArea');

const body = await request.json();

if (body.length === 0) return HttpResponse.json(ONBOARDING_RES.POST_INTEREST_AREA);

if (
!(body.length > 0 && (typeof body[0].siteName === 'string' || typeof body[0].siteUrl === 'string')) ||
!interestArea
) {
console.error('요청 바디 값과, 쿼리스트링 값을 확인해주세요');
throw new HttpResponse(null, { status: 400 });
}

return HttpResponse.json(ONBOARDING_RES.POST_INTEREST_AREA);
},
),
];
6 changes: 6 additions & 0 deletions src/mocks/onboarding/onboarding.responses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const ONBOARDING_RES = {
POST_INTEREST_AREA: {
status: 200,
message: '요청이 성공했습니다.',
},
};

0 comments on commit c55c06d

Please sign in to comment.