All files / msw / handlers pipelines.ts

53.33% Statements 8/15
30% Branches 3/10
50% Functions 4/8
50% Lines 6/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33      47x   7x 42x 7x                   5x 1x                            
import { http, HttpResponse } from 'msw'
import { mockPipelines } from '@/msw/mock-data'
import { createMockPipeline } from '@/msw/data'
 
export const pipelineHandlers = [
  http.get('/api/v1/projects/:projectId/pipelines', ({ params }) => {
    const projectId = params.projectId as string
    const pipelines = mockPipelines.filter((p) => p.project_id === projectId)
    return HttpResponse.json({
      data: pipelines.length > 0 ? pipelines : [createMockPipeline({ project_id: projectId })],
      meta: { limit: 50, returned: Math.max(pipelines.length, 1), has_more: false },
    })
  }),
 
  http.get('/api/v1/pipelines/:id', ({ params }) => {
    const pipeline = mockPipelines.find((p) => p.id === params.id)
    return HttpResponse.json(pipeline ?? createMockPipeline({ id: params.id as string }))
  }),

  http.post('/api/v1/projects/:projectId/pipelines', async ({ params, request }) => {
    const body = (await request.json()) as { config?: Record<string, unknown> | null }
    return HttpResponse.json(createMockPipeline({ project_id: params.projectId as string, config: body.config ?? null }), { status: 201 })
  }),
 
  http.put('/api/v1/pipelines/:id', async ({ params, request }) => {
    const existing = mockPipelines.find((p) => p.id === params.id)
    const body = (await request.json()) as { config?: Record<string, unknown> | null }
    return HttpResponse.json(existing ?? createMockPipeline({ id: params.id as string, config: body.config ?? null }))
  }),

  http.delete('/api/v1/pipelines/:id', () => new HttpResponse(null, { status: 204 })),
]