From da53a35e380dae87e7b20b6f756a6c52c73b825d Mon Sep 17 00:00:00 2001 From: DOBOB_LAPTOP Date: Fri, 3 Nov 2023 20:07:26 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20msw=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/mocks/handlers/songsHandlers.ts | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/frontend/src/mocks/handlers/songsHandlers.ts b/frontend/src/mocks/handlers/songsHandlers.ts index 01a793b4..fd56a3b2 100644 --- a/frontend/src/mocks/handlers/songsHandlers.ts +++ b/frontend/src/mocks/handlers/songsHandlers.ts @@ -2,7 +2,6 @@ import { rest } from 'msw'; import comments from '../fixtures/comments.json'; import extraNextSongDetails from '../fixtures/extraNextSongDetails.json'; import extraPrevSongDetails from '../fixtures/extraPrevSongDetails.json'; -import popularSongs from '../fixtures/popularSongs.json'; import recentSongs from '../fixtures/recentSongs.json'; import songEntries from '../fixtures/songEntries.json'; import type { KillingPartPostRequest } from '@/shared/types/killingPart'; @@ -10,11 +9,6 @@ import type { KillingPartPostRequest } from '@/shared/types/killingPart'; const { BASE_URL } = process.env; const songsHandlers = [ - rest.get(`${BASE_URL}/songs/high-liked`, (req, res, ctx) => { - // const genre = req.url.searchParams.get('genre') - return res(ctx.status(200), ctx.json(popularSongs)); - }), - rest.get(`${BASE_URL}/songs/:songId/parts/:partId/comments`, (req, res, ctx) => { return res(ctx.status(200), ctx.json(comments)); }), @@ -45,13 +39,24 @@ const songsHandlers = [ return res(ctx.status(200), ctx.json(songEntries)); }), rest.get(`${BASE_URL}/songs/high-liked/:songId/prev`, (req, res, ctx) => { - // const genre = req.url.searchParams.get('genre') - return res(ctx.status(200), ctx.json(extraPrevSongDetails)); + // const genre = req.url.searchParams.get('genre'); + const { songId } = req.params; + + const targetIdx = extraPrevSongDetails.findIndex((song) => song.id === Number(songId)); + const sliced = extraPrevSongDetails.slice(0, targetIdx); + + return res(ctx.status(200), ctx.json(sliced)); }), rest.get(`${BASE_URL}/songs/high-liked/:songId/next`, (req, res, ctx) => { // const genre = req.url.searchParams.get('genre') - return res(ctx.status(200), ctx.json(extraNextSongDetails)); + + const { songId } = req.params; + + const targetIdx = extraNextSongDetails.findIndex((song) => song.id === Number(songId)); + const sliced = extraNextSongDetails.slice(targetIdx); + + return res(ctx.status(200), ctx.json(sliced)); }), rest.get(`${BASE_URL}/songs/recent`, (req, res, ctx) => {