import { describe, it, expect, vi, beforeEach } from 'vitest';
import { suggestIssueFix } from '../../seo/issue-fix.js';
const suggestAiFixMock = vi.fn();
vi.mock('../../seo/issue-fix-ai.js', () => ({
    AI_FIX_TYPES: new Set(['duplicate-meta-title', 'missing-structured-data']),
    suggestAiFix: (...args) => suggestAiFixMock(...args),
}));
const entity = {
    entityType: 'page',
    entityId: 'doc-1',
    title: 'About',
    url: '/about',
    content: '<p>About us content here with enough words for SEO testing purposes.</p>',
    metaTitle: 'Shared Title',
    metaDescription: null,
    canonicalUrl: 'https://example.com/about',
    noindex: false,
};
describe('suggestIssueFix', () => {
    beforeEach(() => {
        suggestAiFixMock.mockReset();
    });
    it('returns deterministic fix without calling AI when available', async () => {
        const result = await suggestIssueFix({ type: 'accidental-noindex', title: 'Noindex', entityType: 'page', entityId: 'doc-1' }, { entity: { ...entity, noindex: true }, updatedAt: '2024-01-01T00:00:00.000Z' });
        expect(result.cacheForApply).toBe(false);
        expect(result.suggestion.source).toBe('deterministic');
        expect(result.suggestion.autoFixable).toBe(true);
        expect(suggestAiFixMock).not.toHaveBeenCalled();
    });
    it('falls back to AI for duplicate-meta-title', async () => {
        suggestAiFixMock.mockResolvedValue({
            ok: true,
            suggestion: {
                autoFixable: true,
                source: 'ai',
                fingerprint: 'doc-1:1:duplicate-meta-title',
                patch: { metaTitle: 'Unique About Page Title' },
                changes: [],
                justification: 'AI title',
            },
        });
        const result = await suggestIssueFix({ type: 'duplicate-meta-title', title: 'Dup', entityType: 'page', entityId: 'doc-1' }, { entity, updatedAt: '2024-01-01T00:00:00.000Z' }, { db: {}, userId: 'u1', collection: 'pages' });
        expect(suggestAiFixMock).toHaveBeenCalled();
        expect(result.cacheForApply).toBe(true);
        expect(result.suggestion.source).toBe('ai');
    });
});
//# sourceMappingURL=issue-fix-orchestrator.test.js.map