export type TestType = 'unit' | 'integration' | 'e2e' | 'performance' | 'security'; export type TestFramework = 'jest' | 'mocha' | 'vitest' | 'cypress' | 'playwright' | 'generic'; export interface TestSuggestion { readonly id: string; readonly testType: TestType; readonly framework: TestFramework; readonly description: string; readonly testCode: string; readonly setupCode?: string; readonly targetFunction?: string; readonly targetFile?: string; readonly testCases: TestCase[]; readonly coverage?: TestCoverage; } export interface TestCase { readonly name: string; readonly description: string; readonly input: Record; readonly expectedOutput?: unknown; readonly expectedBehavior?: string; readonly shouldThrow?: boolean; readonly expectedError?: string; } export interface TestCoverage { readonly lines: number; readonly branches: number; readonly functions: number; readonly statements: number; } export interface TestSuggestionBuilder { id(id: string): TestSuggestionBuilder; testType(testType: TestType): TestSuggestionBuilder; framework(framework: TestFramework): TestSuggestionBuilder; description(description: string): TestSuggestionBuilder; testCode(testCode: string): TestSuggestionBuilder; setupCode(setupCode: string): TestSuggestionBuilder; targetFunction(targetFunction: string): TestSuggestionBuilder; targetFile(targetFile: string): TestSuggestionBuilder; addTestCase(testCase: TestCase): TestSuggestionBuilder; testCases(testCases: TestCase[]): TestSuggestionBuilder; coverage(coverage: TestCoverage): TestSuggestionBuilder; build(): TestSuggestion; } export class TestSuggestionImpl implements TestSuggestionBuilder { private suggestion: any = { testCases: [], }; id(id: string): TestSuggestionBuilder { this.suggestion.id = id; return this; } testType(testType: TestType): TestSuggestionBuilder { this.suggestion.testType = testType; return this; } framework(framework: TestFramework): TestSuggestionBuilder { this.suggestion.framework = framework; return this; } description(description: string): TestSuggestionBuilder { this.suggestion.description = description; return this; } testCode(testCode: string): TestSuggestionBuilder { this.suggestion.testCode = testCode; return this; } setupCode(setupCode: string): TestSuggestionBuilder { this.suggestion.setupCode = setupCode; return this; } targetFunction(targetFunction: string): TestSuggestionBuilder { this.suggestion.targetFunction = targetFunction; return this; } targetFile(targetFile: string): TestSuggestionBuilder { this.suggestion.targetFile = targetFile; return this; } addTestCase(testCase: TestCase): TestSuggestionBuilder { if (!this.suggestion.testCases) { this.suggestion.testCases = []; } this.suggestion.testCases.push(testCase); return this; } testCases(testCases: TestCase[]): TestSuggestionBuilder { this.suggestion.testCases = testCases; return this; } coverage(coverage: TestCoverage): TestSuggestionBuilder { this.suggestion.coverage = coverage; return this; } build(): TestSuggestion { if (!this.suggestion.id || !this.suggestion.testType || !this.suggestion.framework || !this.suggestion.description || !this.suggestion.testCode || !this.suggestion.testCases) { throw new Error('Required fields missing for TestSuggestion'); } return { id: this.suggestion.id, testType: this.suggestion.testType, framework: this.suggestion.framework, description: this.suggestion.description, testCode: this.suggestion.testCode, setupCode: this.suggestion.setupCode, targetFunction: this.suggestion.targetFunction, targetFile: this.suggestion.targetFile, testCases: this.suggestion.testCases, coverage: this.suggestion.coverage, }; } }