|
18 | 18 | ********************************************************************************/ |
19 | 19 |
|
20 | 20 | import { environment } from '@env'; |
| 21 | +import { InvestigationStatus } from '@shared/model/investigations.model'; |
21 | 22 | import { rest } from 'msw'; |
22 | 23 | import { applyPagination, extractPagination } from '../pagination.helper'; |
23 | | -import { buildMockInvestigations } from './investigations.model'; |
| 24 | +import { buildMockInvestigations, getInvestigationById, InvestigationIdPrefix } from './investigations.model'; |
24 | 25 |
|
25 | 26 | export const investigationsHandlers = [ |
26 | | - rest.get(`${environment.apiUrl}/investigations/received`, (req, res, ctx) => { |
| 27 | + rest.get(`${environment.apiUrl}/investigations`, (req, res, ctx) => { |
27 | 28 | const pagination = extractPagination(req); |
28 | | - return res(ctx.status(200), ctx.json(applyPagination(buildMockInvestigations(['received']), pagination))); |
29 | | - }), |
| 29 | + const status = req.url.searchParams.get('status') ?? ''; |
30 | 30 |
|
31 | | - rest.get(`${environment.apiUrl}/investigations/queued-and-requested`, (req, res, ctx) => { |
32 | | - const pagination = extractPagination(req); |
33 | | - return res( |
34 | | - ctx.status(200), |
35 | | - ctx.json(applyPagination(buildMockInvestigations(['requested', 'queued']), pagination)), |
36 | | - ); |
| 31 | + const currentStatus = status.split(',') as InvestigationStatus[]; |
| 32 | + return res(ctx.status(200), ctx.json(applyPagination(buildMockInvestigations(currentStatus), pagination))); |
37 | 33 | }), |
38 | 34 |
|
39 | 35 | rest.post(`${environment.apiUrl}/investigations`, (_, res, ctx) => { |
40 | | - const investigations = buildMockInvestigations(['queued']); |
| 36 | + return res(ctx.status(200), ctx.json({ id: InvestigationIdPrefix + 1 })); |
| 37 | + }), |
| 38 | + |
| 39 | + rest.put(`${environment.apiUrl}/investigations/:investigationId/status`, (req, res, ctx) => { |
| 40 | + const { investigationId } = req.params; |
| 41 | + const { status } = req.body as Record<string, unknown>; |
41 | 42 |
|
42 | | - const response = { investigationId: investigations[0].id }; |
43 | | - return res(ctx.status(200), ctx.json(response)); |
| 43 | + const investigation = getInvestigationById(investigationId as string); |
| 44 | + return res(ctx.status(200), ctx.json({ ...investigation, status })); |
44 | 45 | }), |
45 | 46 | ]; |
0 commit comments