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์— ๋Œ€ํ•ด delay ์„ค์ • #46

Merged
merged 5 commits into from
May 10, 2024
10 changes: 7 additions & 3 deletions src/app/mocks/dir/response.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { HttpResponse } from 'msw';
import { HttpResponse, delay } from 'msw';

import { errorMessage } from '../consts/error';

export function createHttpSuccessResponse<T>(data: T) {
export async function createHttpSuccessResponse<T>(data: T) {
await delay();

return HttpResponse.json(
{
code: '2000',
Expand All @@ -12,7 +14,9 @@ export function createHttpSuccessResponse<T>(data: T) {
);
}

export function createHttpErrorResponse(code: keyof typeof errorMessage) {
export async function createHttpErrorResponse(code: keyof typeof errorMessage) {
await delay();

return HttpResponse.json(
{
code,
Expand Down
6 changes: 2 additions & 4 deletions src/app/mocks/handler/feed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { delay, http } from 'msw';
import { http } from 'msw';

import { feeds } from '../consts/feed';
import { reports } from '../consts/report';
Expand Down Expand Up @@ -28,7 +28,7 @@ export const feedHandlers = [
/**
* @todo pageCount๋ฅผ ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›๋„๋ก ์ˆ˜์ •
*/
http.get('/feeds', async ({ request }) => {
http.get('/feeds', ({ request }) => {
const url = new URL(request.url);
const page = url.searchParams.get('page') || 1;
const count = url.searchParams.get('count') || 10;
Expand All @@ -48,8 +48,6 @@ export const feedHandlers = [
const endOfPageRange = formattedPage * pageCount;
const hasNextPage = endOfPageRange < totalFeeds;

await delay(Math.floor(Math.random() * 4000));

return createHttpSuccessResponse({
feeds: feedsData,
currentPageNumber: pageCount,
Expand Down
Loading