Skip to content

Commit

Permalink
๐Ÿ› ๏ธ ํ˜„์‹ค์ ์ธ ํ™˜๊ฒฝ ๊ตฌ์ถ•์„ ์œ„ํ•ด ๋ชจ๋“  API์— ๋Œ€ํ•ด delay ์„ค์ • (#46)
Browse files Browse the repository at this point in the history
* feat: Http ์„ฑ๊ณต ๋ฐ ์‹คํŒจ ์‘๋‹ต ์ƒ์„ฑ ํ•จ์ˆ˜ delay ์ ์šฉ
* feat: ํ”ผ๋“œ ๋ชฉ๋ก ์กฐํšŒ delay ์ œ๊ฑฐ
* feat: ์‘๋‹ต ์‹œ๊ฐ„ ๋ณ€์ˆ˜ ์ ์šฉ
* feat: delay ์ฃผ์„ ์ฒ˜๋ฆฌ
* feat: delay default ํŒŒ๋ผ๋ฉ”ํ„ฐ๋กœ ์ˆ˜์ •

Closes #45
  • Loading branch information
BangDori authored May 10, 2024
1 parent 261b4ac commit 06b6377
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
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

0 comments on commit 06b6377

Please sign in to comment.