Skip to content

Commit

Permalink
fix: msw 잘못된 요청을 수정합니다
Browse files Browse the repository at this point in the history
  • Loading branch information
Zero-1016 committed May 26, 2024
1 parent 060bde2 commit db867f1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/entities/mock/api/handler/movie/bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const bookmarkHandlers = [
const { movieId } = params

if (!movieId) {
return HttpResponse.json({ status: 400, statusText: '영화 아이디가 없습니다.' })
return HttpResponse.json(null, { status: 400, statusText: '영화 아이디가 없습니다.' })
}

return HttpResponse.json(
Expand All @@ -28,7 +28,7 @@ export const bookmarkHandlers = [
const { movieId } = params

if (!movieId) {
return HttpResponse.json({ status: 400, statusText: '영화 아이디가 없습니다.' })
return HttpResponse.json(null, { status: 400, statusText: '영화 아이디가 없습니다.' })
}

return HttpResponse.json(
Expand Down
4 changes: 2 additions & 2 deletions src/entities/mock/api/handler/movie/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const reviewHandlers = [
const { reviewId } = params

if (!reviewId) {
return HttpResponse.json({ status: 400, statusText: '수정할 리뷰가 없습니다.' })
return HttpResponse.json(null, { status: 400, statusText: '수정할 리뷰가 없습니다.' })
}

return HttpResponse.json(reviewId, { status: 201, statusText: '리뷰를 수정하였습니다.' })
Expand All @@ -62,7 +62,7 @@ export const reviewHandlers = [
const { reviewId } = params

if (!reviewId) {
return HttpResponse.json({ status: 400, statusText: '삭제할 좋아요한 리뷰가 없습니다.' })
return HttpResponse.json(null, { status: 400, statusText: '삭제할 좋아요한 리뷰가 없습니다.' })
}

return HttpResponse.json(reviewId, { status: 201, statusText: '리뷰 좋아요를 취소하였습니다.' })
Expand Down
20 changes: 8 additions & 12 deletions src/entities/mock/api/handler/user/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { http, HttpResponse } from 'msw'

import { generateProfileContent } from '@/entities/mock/generate/profile-content'
import { MyLikeMovie } from '@/entities/movie/model/movie'
import { MyBookMarkResponse, MyReviewResponse } from '@/entities/movie/model/response'

const allUser = new Map()

Expand Down Expand Up @@ -71,7 +70,7 @@ export const userHandlers = [
}
const cur_page = parseInt(page)

const responseData: MyBookMarkResponse = {
return HttpResponse.json({
results: Array(faker.number.int(10))
.fill('')
.map(() => {
Expand Down Expand Up @@ -109,43 +108,40 @@ export const userHandlers = [
page: cur_page,
total_pages: 10,
total_results: 190,
}
return HttpResponse.json(responseData, { status: 201 })
})
}),

http.get('/user/review', ({ request }) => {
const url = new URL(request.url)
const page = url.searchParams.get('page')
const movieId = url.searchParams.get('movieId')
if (!page || !movieId) {
return HttpResponse.json('failure', { status: 400, statusText: '잘못된 리뷰 요청입니다.' })
return HttpResponse.json(null, { status: 400, statusText: '잘못된 리뷰 요청입니다.' })
}
const cur_page = parseInt(page)

const responseData: MyReviewResponse = {
return HttpResponse.json({
results: generateProfileContent(faker.number.int(10)),
page: cur_page,
total_pages: 10,
total_results: 90,
}
return HttpResponse.json(responseData, { status: 201 })
})
}),

http.get('/user/famousLine', ({ request }) => {
const url = new URL(request.url)
const page = url.searchParams.get('page')
const movieId = url.searchParams.get('movieId')
if (!page || !movieId) {
return HttpResponse.json('failure', { status: 400, statusText: '잘못된 명대사 요청입니다.' })
return HttpResponse.json(null, { status: 400, statusText: '잘못된 명대사 요청입니다.' })
}
const cur_page = parseInt(page)

const responseData: MyReviewResponse = {
return HttpResponse.json({
results: generateProfileContent(faker.number.int(10)),
page: cur_page,
total_pages: 10,
total_results: 90,
}
return HttpResponse.json(responseData, { status: 201 })
})
}),
]

0 comments on commit db867f1

Please sign in to comment.