-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
유저 정보를 불러오는 패치 api 함수 구현 및 msw mocking 구현 (#107)
* feat: (#63) 유저 정보를 불러오는 패치 api 함수 구현 및 msw mocking 구현 * test: (#63) 유저 정보 테스트 코드 추가 * refactor: (#63) 코드 가독성을 위해 타입 이름 변경 --------- Co-authored-by: chsua <113416448+chsua@users.noreply.github.com>
- Loading branch information
1 parent
00a4779
commit a025d2f
Showing
6 changed files
with
61 additions
and
2 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,19 @@ | ||
import { getUserInfo, transformUserInfoResponse } from '@api/wus/userInfo'; | ||
|
||
import { MOCK_USER_INFO } from '@mocks/mockData/user'; | ||
|
||
describe('서버와 통신하여 유저의 정보를 불러올 수 있어야 한다.', () => { | ||
test('유저의 정보를 불러온다', async () => { | ||
const data = await getUserInfo(); | ||
|
||
expect(data).toEqual(transformUserInfoResponse(MOCK_USER_INFO)); | ||
}); | ||
|
||
test('클라이언트에서 사용하는 유저 정보 API 명세가 [nickname, postCount, userPoint, userPoint, badge]으로 존재해야한다', async () => { | ||
const data = await getUserInfo(); | ||
|
||
const userInfoKeys = Object.keys(data); | ||
|
||
expect(userInfoKeys).toEqual(['nickname', 'postCount', 'userPoint', 'voteCount', 'badge']); | ||
}); | ||
}); |
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,21 @@ | ||
import type { UserInfoResponse, User } from '@type/user'; | ||
|
||
import { getFetch } from '@utils/fetch'; | ||
|
||
export const transformUserInfoResponse = (userInfo: UserInfoResponse): User => { | ||
const { nickname, postCount, userPoint, voteCount, badge } = userInfo; | ||
|
||
return { | ||
nickname, | ||
postCount, | ||
userPoint, | ||
voteCount, | ||
badge, | ||
}; | ||
}; | ||
|
||
export const getUserInfo = async () => { | ||
const userInfo = await getFetch<UserInfoResponse>('/members/me'); | ||
|
||
return transformUserInfoResponse(userInfo); | ||
}; |
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,9 @@ | ||
import { rest } from 'msw'; | ||
|
||
import { MOCK_USER_INFO } from '@mocks/mockData/user'; | ||
|
||
export const mockUserInfo = [ | ||
rest.get('/members/me', (req, res, ctx) => { | ||
return res(ctx.status(200), ctx.json(MOCK_USER_INFO)); | ||
}), | ||
]; |
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