All files / msw data.ts

76.19% Statements 16/21
60% Branches 12/20
33.33% Functions 1/3
76.19% Lines 16/21

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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 11146x   7x 7x           7x                           7x                           7x           7x 7x 7x 7x 7x 7x 7x                                                     46x                                                             46x      
import type { components } from '@/types/api'
 
type Run = components['schemas']['Run']
type Project = components['schemas']['Project']
type Pipeline = components['schemas']['Pipeline']
 
let runId = 0
 
export function createMockRun(overrides?: Partial<Run>): Run {
  runId++
  const phases = ['pending', 'running', 'succeeded', 'failed'] as const
  const projects = [
    { id: crypto.randomUUID(), name: 'My Application' },
    { id: crypto.randomUUID(), name: 'Documentation Site' },
    { id: crypto.randomUUID(), name: 'API Gateway' },
  ]
  const pipelines = [
    { id: crypto.randomUUID(), name: 'Doc quality' },
    { id: crypto.randomUUID(), name: 'PR Review' },
    { id: crypto.randomUUID(), name: 'Release build' },
  ]
  const sources = ['manual', 'webhook', 'api', 'schedule'] as const
  const phase = overrides?.phase ?? phases[Math.floor(Math.random() * 4)]
  const project = projects[Math.floor(Math.random() * 3)]
  const pipeline = pipelines[Math.floor(Math.random() * 3)]
  const source = sources[Math.floor(Math.random() * 4)]
  const daysAgo = Math.floor(Math.random() * 7)
  const created = new Date(Date.now() - daysAgo * 86400000 - Math.random() * 3600000).toISOString()
 
  return {
    run_id: `run-${runId}`,
    phase,
    run_number: runId + 24300,
    project_id: project.id,
    project_name: project.name,
    pipeline_id: pipeline.id,
    pipeline_name: pipeline.name,
    source_type: source,
    source_metadata: null,
    error: phase === 'failed'
      ? { message: 'Pipeline step failed', code: 'EXECUTION_ERROR', step: 'analyze', details: null }
      : null,
    output: phase === 'succeeded'
      ? 'Pipeline completed successfully.\n- Step analyze: All checks passed\n- Step review: Approved\n- Output: agent-platform/pipeline-1/output'
      : null,
    exit_code: phase === 'failed' ? 1 : 0,
    token_input: Math.floor(Math.random() * 100000),
    token_output: Math.floor(Math.random() * 50000),
    created_at: created,
    updated_at: created,
    started_at: phase !== 'pending' ? created : null,
    completed_at: phase === 'succeeded' || phase === 'failed' ? new Date().toISOString() : null,
    ...overrides,
  } as Run
}
 
const staticProjects = [
  { id: 'proj-1', name: 'My Application', count: 3 },
  { id: 'proj-2', name: 'Documentation Site', count: 1 },
  { id: 'proj-3', name: 'API Gateway', count: 5 },
]
 
export function createMockProject(overrides?: Partial<Project>): Project {
  const p = staticProjects[Math.floor(Math.random() * 3)]
  return {
    id: p.id,
    name: p.name,
    description: p.id === 'proj-1' ? 'Main application repository' : null,
    pipeline_count: p.count,
    created_by: 'user-1',
    updated_by: 'user-1',
    created_at: new Date(Date.now() - 30 * 86400000).toISOString(),
    updated_at: new Date().toISOString(),
    ...overrides,
  } as Project
}
 
const mockPipelineDefs = [
  { name: 'Doc quality', path: 'manifests/doc-quality/', branch: null },
  { name: 'PR Review', path: 'manifests/review-pr/', branch: 'review-output' },
  { name: 'Release build', path: 'manifests/release/', branch: 'release-output' },
]
 
const mockRepoIds = ['repo-1', 'repo-2', 'repo-3']
 
export function createMockPipeline(overrides?: Partial<Pipeline>): Pipeline {
  const def = mockPipelineDefs[Math.floor(Math.random() * 3)]
  const projectNameMap: Record<string, string> = {
    'proj-1': 'My Application',
    'proj-2': 'Documentation Site',
    'proj-3': 'API Gateway',
  }
  return {
    id: crypto.randomUUID(),
    project_id: 'proj-1',
    project_name: projectNameMap[overrides?.project_id ?? 'proj-1'] ?? 'My Application',
    name: def.name,
    code_repo_id: mockRepoIds[Math.floor(Math.random() * mockRepoIds.length)],
    manifest_repo_id: 'repo-4',
    manifest_path: def.path,
    output_branch: def.branch,
    enabled: true,
    description: null,
    created_by: 'user-1',
    updated_by: 'user-1',
    created_at: new Date(Date.now() - 30 * 86400000).toISOString(),
    updated_at: new Date().toISOString(),
    ...overrides,
  } as Pipeline
}