|
| 1 | +import { http, HttpResponse } from 'msw' |
| 2 | +import { mockIdea, mockIdeaLiked } from './idea.mock' |
| 3 | +import { mockComment } from './comment.mock' |
| 4 | +import { mockCurrentUser, mockAuthor } from './user.mock' |
| 5 | + |
| 6 | +const API_URL = 'http://localhost:3000/v1' |
| 7 | + |
| 8 | +export const handlers = [ |
| 9 | + http.post(`${API_URL}/like`, () => { |
| 10 | + return HttpResponse.json({ success: true }) |
| 11 | + }), |
| 12 | + |
| 13 | + http.post(`${API_URL}/view`, () => { |
| 14 | + return HttpResponse.json({ success: true }) |
| 15 | + }), |
| 16 | + |
| 17 | + http.post(`${API_URL}/comment`, () => { |
| 18 | + return HttpResponse.json(mockComment) |
| 19 | + }), |
| 20 | + |
| 21 | + http.post(`${API_URL}/collaboration-request`, () => { |
| 22 | + return HttpResponse.json({ success: true }) |
| 23 | + }), |
| 24 | + |
| 25 | + http.patch(`${API_URL}/collaboration-approval`, () => { |
| 26 | + return HttpResponse.json({ success: true }) |
| 27 | + }), |
| 28 | + |
| 29 | + http.post(`${API_URL}/follow`, () => { |
| 30 | + return HttpResponse.json({ success: true }) |
| 31 | + }), |
| 32 | + |
| 33 | + http.post(`${API_URL}/idea`, () => { |
| 34 | + return HttpResponse.json(mockIdea) |
| 35 | + }), |
| 36 | + |
| 37 | + http.patch(`${API_URL}/idea/:id`, ({ params }) => { |
| 38 | + return HttpResponse.json({ |
| 39 | + ...mockIdea, |
| 40 | + id: params.id, |
| 41 | + }) |
| 42 | + }), |
| 43 | + |
| 44 | + http.delete(`${API_URL}/idea/:id`, () => { |
| 45 | + return HttpResponse.json({ success: true }) |
| 46 | + }), |
| 47 | + |
| 48 | + http.get(`${API_URL}/idea`, () => { |
| 49 | + return HttpResponse.json({ |
| 50 | + data: [mockIdea, mockIdeaLiked], |
| 51 | + total: 2, |
| 52 | + page: 0, |
| 53 | + quantity: 10, |
| 54 | + }) |
| 55 | + }), |
| 56 | + |
| 57 | + http.get(`${API_URL}/idea/:id`, ({ params }) => { |
| 58 | + return HttpResponse.json({ |
| 59 | + ...mockIdea, |
| 60 | + id: params.id, |
| 61 | + }) |
| 62 | + }), |
| 63 | + |
| 64 | + http.get(`${API_URL}/comment`, () => { |
| 65 | + return HttpResponse.json({ |
| 66 | + data: [mockComment], |
| 67 | + total: 1, |
| 68 | + page: 0, |
| 69 | + quantity: 10, |
| 70 | + }) |
| 71 | + }), |
| 72 | + |
| 73 | + http.get(`${API_URL}/user/my-user`, () => { |
| 74 | + return HttpResponse.json(mockCurrentUser) |
| 75 | + }), |
| 76 | + |
| 77 | + http.get(`${API_URL}/user/:id`, () => { |
| 78 | + return HttpResponse.json(mockAuthor) |
| 79 | + }), |
| 80 | + |
| 81 | + http.get(`${API_URL}/user`, ({ request }) => { |
| 82 | + const url = new URL(request.url) |
| 83 | + const pathname = url.pathname |
| 84 | + |
| 85 | + if (pathname.endsWith('/my-user')) { |
| 86 | + return HttpResponse.json(mockCurrentUser) |
| 87 | + } |
| 88 | + |
| 89 | + if (pathname.match(/\/user\/[^/]+$/)) { |
| 90 | + return HttpResponse.json(mockAuthor) |
| 91 | + } |
| 92 | + |
| 93 | + return HttpResponse.json({ |
| 94 | + data: [mockCurrentUser, mockAuthor], |
| 95 | + total: 2, |
| 96 | + page: 0, |
| 97 | + quantity: 10, |
| 98 | + }) |
| 99 | + }), |
| 100 | + |
| 101 | + http.patch(`${API_URL}/user`, () => { |
| 102 | + return HttpResponse.json(mockCurrentUser) |
| 103 | + }), |
| 104 | + |
| 105 | + http.delete(`${API_URL}/user`, () => { |
| 106 | + return HttpResponse.json({ success: true }) |
| 107 | + }), |
| 108 | +] |
| 109 | + |
0 commit comments