Skip to content
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

[API] API 명세 변경을 반영한다 #416

Merged
merged 4 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/home/CreatePanelModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export function CreatePanelModal({ close }: Props): JSX.Element {
createPanelMutation.mutate(
{ title, description },
{
onSuccess: ({ id }) => {
navigate(`/panel/${id}`);
onSuccess: ({ sid }) => {
navigate(`/panel/${sid}`);
},
},
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/home/DeletePanelModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Props {
panel: Panel;
}
export function DeletePanelModal({ close, panel }: Props): JSX.Element {
const { id, title } = panel;
const { sid, title } = panel;
const deletePanelMutation = useDeletePanelMutation();

return (
Expand All @@ -27,7 +27,7 @@ export function DeletePanelModal({ close, panel }: Props): JSX.Element {
variant="danger"
type="button"
onClick={() => {
deletePanelMutation.mutate(id, {
deletePanelMutation.mutate(sid, {
onSuccess: () => {
close();
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/home/PanelGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function PanelGrid({ panelPages }: Props): JSX.Element {

const handlePanelTitleClick = useCallback(
(panel: Panel) => () => {
navigate(`/panel/${panel.id}`);
navigate(`/panel/${panel.sid}`);
},
[navigate],
);
Expand All @@ -89,7 +89,7 @@ export function PanelGrid({ panelPages }: Props): JSX.Element {
{panelPages.map((page) =>
page.panels.map((panel) => (
<PanelItem
key={panel.id}
key={panel.sid}
panel={panel}
openActionMenu={handleOpenPanelActionMenu(panel)}
onPanelTitleClick={handlePanelTitleClick(panel)}
Expand Down
4 changes: 2 additions & 2 deletions src/components/home/PanelItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export const PanelItem = ({
openActionMenu,
onPanelTitleClick,
}: Props): JSX.Element => {
const { id, title, createdAt, description } = panel;
const { sid, title, createdAt, description } = panel;

return (
<li
key={id}
key={sid}
className="flex flex-col gap-6 tracking-tight rounded-md bg-white py-4 px-5 border border-grey-light"
>
<div className="flex justify-between items-start">
Expand Down
2 changes: 1 addition & 1 deletion src/components/home/UpdatePanelModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Props = CreateOverlayContentProps & {
};

export function UpdatePanelModal({ close, panel }: Props): JSX.Element {
const updateMutation = useUpdatePanelMutation(panel.id);
const updateMutation = useUpdatePanelMutation(panel.sid);
const messageRef = useRef<HTMLDivElement | null>(null);

const { inputProps, errors, formProps, hasError } = useForm({
Expand Down
5 changes: 3 additions & 2 deletions src/components/home/__tests__/DeletePanelModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Panel } from '@/lib/api/panel';

import React from 'react';

import { faker } from '@faker-js/faker';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

Expand All @@ -12,10 +13,10 @@ import { DeletePanelModal } from '../DeletePanelModal';

const handleClose = vi.fn();
const panel: Panel = {
id: 1,
author: '[email protected]',
sid: faker.datatype.uuid(),
title: '테스트 패널 제목',
description: '테스트 패널 설명',
authorId: 0,
createdAt: new Date().toDateString(),
updatedAt: new Date().toDateString(),
};
Expand Down
18 changes: 8 additions & 10 deletions src/components/home/__tests__/PanelGrid.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { GetMyPanelsResult } from '@/lib/api/panel';

import React from 'react';

import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { PanelGrid } from '@/components/home/PanelGrid';
import { renderWithQueryClient } from '@/lib/test-utils';
import { createMockPanel, createMockPanleList } from '@/mocks/data/panel';
import { createMockPanleList } from '@/mocks/data/panel';

const navigateMockFn = vi.fn();
vi.mock('react-router-dom', () => ({
Expand All @@ -18,13 +16,12 @@ vi.mock('@/hooks/useOverlay', () => ({ useOverlay: vi.fn() }));

describe('PanelGrid', () => {
it('패널 목록을 렌더링한다', () => {
const panelPages: GetMyPanelsResult[] = [
{ panels: createMockPanleList(10) },
];
const panelPage = { panels: createMockPanleList(10), nextPage: -1 };
const panelPages = [panelPage];
renderWithQueryClient(<PanelGrid panelPages={panelPages} />);

expect(
screen.getAllByText(panelPages[0].panels[0].title)[0],
screen.getAllByText(panelPage.panels[0].title)[0],
).toBeInTheDocument();
});

Expand All @@ -35,13 +32,14 @@ describe('PanelGrid', () => {
});

it('패널 제목을 누르면 해당 아이디의 패널 페이지로 이동한다', async () => {
const panel = createMockPanel();
const panelPages: GetMyPanelsResult[] = [{ panels: [panel] }];
const panelPage = { panels: createMockPanleList(10), nextPage: -1 };
const panelPages = [panelPage];
renderWithQueryClient(<PanelGrid panelPages={panelPages} />);

const panel = panelPage.panels[0];
const title = screen.getByText(panel.title);
await userEvent.click(title);

expect(navigateMockFn).toHaveBeenCalledWith(`/panel/${panel.id}`);
expect(navigateMockFn).toHaveBeenCalledWith(`/panel/${panel.sid}`);
});
});
5 changes: 3 additions & 2 deletions src/components/home/__tests__/PanelItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import type { Panel } from '@/lib/api/panel';

import React from 'react';

import { faker } from '@faker-js/faker';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { PanelItem } from '@/components/home/PanelItem';

const panel: Panel = {
id: 1,
author: '[email protected]',
sid: faker.datatype.uuid(),
title: '테스트 패널 제목',
description: '테스트 패널 설명',
authorId: 0,
createdAt: new Date().toDateString(),
updatedAt: new Date().toDateString(),
};
Expand Down
7 changes: 4 additions & 3 deletions src/components/home/__tests__/UpdatePanelModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type * as Vi from 'vitest';

import React from 'react';

import { faker } from '@faker-js/faker';
import { fireEvent, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

Expand All @@ -19,10 +20,10 @@ vi.mock('@/lib/validator', () => ({
const handleClose = vi.fn();

const panel: Panel = {
id: 1,
author: '[email protected]',
sid: faker.datatype.uuid(),
title: '테스트 패널 제목',
description: '테스트 패널 설명',
authorId: 0,
createdAt: new Date().toDateString(),
updatedAt: new Date().toDateString(),
};
Expand Down Expand Up @@ -77,7 +78,7 @@ describe('UpdatePanelModal', () => {

await userEvent.click(submitButton);

expect(spyOnUpdatePanel).toHaveBeenCalledWith(panel.id, {
expect(spyOnUpdatePanel).toHaveBeenCalledWith(panel.sid, {
title: '유효한 패널 제목',
description: '유효한 패널 설명',
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/panel/CreateQuestionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Button } from '@/components/system/Button';
import { useCreateQuestionMutation } from '@/hooks/queries/question';

interface Props {
panelId: Panel['id'];
panelId: Panel['sid'];
close: () => void;
}
export function CreateQuestionModal({ panelId, close }: Props): JSX.Element {
Expand Down
2 changes: 1 addition & 1 deletion src/components/panel/InfiniteQuestionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { IntersectionArea } from '../system/IntersectionArea';
import { QuestionList } from './QuestionList';

interface Props {
panelId: Panel['id'];
panelId: Panel['sid'];
}
type Sort = GetQuestionsParams['sort'];
export function InfiniteQuestionList({ panelId }: Props): JSX.Element {
Expand Down
5 changes: 2 additions & 3 deletions src/components/panel/PanelSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ interface Props {
panel: Panel;
}
export function PanelSidebar({ panel }: Props): JSX.Element {
const { id, title, author, createdAt, description } = panel;
const { sid, title, createdAt, description } = panel;
return (
<div className="flex flex-col justify-start w-[280px] divide-y divide-grey-light">
<div className="flex gap-4 p-5">
<span className="w-1 bg-primary" />
<div className="flex flex-col justify-start items-start">
<h2 className="font-medium">{title}</h2>
<div className="text-grey-dark text-sm">{author}</div>
<div className="text-grey-dark text-sm">
{formatToKRLocaleString(createdAt)}
</div>
Expand All @@ -29,7 +28,7 @@ export function PanelSidebar({ panel }: Props): JSX.Element {
type="button"
onClick={() => {
window.navigator.clipboard.writeText(
`${window.location.origin}/panel/${id}`,
`${window.location.origin}/panel/${sid}`,
);
}}
>
Expand Down
3 changes: 2 additions & 1 deletion src/components/panel/__tests__/CreateQuestionModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import type { Panel } from '@/lib/api/panel';

import React from 'react';

import { faker } from '@faker-js/faker';
import { fireEvent, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { CreateQuestionModal } from '@/components/panel/CreateQuestionModal';
import * as questionApis from '@/lib/api/question';
import { renderWithQueryClient } from '@/lib/test-utils';

const panelId: Panel['id'] = -1;
const panelId: Panel['sid'] = faker.datatype.uuid();
const handleClose = vi.fn();
describe('CreatePanelModal', () => {
it('사용자가 입력하는 글자수를 보여준다', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/panel/__tests__/InfiniteQuestionList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { QueryClient } from '@tanstack/react-query';

import React from 'react';

import { faker } from '@faker-js/faker';
import { fireEvent, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { rest } from 'msw';
Expand All @@ -16,7 +17,7 @@ import { delay } from '@/lib/test-utils/delay';
import { createMockQuestion } from '@/mocks/data/question';
import { server } from '@/mocks/server';

const panelId: Panel['id'] = 0;
const panelId: Panel['sid'] = faker.datatype.uuid();

describe('InfiniteQuestionList', () => {
describe('질문 목록 렌더링', () => {
Expand Down
3 changes: 1 addition & 2 deletions src/components/panel/__tests__/PanelSidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe('PanelSidebar', () => {
render(<PanelSidebar panel={panel} />);

expect(screen.getByText(panel.title)).toBeInTheDocument();
expect(screen.getByText(panel.author)).toBeInTheDocument();
expect(
screen.getByText(formatToKRLocaleString(panel.createdAt)),
).toBeInTheDocument();
Expand All @@ -37,7 +36,7 @@ describe('PanelSidebar', () => {

await userEvent.click(copyUrlButton);
expect(window.navigator.clipboard.writeText).toHaveBeenCalledWith(
`${window.location.origin}/panel/${panel.id}`,
`${window.location.origin}/panel/${panel.sid}`,
);
});
});
5 changes: 3 additions & 2 deletions src/hooks/queries/__tests__/question.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
GetQuestionsResult,
} from '@/lib/api/question';

import { faker } from '@faker-js/faker';
import { act, renderHook, waitFor } from '@testing-library/react';
import { rest } from 'msw';

Expand All @@ -20,7 +21,7 @@ import { server } from '@/mocks/server';

describe('question API queries', () => {
describe('useQuestionsInfiniteQuery', () => {
const panelId: Panel['id'] = -1;
const panelId: Panel['sid'] = faker.datatype.uuid();

it('getQuestions가 nextPage를 -1로 반환하면 hasNextPage는 false이다', async () => {
overrideGetQuestionsWith200({ questions: [], nextPage: -1 });
Expand Down Expand Up @@ -64,7 +65,7 @@ describe('question API queries', () => {

describe('createQuestionMutation', () => {
it('mutate를 호출하면 createQuestion 함수를 호출한다', async () => {
const panelId: Panel['id'] = -1;
const panelId: Panel['sid'] = faker.datatype.uuid();
const body: questionApis.CreateQuestionBody = {
content: '안녕하세요',
};
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/queries/active-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type ActiveInfoDetailQueryOptions =
NonNullableKeys<_ActiveInfoDetailQueryOptions>;

export const activeInfoDetailQuery = (
panelId: Panel['id'],
panelId: Panel['sid'],
): ActiveInfoDetailQueryOptions => ({
queryKey: queryKey.activeInfo.detail(panelId),
queryFn: async () => getMyActiveInfo(panelId).then((res) => res.result),
Expand Down
12 changes: 6 additions & 6 deletions src/hooks/queries/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import type {
LogInBody,
LogInResult,
SignUpBody,
SignUpResult,
SignUpError,
LoginError,
LogoutResult,
LogoutError,
SignUpResponse,
LogoutResponse,
} from '@/lib/api/auth';
import type { ApiError } from '@/lib/apiClient';
import type { UseMutationResult } from '@tanstack/react-query';
Expand All @@ -17,13 +17,13 @@ import { login, logout, signUp } from '@/lib/api/auth';
import { queryKey } from '@/lib/queryKey';

export const useSignUpMutation = (): UseMutationResult<
SignUpResult,
SignUpResponse,
ApiError<SignUpError | undefined> | SyntaxError,
SignUpBody
> => {
const key = queryKey.auth.signup();
const mutation = useMutation<
SignUpResult,
SignUpResponse,
ApiError<SignUpError | undefined> | SyntaxError,
SignUpBody
>(key, signUp);
Expand All @@ -45,13 +45,13 @@ export const useLoginMutation = (): UseMutationResult<
};

export const useLogoutMutation = (): UseMutationResult<
LogoutResult,
LogoutResponse,
ApiError<LogoutError | undefined> | SyntaxError,
void
> => {
const key = queryKey.auth.logout();
const mutation = useMutation<
LogoutResult,
LogoutResponse,
ApiError<LogoutError | undefined> | SyntaxError
>(key, logout);

Expand Down
Loading