// engine/test-scaffold-generator/unit-scaffold.ts — Unit test scaffold generators
// SPEC-018
import { generateMockCode, criteriaContainsMockKeyword } from '../test-mocks-generator.js';
import { toPascal, toSnake, getFrameworkExt, getFrameworkRunCommand } from './helpers.js';
// === Unit test scaffold ===
/**
 * Generate a unit test scaffold for a given spec title and framework.
 */
export function generateUnitTestScaffold(specTitle, specCriteria, framework) {
    const content = buildUnitContent(specTitle, specCriteria, framework);
    const ext = getFrameworkExt(framework);
    const runCommand = getFrameworkRunCommand(framework);
    return {
        filepath: `tests/unit/${toSnake(specTitle)}.test.${ext}`,
        content,
        framework,
        testType: 'unit',
        runCommand,
    };
}
function buildUnitContent(title, criteria, framework) {
    const base = buildBaseUnitContent(title, criteria, framework);
    if (!criteriaContainsMockKeyword(criteria)) {
        return base;
    }
    const mockExample = generateMockCode(framework, [`${title.replace(/\s+/g, '')}Service`], title);
    return `${base}\n// === Mock example for this spec ===\n${mockExample}`;
}
function buildBaseUnitContent(title, criteria, framework) {
    if (framework === 'pytest') {
        return buildPytestUnit(title, criteria);
    }
    if (framework === 'junit') {
        return buildJunitUnit(title, criteria);
    }
    return buildJsUnit(title, criteria, framework);
}
function buildJsUnit(title, criteria, framework) {
    const importLine = framework === 'vitest'
        ? "import { describe, it, expect } from 'vitest';"
        : "import { describe, it, expect } from '@jest/globals';";
    const tests = criteria
        .map((c) => `  it('${c}', () => {\n    // TODO: implement\n    expect(true).toBe(true);\n  });`)
        .join('\n\n');
    return `${importLine}\n\ndescribe('${title}', () => {\n${tests}\n});\n`;
}
function buildPytestUnit(title, criteria) {
    const cls = toPascal(title);
    const methods = criteria
        .map((c) => `    def test_${toSnake(c)}(self):\n        """${c}"""\n        # TODO: implement\n        assert True`)
        .join('\n\n');
    return `import pytest\n\n\nclass Test${cls}:\n    """Unit tests for ${title}."""\n\n${methods}\n`;
}
function buildJunitUnit(title, criteria) {
    const cls = toPascal(title);
    const methods = criteria
        .map((c) => `    @Test\n    void ${toSnake(c).replace(/_([a-z])/g, (_, l) => l.toUpperCase())}() {\n        // TODO: implement — ${c}\n        assertTrue(true);\n    }`)
        .join('\n\n');
    return `import org.junit.jupiter.api.Test;\nimport static org.junit.jupiter.api.Assertions.*;\n\nclass ${cls}Test {\n\n${methods}\n}\n`;
}
// === Integration test scaffold ===
/**
 * Generate an integration test scaffold.
 */
export function generateIntegrationTestScaffold(specTitle, framework) {
    const ext = getFrameworkExt(framework);
    const runCommand = getFrameworkRunCommand(framework);
    const content = buildIntegrationContent(specTitle, framework);
    return {
        filepath: `tests/integration/${toSnake(specTitle)}.integration.test.${ext}`,
        content,
        framework,
        testType: 'integration',
        runCommand,
    };
}
function buildIntegrationContent(title, framework) {
    if (framework === 'pytest') {
        const cls = toPascal(title);
        return `import pytest\n\n\nclass Test${cls}Integration:\n    """Integration tests for ${title}."""\n\n    def test_api_endpoint(self):\n        """Test API endpoint integration."""\n        # TODO: implement\n        assert True\n\n    def test_database_round_trip(self):\n        """Test database persistence."""\n        # TODO: implement\n        assert True\n`;
    }
    const importLine = framework === 'vitest'
        ? "import { describe, it, expect } from 'vitest';"
        : "import { describe, it, expect } from '@jest/globals';";
    return `${importLine}\n\ndescribe('${title} — Integration', () => {\n  it('should handle API endpoint correctly', async () => {\n    // TODO: implement\n    expect(true).toBe(true);\n  });\n\n  it('should persist data to storage', async () => {\n    // TODO: implement\n    expect(true).toBe(true);\n  });\n});\n`;
}
//# sourceMappingURL=unit-scaffold.js.map