All files / msw data.ts

90.47% Statements 19/21
50% Branches 10/20
66.66% Functions 2/3
90.47% Lines 19/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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 12769x   8x 8x           8x                           8x                           8x           8x 8x 8x 8x 8x 8x 8x                                                     69x                                                             69x                                      
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?: Record<string, unknown>): 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',
    branch: null,
    skillRepos: [
      { repository_id: 'repo-2', name: 'org/docs', url: 'github.com:org/docs.git' },
    ],
  },
  {
    name: 'PR Review',
    branch: 'review-output',
    skillRepos: [
      { repository_id: 'repo-3', name: 'org/gateway', url: 'git@github.com:org/gateway.git' },
    ],
  },
  {
    name: 'Release build',
    branch: 'release-output',
    skillRepos: [],
  },
]
 
const mockRepoIds = ['repo-1', 'repo-2', 'repo-3']
 
export function createMockPipeline(overrides?: Record<string, unknown>): 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 as string ?? 'proj-1'] ?? 'My Application',
    name: def.name,
    code_repo_id: mockRepoIds[Math.floor(Math.random() * mockRepoIds.length)],
    manifest_repo_id: 'repo-4',
    output_branch: def.branch,
    enabled: true,
    description: null,
    skill_repos: def.skillRepos,
    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
}