// engine/test-mocks-generator/mock-templates.ts — SPEC-018 multi-language mock templates
// Code generation templates for unit test mocks across frameworks.
import { MOCK_TEMPLATES_B } from './mock-templates-b.js';
// === Template functions ===
function vitestMockTemplate(targets, title) {
    const mocks = targets
        .map((t) => `vi.mock('./${t}', () => ({\n  default: vi.fn(),\n  ${t}: vi.fn(),\n}));`)
        .join('\n\n');
    const stubs = targets
        .map((t) => `const mock${t} = vi.fn();\nmock${t}.mockResolvedValue({ id: '1', success: true });`)
        .join('\n');
    return [
        `// ${title} — Vitest mock setup`,
        "import { describe, it, expect, vi, beforeEach } from 'vitest';",
        '',
        '// Module-level mocks (hoisted automatically by Vitest)',
        mocks,
        '',
        `describe('${title}', () => {`,
        '  beforeEach(() => {',
        '    vi.clearAllMocks();',
        '  });',
        '',
        '  // Inline function stubs',
        stubs
            .split('\n')
            .map((l) => `  ${l}`)
            .join('\n'),
        '',
        "  it('should call mocked dependency', async () => {",
        /* v8 ignore next 1 */ `    const result = await mock${targets[0] ?? 'Service'}();`,
        "    expect(result).toEqual({ id: '1', success: true });",
        /* v8 ignore next 1 */ `    expect(mock${targets[0] ?? 'Service'}).toHaveBeenCalledOnce();`,
        '  });',
        '});',
        '',
    ].join('\n');
}
function jestMockTemplate(targets, title) {
    const mocks = targets.map((t) => `jest.mock('./${t}');`).join('\n');
    const stubs = targets
        .map((t) => `const mock${t} = jest.fn().mockResolvedValue({ id: '1', success: true });`)
        .join('\n');
    return [
        `// ${title} — Jest mock setup`,
        "import { describe, it, expect, jest, beforeEach } from '@jest/globals';",
        '',
        mocks,
        '',
        stubs,
        '',
        `describe('${title}', () => {`,
        '  beforeEach(() => {',
        '    jest.clearAllMocks();',
        '  });',
        '',
        "  it('should call mocked dependency', async () => {",
        /* v8 ignore next 1 */ `    const result = await mock${targets[0] ?? 'Service'}();`,
        "    expect(result).toEqual({ id: '1', success: true });",
        /* v8 ignore next 1 */ `    expect(mock${targets[0] ?? 'Service'}).toHaveBeenCalled();`,
        '  });',
        '});',
        '',
    ].join('\n');
}
function pytestMockTemplate(targets, title) {
    const imports = targets
        .map((t) => {
        const mod = t.charAt(0).toLowerCase() + t.slice(1);
        return `from app.${mod} import ${t}`;
    })
        .join('\n');
    const patches = targets
        .map((t) => {
        const mod = t.charAt(0).toLowerCase() + t.slice(1);
        return `@pytest.fixture\ndef mock_${mod}(mocker):\n    """Patch ${t} for unit testing."""\n    return mocker.patch('app.${mod}.${t}', return_value={'id': '1', 'success': True})`;
    })
        .join('\n\n');
    // targets always has ≥1 item (guaranteed by generateMockCode) — false branch unreachable
    /* v8 ignore start */
    const testMethod = targets[0]
        ? `    mock_${targets[0].charAt(0).toLowerCase() + targets[0].slice(1)}.assert_called_once()`
        : '    # TODO: assert mock was called';
    /* v8 ignore stop */
    return [
        `# ${title} — pytest mock setup (pytest-mock)`,
        'import pytest',
        imports,
        '',
        '',
        patches,
        '',
        '',
        `class Test${title.replace(/\s+/g, '')}:`,
        `    """Unit tests for ${title} with mocked dependencies."""`,
        '',
        `    def test_calls_dependency(self, ${targets.map((t) => `mock_${t.charAt(0).toLowerCase() + t.slice(1)}`).join(', ')}):`,
        `        """Verify that dependencies are properly mocked."""`,
        '        # Arrange: mock already set up via fixtures',
        '        # Act',
        '        result = True  # TODO: call the function under test',
        '        # Assert',
        testMethod,
        '        assert result is True',
        '',
    ].join('\n');
}
export const MOCK_TEMPLATES = {
    vitest: vitestMockTemplate,
    jest: jestMockTemplate,
    pytest: pytestMockTemplate,
    ...MOCK_TEMPLATES_B,
};
//# sourceMappingURL=mock-templates.js.map