-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from CHZZK-Study/chore/axios-setting
chore : axios 세팅 msw 연동 및 테스트
- Loading branch information
Showing
16 changed files
with
202 additions
and
154 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_MOCK_API_URL= http://localhost:5173 |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { API_END_POINT } from '@/constants/api'; | ||
// eslint-disable-next-line import/no-cycle | ||
import { TestItems } from '@/pages/Test'; | ||
import { httpClient } from '@/utils/axios'; | ||
|
||
interface TestData { | ||
test: TestItems[]; | ||
} | ||
|
||
export const getTest = async (): Promise<TestData> => { | ||
const response = await httpClient.get(API_END_POINT.TEST); | ||
return response.data; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const API_END_POINT = { | ||
// AUTH | ||
LOGIN: '/auth/login', | ||
LOGOUT: '/auth/logout', | ||
REFRESH_TOKEN: '/auth/token', | ||
SIGNUP: '/users/signup', | ||
PROFILE: '/profile', | ||
// Test | ||
TEST: '/test', | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
/* eslint-disable import/no-named-as-default */ | ||
import { setupWorker } from 'msw/browser'; | ||
import { handlers } from './handlers'; | ||
import { HttpHandler } from 'msw'; | ||
import getTest from './handlers/test'; | ||
|
||
export const worker = setupWorker(...handlers); | ||
export const handlers: HttpHandler[] = [getTest]; | ||
|
||
export default worker; | ||
export const worker = setupWorker(...handlers); | ||
/* eslint-disable import/no-named-as-default */ |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { http, HttpHandler, HttpResponse } from 'msw'; | ||
import { API_END_POINT } from '@/constants/api'; | ||
import ongoingProducts from '../data/ongoingData'; | ||
|
||
export const getTest: HttpHandler = http.get( | ||
`${API_END_POINT.TEST}`, | ||
async () => { | ||
return new HttpResponse( | ||
JSON.stringify({ | ||
test: [...ongoingProducts], | ||
}), | ||
{ | ||
status: 200, | ||
statusText: 'OK', | ||
}, | ||
); | ||
}, | ||
); | ||
|
||
export default getTest; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* eslint-disable import/no-cycle */ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { getTest } from '@/api/test.api'; | ||
/* eslint-disable import/no-cycle */ | ||
|
||
export interface TestItems { | ||
id: number; | ||
name: string; | ||
startPrice: string; | ||
timeLeft: string; | ||
activeUserCount: string; | ||
isBidding: boolean; | ||
} | ||
|
||
const Test = () => { | ||
const { data, isLoading, error } = useQuery({ | ||
queryKey: ['TEST'], | ||
queryFn: () => getTest(), | ||
}); | ||
|
||
if (isLoading) return <div>Loading</div>; | ||
if (error) return <div>Error</div>; | ||
|
||
return ( | ||
<div> | ||
{data?.test?.map( | ||
( | ||
item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */, | ||
index: number /* eslint-disable-line @typescript-eslint/no-unused-vars */, | ||
) => <div key={item.id}>{item.name}</div>, | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Test; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import axios, { AxiosRequestConfig } from 'axios'; | ||
|
||
export const createClient = (config?: AxiosRequestConfig) => { | ||
const axiosInstance = axios.create({ | ||
baseURL: import.meta.env.VITE_MOCK_API_URL, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
withCredentials: true, | ||
timeout: 5000, | ||
...config, | ||
}); | ||
axiosInstance.interceptors.request.use((request) => { | ||
return request; | ||
}); | ||
|
||
axiosInstance.interceptors.response.use( | ||
(response) => { | ||
return response; | ||
}, | ||
(error) => { | ||
return Promise.reject(error); | ||
}, | ||
); | ||
|
||
return axiosInstance; | ||
}; | ||
|
||
export const httpClient = createClient(); |
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