Skip to content

Commit

Permalink
test:마지막 다락방 Id를 이용하게 테스트 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ss0526100 committed Aug 20, 2024
1 parent 1ba0327 commit 0098831
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 4 additions & 0 deletions frontend/src/hooks/queries/useChats.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '../../mocks/handler/chatHandler';

import { renderHook } from '@testing-library/react';
import { setLastDarakbangId } from '@_common/lastDarakbangManager';
import useChats from './useChats';

const queryClient = new QueryClient();
Expand All @@ -16,6 +17,9 @@ const wrapper = ({ children }: { children: ReactNode }) => (
);

describe('useChats', () => {
beforeEach(() => {
setLastDarakbangId(1);
});
afterEach(() => {
nowChatServerData.length = 0;
initChatIndex();
Expand Down
22 changes: 12 additions & 10 deletions frontend/src/mocks/handler/chatHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { HttpResponse, http } from 'msw';

import { Chat } from '@_types/index';
import mockedChats from './mockedChats';
import ENDPOINTS from '@_apis/endPoints';

let nowChatIndex = 0;

Expand All @@ -26,13 +25,16 @@ export const chatSliceIndexes = [
];

export const chatHandler = [
http.get(ENDPOINTS.chat, async ({ request }) => {
const url = new URL(request.url);

const recentChatId = +(url.searchParams.get('recentChatId') || 0);

return HttpResponse.json({
data: { chats: nowChatServerData.slice(recentChatId) },
});
}),
http.get(
`${process.env.BASE_URL}/v1/darakbang/1/chat`,
async ({ request }) => {
const url = new URL(request.url);

const recentChatId = +(url.searchParams.get('recentChatId') || 0);

return HttpResponse.json({
data: { chats: nowChatServerData.slice(recentChatId) },
});
},
),
];

0 comments on commit 0098831

Please sign in to comment.