feat: add .spec.ts generation for models, mappers, repositories and use-cases
Add 4 new Mustache templates for generating unit test specs: - model-entity.spec.mustache: tests instantiation, property setting, mock builder - mapper.spec.mustache: tests per-property DTO→Entity mapping, instanceof, all fields - api.repository.impl.spec.mustache: tests HTTP method, response mapping, error propagation - api.use-cases.impl.spec.mustache: tests repository delegation, observable forwarding Generator changes: - Add uppercaseHttpMethod to TagOperation for spec HTTP assertions - Add testValue to TagOperationParam for auto-generated test arguments - Add resolveTestParamValue utility for primitive/complex type test literals - Add specs counter to GeneratedCount and GenerationReport - Wire 4 new renderTemplate calls in schema and tag loops - Update report generator to count .spec.ts files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -12,6 +12,15 @@ function countMockFiles(dir: string): number {
|
||||
}
|
||||
}
|
||||
|
||||
/** Counts files ending with `.spec.ts` in a directory (returns 0 if directory does not exist). */
|
||||
function countSpecFiles(dir: string): number {
|
||||
try {
|
||||
return fs.readdirSync(dir).filter((f) => f.endsWith('.spec.ts')).length;
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/** Generates and persists the `generation-report.json` file with process statistics. */
|
||||
export function generateReport(outputDir: string, analysis: SwaggerAnalysis): GenerationReport {
|
||||
logStep('Generating report...');
|
||||
@@ -35,7 +44,12 @@ export function generateReport(outputDir: string, analysis: SwaggerAnalysis): Ge
|
||||
countMockFiles(path.join(outputDir, 'di/repositories')) +
|
||||
countMockFiles(path.join(outputDir, 'di/use-cases')) +
|
||||
countMockFiles(path.join(outputDir, 'domain/use-cases')) +
|
||||
countMockFiles(path.join(outputDir, 'entities/models'))
|
||||
countMockFiles(path.join(outputDir, 'entities/models')),
|
||||
specs:
|
||||
countSpecFiles(path.join(outputDir, 'entities/models')) +
|
||||
countSpecFiles(path.join(outputDir, 'data/mappers')) +
|
||||
countSpecFiles(path.join(outputDir, 'data/repositories')) +
|
||||
countSpecFiles(path.join(outputDir, 'domain/use-cases'))
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user