Skip to content

Commit

Permalink
FIX : 클라이언트 페스를 상수로 관리 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
jobkaeHenry authored Nov 6, 2023
1 parent fadf6de commit 335a186
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
10 changes: 10 additions & 0 deletions client/src/__test__/post/createPostDetailPath.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {POST_DETAIL} from "@/const/clientPath";

describe("createPostDetailPath 함수 테스트", () => {
it("postId=1 userId=thisUser 가 입력되었을 때 ", () => {
expect(POST_DETAIL("thisUser", "1")).toEqual("/post/@thisUser/1");
});
it("공백을 자동으로 Trim 하는지 여부", () => {
expect(POST_DETAIL(" thisUser", "1 ")).toEqual("/post/@thisUser/1");
});
});
5 changes: 3 additions & 2 deletions client/src/components/post/PostCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";
import { POST_DETAIL } from "@/const/clientPath";
import { PostInterface } from "@/types/post/PostInterface";
import createPostDetailPath from "@/utils/createPostDetailPath";

import { MoreVertOutlined } from "@mui/icons-material";
import {
Avatar,
Expand All @@ -25,7 +26,7 @@ const PostCard = ({
id,
}: PostInterface) => {
return (
<Link href={createPostDetailPath(userId, id)}>
<Link href={`${POST_DETAIL(userId, id)}`}>
<Card sx={{ display: "flex", gap: 2, p: 2 }}>
<Avatar
sx={{ bgcolor: "secondary.main" }}
Expand Down
14 changes: 14 additions & 0 deletions client/src/const/clientPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,18 @@ export const MY_PROFILE = "/user" as const
*/
export const WIKI = "/wiki" as const

/**
* 유저아이디와 게시글 아이디를 입력받아 /post/@userId/postId 형태의 path를 리턴
* @param userId 유저ID
* @param postId 게시글ID
* @returns
*/
export const POST_DETAIL = (userId: string, postId: string) => {
const trimmedUserId = userId.trim();
const trimmedPostId = postId.trim();

return `/post/@${trimmedUserId}/${trimmedPostId}`;
};


export default HOME;
10 changes: 0 additions & 10 deletions client/src/utils/createPostDetailPath.test.ts

This file was deleted.

14 changes: 0 additions & 14 deletions client/src/utils/createPostDetailPath.ts

This file was deleted.

0 comments on commit 335a186

Please sign in to comment.