/** * ADR-190-A — docs-hub SSR-lite: guards, render output, escaping, sitemap. * * AC-4 is the test that matters: a password-protected or non-external space is * force-noindex and force-excluded from the sitemap EVEN WITH indexable:true. * AC-9 re-asserts the ADR-190 escaping contract on this new surface. * * Both the DB and the public loaders are mocked — hermetic, no master (ADR-0009). */ import { describe, it, expect, vi, beforeEach } from 'vitest'; const getPublicSpaceBySlug = vi.fn(); const listIndexableSpaces = vi.fn(); const loadPublicDocumentsRegistry = vi.fn(); const loadPublicDocument = vi.fn(); // Keep the real readPublicSeoPrefs — the guard logic under test depends on it. vi.mock('../SpaceVisibilityService.js', async (importOriginal) => { const actual = await importOriginal(); return { ...actual, getPublicSpaceBySlug, listIndexableSpaces }; }); // blogSeo pulls fetchPublicRows from public.js; stub the whole module so the // DB graph never loads (same trick as blogSeo.test.js). vi.mock('../../routes/v3/public.js', () => ({ fetchPublicRows: vi.fn(), loadPublicDocumentsRegistry, loadPublicDocument, })); vi.mock('../../database/connection.js', () => ({ dbGet: vi.fn(), dbRun: vi.fn(), dbAll: vi.fn(), })); const mod = await import('../publicDocsSeo.js'); const { renderDocPage, renderHubPage, renderDocBody, collectDocsSitemapUrls, registerPublicDocsSeoRoutes, } = mod; const SEO = { indexable: true, in_sitemap: true, site_origin: 'https://godcrm.ai', site_name: 'GOD CRM', title_template: '%s — GOD CRM Docs', default_description: 'GOD CRM documentation — spaces, tables, agents, modules and widgets.', og_image: '/og/docs.png', default_lang: 'en', }; const DOC = { id: 46043, slug: '01-what-is-god-crm', name: 'What is GOD CRM?', description: 'A CRM you describe in plain language instead of configuring.', status: 'published', seo_title: '', seo_description: '', seo_noindex: false, created_at: '2026-06-01T10:00:00Z', updated_at: '2026-06-22T10:55:38Z', }; const ITEMS = [ { level: 'text', content_en: 'GOD CRM is a **universal** system.', content_ru: 'Это система.' }, { level: 'h2', content_en: 'The One-Sentence Answer', content_ru: 'Ответ' }, { level: 'divider', content_en: '', content_ru: '' }, { level: 'text', content_en: '', content_ru: 'Только по-русски.' }, ]; const TEMPLATE = [ '
', '