-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] 마이페이지 - 프로필 수정 모달 폼 제출 테스트 코드 작성 #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,62 @@ import { User } from '@/types/service/user'; | |||||||||||||||||||||||||||||||||||||||||||||
| import { createMockErrorResponse, createMockSuccessResponse } from '../common/common-mock'; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { mockUserItems } from './user-mock'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // 1. 팔로우 등록 모킹 | ||||||||||||||||||||||||||||||||||||||||||||||
| const followUserMock = http.post(`*/users/follow`, async ({ request }) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const url = new URL(request.url); | ||||||||||||||||||||||||||||||||||||||||||||||
| const followNickname = url.searchParams.get('followNickname'); | ||||||||||||||||||||||||||||||||||||||||||||||
| const user = mockUserItems.find((v) => v.nickName === followNickname); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (user?.isFollow === false) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json(createMockSuccessResponse('팔로우 성공')); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (user?.isFollow === null) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||
| createMockErrorResponse({ | ||||||||||||||||||||||||||||||||||||||||||||||
| status: 400, | ||||||||||||||||||||||||||||||||||||||||||||||
| detail: '회원 : 자기 자신을 팔로우할 수 없습니다.', | ||||||||||||||||||||||||||||||||||||||||||||||
| errorCode: 'NOT_SAME_FOLLOW', | ||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (user?.isFollow === true) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||
| createMockErrorResponse({ | ||||||||||||||||||||||||||||||||||||||||||||||
| status: 400, | ||||||||||||||||||||||||||||||||||||||||||||||
| detail: '회원 : 이미 팔로우 중입니다.', | ||||||||||||||||||||||||||||||||||||||||||||||
| errorCode: 'ALREADY_EXIST_FOLLOW', | ||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // 2. 유저 프로필 변경 모킹 | ||||||||||||||||||||||||||||||||||||||||||||||
| const updateUserItemMock = http.patch(`*/users/profile`, async ({ request }) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const body = (await request.json()) as User; | ||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||
| createMockSuccessResponse({ | ||||||||||||||||||||||||||||||||||||||||||||||
| ...mockUserItems[0], | ||||||||||||||||||||||||||||||||||||||||||||||
| ...body, | ||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // 4. 알림 설정 변경 모킹 | ||||||||||||||||||||||||||||||||||||||||||||||
| const updateMyNotificationMock = http.patch(`*/users/notification`, async ({ request }) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const url = new URL(request.url); | ||||||||||||||||||||||||||||||||||||||||||||||
| const isNotificationEnabled = url.searchParams.get('isNotificationEnabled'); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||
| createMockSuccessResponse({ | ||||||||||||||||||||||||||||||||||||||||||||||
| ...mockUserItems[0], | ||||||||||||||||||||||||||||||||||||||||||||||
| isNotificationEnabled: !!isNotificationEnabled, | ||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // 5. 유저 프로필 조회 모킹 | ||||||||||||||||||||||||||||||||||||||||||||||
| const getUserItemMock = http.get(`*/users/:userId`, ({ params }) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const id = Number(params.userId); | ||||||||||||||||||||||||||||||||||||||||||||||
| const user = mockUserItems.find((item) => item.userId === id); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -23,39 +79,74 @@ const getUserItemMock = http.get(`*/users/:userId`, ({ params }) => { | |||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json(createMockSuccessResponse(user)); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // 7. 닉네임 중복 검사 모킹 | ||||||||||||||||||||||||||||||||||||||||||||||
| const getNicknameAvailabilityMock = http.get(`*/users/nickname/availability`, ({ request }) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const url = new URL(request.url); | ||||||||||||||||||||||||||||||||||||||||||||||
| const nickname = url.searchParams.get('nickname'); | ||||||||||||||||||||||||||||||||||||||||||||||
| const user = mockUserItems.find((item) => item.nickName === nickname); | ||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||
| createMockSuccessResponse({ | ||||||||||||||||||||||||||||||||||||||||||||||
| data: { available: !user }, | ||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // 8. 본인 프로필 조회 모킹 | ||||||||||||||||||||||||||||||||||||||||||||||
| const getMeItemMock = http.get(`*/users/me`, () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const id = 1; | ||||||||||||||||||||||||||||||||||||||||||||||
| const user = mockUserItems.find((item) => item.userId === id); | ||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json(createMockSuccessResponse(user)); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const updateUserItemMock = http.patch(`*/users`, async ({ request }) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const body = (await request.json()) as User; | ||||||||||||||||||||||||||||||||||||||||||||||
| // 7. 닉네임 중복 검사 모킹 | ||||||||||||||||||||||||||||||||||||||||||||||
| const getEmailAvailabilityMock = http.get(`*/users/email/availability`, ({ request }) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const url = new URL(request.url); | ||||||||||||||||||||||||||||||||||||||||||||||
| const email = url.searchParams.get('email'); | ||||||||||||||||||||||||||||||||||||||||||||||
| const user = mockUserItems.find((item) => item.email === email); | ||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||
| createMockSuccessResponse({ | ||||||||||||||||||||||||||||||||||||||||||||||
| ...mockUserItems[0], | ||||||||||||||||||||||||||||||||||||||||||||||
| ...body, | ||||||||||||||||||||||||||||||||||||||||||||||
| data: { available: !user }, | ||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+101
to
111
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 응답 구조가 일관되지 않습니다. Line 113-115에서 getNicknameAvailabilityMock과 동일한 불필요한 중첩 구조 문제가 있습니다. 🔎 수정 제안-const getEmailAvailabilityMock = http.get(`*/users/email/availability`, ({ request }) => {
+const getEmailAvailabilityMock = http.get(`*/users/email/availability`, ({ request }) => {
const url = new URL(request.url);
const email = url.searchParams.get('email');
const user = mockUserItems.find((item) => item.email === email);
return HttpResponse.json(
- createMockSuccessResponse({
- data: { available: !user },
- }),
+ createMockSuccessResponse({ available: !user }),
);
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const deleteUserItemMock = http.delete(`*/users`, async () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json(createMockSuccessResponse(null)); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
| const unfollowUserMock = http.delete(`*/users/unfollow`, ({ request }) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const url = new URL(request.url); | ||||||||||||||||||||||||||||||||||||||||||||||
| const unFollowNickname = url.searchParams.get('unFollowNickname'); | ||||||||||||||||||||||||||||||||||||||||||||||
| const user = mockUserItems.find((v) => v.nickName === unFollowNickname); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const followUserItemMock = http.post(`*/follows`, async () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json(createMockSuccessResponse(null)); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (user?.isFollow === false) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json(createMockSuccessResponse('팔로우 취소 성공')); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (user?.isFollow === null) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||
| createMockErrorResponse({ | ||||||||||||||||||||||||||||||||||||||||||||||
| status: 400, | ||||||||||||||||||||||||||||||||||||||||||||||
| detail: '회원 : 팔로우 취소 대상은 본인 될 수 없습니다.', | ||||||||||||||||||||||||||||||||||||||||||||||
| errorCode: 'NOT_SAME_FOLLOW', | ||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const unfollowUserItemMock = http.delete(`*/follows/:followId`, async () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json(createMockSuccessResponse(null)); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (user?.isFollow === true) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.json( | ||||||||||||||||||||||||||||||||||||||||||||||
| createMockErrorResponse({ | ||||||||||||||||||||||||||||||||||||||||||||||
| status: 400, | ||||||||||||||||||||||||||||||||||||||||||||||
| detail: '회원 : 팔로우 관계를 찾을 수 없습니다.', | ||||||||||||||||||||||||||||||||||||||||||||||
| errorCode: 'NOT_FOUND_FOLLOW', | ||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| export const userHandlers = [ | ||||||||||||||||||||||||||||||||||||||||||||||
| followUserMock, | ||||||||||||||||||||||||||||||||||||||||||||||
| getUserItemMock, | ||||||||||||||||||||||||||||||||||||||||||||||
| updateMyNotificationMock, | ||||||||||||||||||||||||||||||||||||||||||||||
| getMeItemMock, | ||||||||||||||||||||||||||||||||||||||||||||||
| updateUserItemMock, | ||||||||||||||||||||||||||||||||||||||||||||||
| deleteUserItemMock, | ||||||||||||||||||||||||||||||||||||||||||||||
| followUserItemMock, | ||||||||||||||||||||||||||||||||||||||||||||||
| unfollowUserItemMock, | ||||||||||||||||||||||||||||||||||||||||||||||
| getNicknameAvailabilityMock, | ||||||||||||||||||||||||||||||||||||||||||||||
| getEmailAvailabilityMock, | ||||||||||||||||||||||||||||||||||||||||||||||
| unfollowUserMock, | ||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
응답 구조가 API 타입 정의와 일치하지 않습니다.
Line 94-96에서
{ data: { available: !user } }형태로 중첩된 객체를 반환하고 있지만,createMockSuccessResponse는 이미{ status, success, data }구조를 생성합니다. 이로 인해 최종 응답이{ status: 200, success: true, data: { data: { available: boolean } } }형태가 되어 불필요한 중첩이 발생합니다.🔎 수정 제안
const getNicknameAvailabilityMock = http.get(`*/users/nickname/availability`, ({ request }) => { const url = new URL(request.url); - const nickname = url.searchParams.get('nickname'); + const nickName = url.searchParams.get('nickName'); - const user = mockUserItems.find((item) => item.nickName === nickname); + const user = mockUserItems.find((item) => item.nickName === nickName); return HttpResponse.json( - createMockSuccessResponse({ - data: { available: !user }, - }), + createMockSuccessResponse({ available: !user }), ); });참고: 파라미터 이름도
nickname에서nickName으로 변경하여 API 서비스 코드(Line 48 in src/api/service/user-service/index.ts)와 일치시켰습니다.📝 Committable suggestion
🤖 Prompt for AI Agents