Skip to content

Commit

Permalink
๐Ÿ› ๏ธ ProfileFeed, User Content ์ด์Šˆ ์ˆ˜์ • (#97)
Browse files Browse the repository at this point in the history
* feat: user content ์ œ๊ฑฐ

* feat: ProfileFeed Interface์™€ ๊ด€๋ จ mockdata ์‚ญ์ œ

* fix: feed mockdata id ์˜ค๊ธฐ์ž… ์ˆ˜์ •

* feat: user test ์ฝ”๋“œ ์ˆ˜์ •

uri ์ˆ˜์ • ๋ฐ test case ์ˆ˜์ •

* fix: userHandler ์ˆ˜์ •

profileFeed Interface ์‚ญ์ œ์— ๋”ฐ๋ผ ์‚ฌ์šฉ์ž๋ณ„ ํ”ผ๋“œ ์กฐํšŒ handler๊ฐ€ feeds data๋กœ ์ ์ ˆํ•˜๊ฒŒ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ์ˆ˜์ •

Closes #93, #94
  • Loading branch information
Legitgoons authored Jul 6, 2024
1 parent 07d8688 commit 78c6dde
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 121 deletions.
4 changes: 2 additions & 2 deletions src/app/mocks/consts/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export const feeds: Feeds = {
imageUrl: 'https://picsum.photos/320/320',
},
{
id: 1,
id: 2,
imageUrl: 'https://picsum.photos/320/320',
},
{
id: 2,
id: 3,
imageUrl: 'https://picsum.photos/320/320',
},
{
Expand Down
5 changes: 0 additions & 5 deletions src/app/mocks/consts/likeUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const likeUsers: Users = {
profileImage: '',
name: '์ด์˜์ฐฌ',
username: 'Legitgoons',
content: '์ทจ์—…ํ•˜๊ณ ์‹ถ๋‹น',
locked: false,
feedCount: 124,
followingCount: 2,
Expand All @@ -21,7 +20,6 @@ export const likeUsers: Users = {
profileImage: '',
name: '์–‘์žฌ์„œ',
username: 'psychology50',
content: 'IMPM',
locked: true,
feedCount: 6,
followingCount: 35,
Expand All @@ -32,7 +30,6 @@ export const likeUsers: Users = {
profileImage: 'https://picsum.photos/32/32',
name: '์‹ ์–€',
username: 'yanni13',
content: 'imiOSDev',
locked: true,
feedCount: 51,
followingCount: 7897,
Expand All @@ -43,7 +40,6 @@ export const likeUsers: Users = {
profileImage: 'https://picsum.photos/32/32',
name: '์ด์ˆ˜๋ฏผ',
username: 'SSXXMM22',
content: 'imdesigner',
locked: true,
feedCount: 24,
followingCount: 42,
Expand All @@ -54,7 +50,6 @@ export const likeUsers: Users = {
profileImage: 'https://picsum.photos/32/32',
name: '์•ˆ์„ฑ์œค',
username: 'asn6878',
content: 'imbackend',
locked: true,
feedCount: 87,
followingCount: 67,
Expand Down
82 changes: 0 additions & 82 deletions src/app/mocks/consts/profileFeed.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/app/mocks/consts/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const users: Users = {
profileImage: '',
name: '๊ฐ•๋ณ‘์ค€',
username: 'bangdori',
content: '์Šคํƒ€ํŠธ์—…์œผ๋กœ ๊ฐ‘๋‹ˆ๋‹น',
locked: false,
feedCount: 100,
followingCount: 347,
Expand All @@ -21,7 +20,6 @@ export const users: Users = {
profileImage: '',
name: '์ด์˜์ฐฌ',
username: 'Legitgoons',
content: '์ทจ์—…ํ•˜๊ณ ์‹ถ๋‹น',
locked: false,
feedCount: 124,
followingCount: 2,
Expand All @@ -32,7 +30,6 @@ export const users: Users = {
profileImage: '',
name: '์–‘์žฌ์„œ',
username: '์˜ค๋Š˜๋„๋ฐค์ƒ˜',
content: 'IMPM',
locked: true,
feedCount: 6,
followingCount: 35,
Expand All @@ -43,7 +40,6 @@ export const users: Users = {
profileImage: 'https://picsum.photos/32/32',
name: '์ด์ˆ˜๋ฏผ',
username: 'SSXXMM22',
content: 'imdesigner',
locked: true,
feedCount: 24,
followingCount: 42,
Expand All @@ -54,7 +50,6 @@ export const users: Users = {
profileImage: 'https://picsum.photos/32/32',
name: '์‹ ์–€',
username: 'yanni13',
content: 'imiOSDev',
locked: true,
feedCount: 51,
followingCount: 7897,
Expand All @@ -65,7 +60,6 @@ export const users: Users = {
profileImage: 'https://picsum.photos/32/32',
name: '์ด์ฃผ์›',
username: '2weeksone',
content: 'imdesignertoo',
locked: false,
feedCount: 97,
followingCount: 98,
Expand All @@ -76,7 +70,6 @@ export const users: Users = {
profileImage: 'https://picsum.photos/32/32',
name: '์•ˆ์„ฑ์œค',
username: 'asn6878',
content: 'imbackend',
locked: true,
feedCount: 87,
followingCount: 67,
Expand All @@ -87,7 +80,6 @@ export const users: Users = {
profileImage: 'https://picsum.photos/32/32',
name: '์ด์ง„์šฐ',
username: '๋„ค์ด๋ฒ„๋งจ',
content: 'imbackendtoo',
locked: false,
feedCount: 32,
followingCount: 24,
Expand All @@ -98,7 +90,6 @@ export const users: Users = {
profileImage: 'https://picsum.photos/32/32',
name: '์ตœํฌ์ง„',
username: '๋ถ€์ž๊ฐ€๋ ๊ฑฐ์•ผ',
content: 'iLoveNewjeans',
locked: false,
feedCount: 66,
followingCount: 1,
Expand Down
14 changes: 8 additions & 6 deletions src/app/mocks/handler/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
} from '../dir/response';

import { users } from '../consts/user';
import { profileFeeds } from '../consts/profileFeed';
import { feeds } from '../consts/feed';
import { reports } from '../consts/report';
import { hiddens } from '../consts/hidden';

export const userHandler = [
// 1๏ธโƒฃ ์‚ฌ์šฉ์ž ์กฐํšŒ
Expand All @@ -27,8 +28,8 @@ export const userHandler = [

return createHttpSuccessResponse({ user: user });
}),
// 2๏ธโƒฃ ์‚ฌ์šฉ์ž ํ”„๋กœํ•„ ํ”ผ๋“œ ์กฐํšŒ
http.get('/profile/:user_id', ({ request, params }) => {
// 2๏ธโƒฃ ์‚ฌ์šฉ์ž๋ณ„ ํ”ผ๋“œ ์กฐํšŒ
http.get('/users/:user_id/feeds', ({ request, params }) => {
const { user_id } = params;

const url = new URL(request.url);
Expand All @@ -52,11 +53,12 @@ export const userHandler = [
const formattedPage = Number(page);
const pageCount = 5;

const profileFeedsData = Object.values(profileFeeds)
const profileFeedsData = Object.values(feeds)
.filter((feed) => formattedUserId === feed.user.id)
.slice((formattedPage - 1) * pageCount, formattedPage * pageCount)
.filter((feed) => !reports[feed.id]);
.filter((feed) => !reports[feed.id] && !hiddens[feed.id]);

const totalFeeds = Object.values(profileFeeds).length;
const totalFeeds = Object.values(profileFeedsData).length;
const endOfPageRange = formattedPage * pageCount;
const hasNextPage = endOfPageRange < totalFeeds;

Expand Down
6 changes: 3 additions & 3 deletions src/app/mocks/test/user/user.error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('[GET] ํ”„๋กœํ•„ ํ”ผ๋“œ ์กฐํšŒ API', () => {
for (const userId of userIds) {
const response = await axios({
method: 'GET',
url: `/profile/${userId}`,
url: `/users/${userId}`,
});
const { code } = response.data;

Expand All @@ -49,7 +49,7 @@ describe('[GET] ํ”„๋กœํ•„ ํ”ผ๋“œ ์กฐํšŒ API', () => {

const response = await axios({
method: 'GET',
url: `/profile/${userId}`,
url: `/users/${userId}`,
});
const { code } = response.data;

Expand All @@ -62,7 +62,7 @@ describe('[GET] ํ”„๋กœํ•„ ํ”ผ๋“œ ์กฐํšŒ API', () => {
for (const page of pages) {
const response = await axios({
method: 'GET',
url: `/profile/${userId}&p=${page}`,
url: `/users/${userId}/feeds?page=${page}`,
});
const { code } = response.data;

Expand Down
8 changes: 4 additions & 4 deletions src/app/mocks/test/user/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ async function getUserById(userId: number) {
}

async function getProfileFeedById(userId: number, page: number) {
const profileFeed = await axios.get(`/profile/${userId}?page=${page}`);
const profileFeed = await axios.get(`/users/${userId}/feeds?page=${page}`);

const profileFeedData = profileFeed.data.data;
return { profileFeedData };
}
Expand All @@ -24,14 +25,13 @@ it('์œ ์ € ์ •๋ณด ์กฐํšŒ ์‹œ, id์— ์ผ์น˜ํ•˜๋Š” ์œ ์ € ์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.'
});

it('์œ ์ €์˜ ProfileFeed ์กฐํšŒ ์‹œ, ํ•ด๋‹น ์œ ์ €์˜ ProfileFeed๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.', async () => {
const userId = 4;
const userId = 1;
let page = 1;

// ProfileFeed ๊ฐ€์ ธ์˜ค๊ธฐ
const { profileFeedData: profileFeedData } = await getProfileFeedById(
userId,
page,
);

expect(profileFeedData.currentPageNumber).toBe(5);
expect(profileFeedData.feeds[0].images.length).toBe(10);
});
1 change: 0 additions & 1 deletion src/shared/consts/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export type * from './feed';
export type { Comment } from './comment';
export type { Like } from './like';
export type * from './user';
export type { ProfileFeed } from './profileFeed';
8 changes: 0 additions & 8 deletions src/shared/consts/types/profileFeed.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/shared/consts/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export interface User {
profileImage: string;
name: string;
username: string;
content: string;
locked: boolean;

feedCount: number;
Expand Down

0 comments on commit 78c6dde

Please sign in to comment.