-
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.
⚙️ MSW Follow, Search, User Test 코드 (#51)
* feat: User Interface에 locked 속성 추가, Mock data 반영 * feat: user handler -> follow, profile, search handler로 분리 같은 도메인에 따라 관리하기 위해서 user api 항목을 follow, profile, search로 분리하였습니다. 또한 follow handler의 코드가 일부 수정되었습니다. * feat: worker와 test server에 followHandler 추가 * chore: relationshipStatus mock data 수정 * test: follow API 테스트 추가 * test: follow API error처리 테스트 추가 * feat: worker와 test server에 searchHandler, profileHandler 추가 * feat: profileHandler -> userHandler로 이름 수정 * feat: profileFeed Interface / mock data에서 Title 삭제 UI 수정으로 인해 삭제했습니다. * feat: likeUser mock data 구현 * feat: searchHanlder likeUsers 연결 * feat: profileHandler -> userHandler로 수정 * feat: userHandler profileFeed 조회 userId 검사 구현 * chore: follow test toEqual -> toBe 수정 * feat: search test 구현 * feat: user test 구현 * feat: user error test 구현 * chore: user test console.log 삭제
- Loading branch information
1 parent
68f618a
commit 86deaf8
Showing
16 changed files
with
586 additions
and
111 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
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,58 @@ | ||
import { User } from '@/shared/consts'; | ||
|
||
interface Users { | ||
[userId: number]: User; | ||
} | ||
|
||
export const likeUsers: Users = { | ||
1: { | ||
id: 2, | ||
profileImage: 'https://picsum.photos/200/200', | ||
name: '이의찬', | ||
content: 'Legitgoons', | ||
locked: false, | ||
feedCount: 124, | ||
followingCount: 2, | ||
followerCount: 5341, | ||
}, | ||
2: { | ||
id: 3, | ||
profileImage: 'https://picsum.photos/200/200', | ||
name: '양재서', | ||
content: 'psychology50', | ||
locked: true, | ||
feedCount: 6, | ||
followingCount: 35, | ||
followerCount: 423, | ||
}, | ||
3: { | ||
id: 5, | ||
profileImage: 'https://picsum.photos/200/200', | ||
name: '신얀', | ||
content: 'yanni13', | ||
locked: true, | ||
feedCount: 51, | ||
followingCount: 7897, | ||
followerCount: 7890, | ||
}, | ||
4: { | ||
id: 4, | ||
profileImage: 'https://picsum.photos/200/200', | ||
name: '이수민', | ||
content: 'SSXXMM22', | ||
locked: true, | ||
feedCount: 24, | ||
followingCount: 42, | ||
followerCount: 53251, | ||
}, | ||
5: { | ||
id: 7, | ||
profileImage: 'https://picsum.photos/200/200', | ||
name: '안성윤', | ||
content: 'asn6878', | ||
locked: true, | ||
feedCount: 87, | ||
followingCount: 67, | ||
followerCount: 4556, | ||
}, | ||
}; |
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
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,87 @@ | ||
import { http } from 'msw'; | ||
|
||
import { | ||
createHttpSuccessResponse, | ||
createHttpErrorResponse, | ||
} from '../dir/response'; | ||
|
||
import { relationshipStatus } from '../consts/relationshipStatus'; | ||
import { users } from '../consts/user'; | ||
|
||
export const followHandler = [ | ||
// 1️⃣ 팔로우 요청 | ||
http.post('/users/:user_id/follow', ({ params }) => { | ||
const { user_id } = params; | ||
|
||
if (isNaN(Number(user_id))) { | ||
return createHttpErrorResponse('4220'); | ||
} | ||
|
||
const formattedUserId = Number(user_id); | ||
const followInfo = relationshipStatus[formattedUserId]; | ||
|
||
switch (followInfo) { | ||
case 'self': | ||
return createHttpErrorResponse('4220'); | ||
case 'none': | ||
if (users[formattedUserId].locked) { | ||
relationshipStatus[formattedUserId] = 'pending'; | ||
} else relationshipStatus[formattedUserId] = 'following'; | ||
break; | ||
case 'following': | ||
return createHttpErrorResponse('4220'); | ||
case 'pending': | ||
return createHttpErrorResponse('4220'); | ||
default: | ||
return createHttpErrorResponse('4040'); | ||
} | ||
|
||
return createHttpSuccessResponse({}); | ||
}), | ||
// 2️⃣ 언팔로우 & 팔로우 요청 취소 | ||
http.delete('/users/:user_id/follow', ({ params }) => { | ||
const { user_id } = params; | ||
|
||
if (isNaN(Number(user_id))) { | ||
return createHttpErrorResponse('4220'); | ||
} | ||
|
||
const formattedUserId = Number(user_id); | ||
const followInfo = relationshipStatus[formattedUserId]; | ||
|
||
switch (followInfo) { | ||
case 'self': | ||
return createHttpErrorResponse('4220'); | ||
case 'none': | ||
return createHttpErrorResponse('4220'); | ||
case 'following': | ||
relationshipStatus[formattedUserId] = 'none'; | ||
break; | ||
case 'pending': | ||
relationshipStatus[formattedUserId] = 'none'; | ||
break; | ||
|
||
default: | ||
return createHttpErrorResponse('4040'); | ||
} | ||
|
||
return createHttpSuccessResponse({}); | ||
}), | ||
// 3️⃣ 팔로우 확인 | ||
http.get('/users/:user_id/follow', ({ params }) => { | ||
const { user_id } = params; | ||
|
||
if (isNaN(Number(user_id))) { | ||
return createHttpErrorResponse('4220'); | ||
} | ||
|
||
const formattedUserId = Number(user_id); | ||
const followInfo = relationshipStatus[formattedUserId]; | ||
|
||
if (!followInfo) { | ||
return createHttpErrorResponse('4040'); | ||
} | ||
|
||
return createHttpSuccessResponse({ relationshipStatus: followInfo }); | ||
}), | ||
]; |
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,42 @@ | ||
import { http } from 'msw'; | ||
import { User } from '@/shared/consts'; | ||
|
||
import { | ||
createHttpSuccessResponse, | ||
createHttpErrorResponse, | ||
} from '../dir/response'; | ||
|
||
import { users } from '../consts/user'; | ||
import { likeUsers } from '../consts/likeUser'; | ||
|
||
export const searchHandler = [ | ||
// 1️⃣ 사용자 검색 | ||
http.get('/users', ({ request }) => { | ||
const url = new URL(request.url); | ||
const query = url.searchParams.get('q'); | ||
|
||
if (!query) { | ||
return createHttpErrorResponse('4220'); | ||
} | ||
|
||
const filteredUsers: User[] = Object.values(users).filter((user) => | ||
user.name.includes(query), | ||
); | ||
return createHttpSuccessResponse({ users: filteredUsers }); | ||
}), | ||
// 2️⃣ 좋아요 사용자 검색 | ||
http.get('/like', ({ request }) => { | ||
const url = new URL(request.url); | ||
const query = url.searchParams.get('q'); | ||
|
||
if (!query) { | ||
return createHttpErrorResponse('4220'); | ||
} | ||
|
||
const filteredUsers: User[] = Object.values(likeUsers).filter((user) => | ||
user.name.includes(query), | ||
); | ||
|
||
return createHttpSuccessResponse({ likeUsers: filteredUsers }); | ||
}), | ||
]; |
Oops, something went wrong.