Skip to content

Commit

Permalink
feat: 허용서비스 세트 get 관련 mocking 코드 작성 (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivoryeee committed Jan 12, 2025
1 parent c745e5f commit 6cdfcc2
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/mocks/allowedService/resolvers/allowedServiceResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,32 @@ import { HttpResponse, http } from 'msw';
import { ALLOW_RES } from '../responses/allowedServiceResponses';

export const ALLOWEDSERVICE_MOCK_URL = {
GET_SETS: 'api/v2/allowedServiceSet/:category',
GET_SETS_DETAIL: 'api/v2/allowedServiceSet/:allowedServiceSetId/:category',
GET_RECOMMEND_SERVICES: 'api/v2/allowedServiceSet/recommendSite/:category',
};

export const allowedServiceResolvers = [
http.get(ALLOWEDSERVICE_MOCK_URL.GET_SETS, async ({ params }) => {
const { category } = params;

if (!category) {
throw new HttpResponse(null, { status: 400 });
}

return HttpResponse.json(ALLOW_RES.GET_SETS);
}),

http.get(ALLOWEDSERVICE_MOCK_URL.GET_SETS_DETAIL, async ({ params }) => {
const { allowedServiceSetId, category } = params;

if (!category || !allowedServiceSetId) {
throw new HttpResponse(null, { status: 400 });
}

return HttpResponse.json(ALLOW_RES.GET_SETS_DETAIL);
}),

http.get(ALLOWEDSERVICE_MOCK_URL.GET_RECOMMEND_SERVICES, async ({ params }) => {
const { category } = params;

Expand Down
33 changes: 33 additions & 0 deletions src/mocks/allowedService/responses/allowedServiceResponses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
export const ALLOW_RES = {
GET_SETS: {
status: 200,
message: '요청이 성공했습니다.',
data: [
{
name: 'khyojun 1',
colorCode: 'bg-color-palette-red',
allowSitesIcon: [
'https://www.google.com/s2/favicons?domain=google.com',
'https://www.google.com/s2/favicons?domain=naver.com',
],
},
],
},

GET_SETS_DETAIL: {
status: 200,
message: '요청이 성공했습니다.',
data: [
{
id: '3',
name: 'khyojun 1',
colorCode: 'bg-color-palette-red',
allowedSites: [
{
siteIcon: 'https://www.google.com/s2/favicons?domain=naver.com',
siteUrl: 'https://www.naver.com/',
},
],
},
],
},

GET_RECOMMEND_SERVICES: {
status: 200,
message: '요청이 성공했습니다.',
Expand Down
14 changes: 14 additions & 0 deletions src/shared/apisV2/allowedService/axios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ import axios from 'axios';

import { ALLOWEDSERVICE_MOCK_URL } from '@/mocks/allowedService/resolvers/allowedServiceResolvers';

export const getAllowedServiceSet = async (category: string) => {
const { data } = await axios.get(ALLOWEDSERVICE_MOCK_URL.GET_SETS, {
params: { category },
});
return data;
};

export const getAllowedServiceSetDetail = async (category: string, allowedServiceSetId: number) => {
const { data } = await axios.get(ALLOWEDSERVICE_MOCK_URL.GET_SETS, {
params: { category, allowedServiceSetId },
});
return data;
};

export const getRecommendServices = async (category: string) => {
const { data } = await axios.get(ALLOWEDSERVICE_MOCK_URL.GET_RECOMMEND_SERVICES, {
params: { category },
Expand Down
16 changes: 15 additions & 1 deletion src/shared/apisV2/allowedService/queries/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import { useQuery } from '@tanstack/react-query';

import { getRecommendServices } from './../axios/index';
import { getAllowedServiceSet, getAllowedServiceSetDetail, getRecommendServices } from './../axios/index';

export const useGetAllowedServiceSet = (category: string) => {
return useQuery({
queryKey: ['ServiceSet', category],
queryFn: () => getAllowedServiceSet(category),
});
};

export const useGetAllowedServiceSetDetail = (category: string, allowedServiceSetId: number) => {
return useQuery({
queryKey: ['ServiceSet', category, allowedServiceSetId],
queryFn: () => getAllowedServiceSetDetail(category, allowedServiceSetId),
});
};

export const useGetRecommendService = (category: string) => {
return useQuery({
Expand Down

0 comments on commit 6cdfcc2

Please sign in to comment.