From e7d424ece46b3645d791fbfda5cbf94c3304f982 Mon Sep 17 00:00:00 2001 From: yoonyesol Date: Sat, 24 Aug 2024 00:52:11 +0900 Subject: [PATCH] =?UTF-8?q?Test:=20#80=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EB=AA=A8=ED=82=B9=20=ED=95=A8=EC=88=98=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mocks/handlers.ts | 3 ++- src/mocks/services/authServiceHandler.ts | 32 ++++++++++++++++++++++++ src/pages/user/SearchPasswordPage.tsx | 6 ++--- src/pages/user/SignInPage.tsx | 6 ++--- src/pages/user/SignUpPage.tsx | 14 +++++------ src/types/UserType.tsx | 6 ++--- 6 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 src/mocks/services/authServiceHandler.ts diff --git a/src/mocks/handlers.ts b/src/mocks/handlers.ts index 478ec85a..c24a1e51 100644 --- a/src/mocks/handlers.ts +++ b/src/mocks/handlers.ts @@ -1,7 +1,8 @@ import userServiceHandler from '@mocks/services/userServiceHandler'; import teamServiceHandler from '@mocks/services/teamServiceHandler'; import projectServiceHandler from '@mocks/services/projectServiceHandler'; +import authServiceHandler from './services/authServiceHandler'; -const handlers = [...userServiceHandler, ...teamServiceHandler, ...projectServiceHandler]; +const handlers = [...userServiceHandler, ...teamServiceHandler, ...projectServiceHandler, ...authServiceHandler]; export default handlers; diff --git a/src/mocks/services/authServiceHandler.ts b/src/mocks/services/authServiceHandler.ts new file mode 100644 index 00000000..c3b85f05 --- /dev/null +++ b/src/mocks/services/authServiceHandler.ts @@ -0,0 +1,32 @@ +import { http, HttpResponse } from 'msw'; + +const BASE_URL = import.meta.env.VITE_BASE_URL; + +type LoginRequestBody = { + username: string; + password: string; +}; +const authServiceHandler = [ + // 로그인 API + http.post(`${BASE_URL}/user/login`, async ({ request }) => { + const { username, password } = (await request.json()) as LoginRequestBody; + + if (username === 'test' && password === 'test@123') { + const accessToken = 'mockedAccessToken'; + const refreshToken = 'mockedRefreshToken'; + + return HttpResponse.json( + { accessToken }, + { + status: 200, + headers: { + 'Set-Cookie': `refreshToken=${refreshToken}; HttpOnly; Secure; SameSite=Strict; Path=/;`, + }, + }, + ); + } + return new HttpResponse(JSON.stringify({ message: '아이디 또는 비밀번호가 잘못되었습니다.' }), { status: 400 }); + }), +]; + +export default authServiceHandler; diff --git a/src/pages/user/SearchPasswordPage.tsx b/src/pages/user/SearchPasswordPage.tsx index 620e8844..e202c733 100644 --- a/src/pages/user/SearchPasswordPage.tsx +++ b/src/pages/user/SearchPasswordPage.tsx @@ -13,7 +13,7 @@ export default function SearchPasswordPage() { } = useForm({ mode: 'onChange', defaultValues: { - id: '', + username: '', email: '', code: '', }, @@ -28,8 +28,8 @@ export default function SearchPasswordPage() { {/* 아이디 */} {/* 이메일 */} diff --git a/src/pages/user/SignInPage.tsx b/src/pages/user/SignInPage.tsx index 8148a64a..f63d6d4b 100644 --- a/src/pages/user/SignInPage.tsx +++ b/src/pages/user/SignInPage.tsx @@ -23,7 +23,7 @@ export default function SignInPage() { } = useForm({ mode: 'onChange', defaultValues: { - id: '', + username: '', password: '', }, }); @@ -58,8 +58,8 @@ export default function SignInPage() { {/* 아이디 */} {/* 비밀번호 */} diff --git a/src/pages/user/SignUpPage.tsx b/src/pages/user/SignUpPage.tsx index 55cd3fe2..fc9a4a6b 100644 --- a/src/pages/user/SignUpPage.tsx +++ b/src/pages/user/SignUpPage.tsx @@ -21,7 +21,7 @@ export default function SignUpPage() { const methods = useForm({ mode: 'onChange', defaultValues: { - id: '', + username: '', email: '', code: '', nickname: '', @@ -34,7 +34,7 @@ export default function SignUpPage() { // form 전송 함수 const onSubmit = async (data: UserSignUpForm) => { - const { id, code, checkPassword, ...filteredData } = data; + const { username, code, checkPassword, ...filteredData } = data; console.log(data); const verifyResult = verifyCode(methods.watch('code'), methods.setError); @@ -43,8 +43,8 @@ export default function SignUpPage() { // TODO: 폼 제출 로직 수정 필요 try { // 회원가입 폼 - const formData = { ...filteredData, id, code }; - const registrationResponse = await axios.post(`http://localhost:8080/api/v1/user/${id}`, formData); + const formData = { ...filteredData, username, code }; + const registrationResponse = await axios.post(`http://localhost:8080/api/v1/user/${username}`, formData); if (registrationResponse.status !== 200) return toastError('회원가입에 실패했습니다. 다시 시도해 주세요.'); // 이미지 폼 @@ -54,7 +54,7 @@ export default function SignUpPage() { const jpeg = await reduceImageSize(imageUrl); const file = new File([jpeg], new Date().toISOString(), { type: 'image/jpeg' }); imgFormData.append('profileUrl', file); - imgFormData.append('id', id ?? ''); + imgFormData.append('username', username ?? ''); const imageResponse = await axios.post(`http://localhost:8080/api/v1/users/file`, imgFormData, { headers: { 'Content-Type': 'multipart/form-data' }, @@ -80,8 +80,8 @@ export default function SignUpPage() { {/* 아이디 */} {/* 이메일 */} diff --git a/src/types/UserType.tsx b/src/types/UserType.tsx index a0e67421..11a1ce63 100644 --- a/src/types/UserType.tsx +++ b/src/types/UserType.tsx @@ -2,7 +2,7 @@ import type { Role } from '@/types/RoleType'; export type User = { userId: number; - id: string | null; + username: string | null; email: string; provider: 'LOCAL' | 'KAKAO' | 'GOOGLE'; nickname: string; @@ -21,13 +21,13 @@ export type UserSignUpForm = Omit & { checkPassword: string; }; -export type UserSignInForm = Pick & { +export type UserSignInForm = Pick & { password: string; }; export type EmailVerificationForm = Pick & { code: string }; -export type SearchPasswordForm = Pick & { code: string }; +export type SearchPasswordForm = Pick & { code: string }; export type EditPasswordForm = { password: string;