import { beforeEach, describe, expect, it } from 'vitest';
import { handleActuateAPI } from '../../api/index.js';
import { initDB } from '../../db.js';
function createMockDB(docs) {
    const findMany = async (args) => {
        const where = args?.where ?? {};
        return docs.filter((d) => {
            if (where.status && d.status !== where.status)
                return false;
            if (where.deletedAt === null && d.deletedAt !== null)
                return false;
            return true;
        });
    };
    return {
        document: { findMany, findFirst: async () => null, count: async () => 0 },
        user: {},
        session: {},
        media: {},
    };
}
const PUBLIC_PAGE = {
    title: 'Public About Page',
    slug: 'about',
    collection: 'pages',
    status: 'PUBLISHED',
    deletedAt: null,
    updatedAt: new Date('2026-03-01T00:00:00Z'),
    data: { metaDescription: 'About us' },
};
const SOFT_DELETED = {
    title: 'Deleted Secret Page',
    slug: 'deleted-secret',
    collection: 'pages',
    status: 'PUBLISHED',
    deletedAt: new Date('2026-02-01T00:00:00Z'),
    updatedAt: new Date('2026-02-15T00:00:00Z'),
    data: {},
};
const INTERNAL_CONFIG = {
    title: 'SEO Config',
    slug: 'seo-config',
    collection: '__seo_config__',
    status: 'PUBLISHED',
    deletedAt: null,
    updatedAt: new Date('2026-03-10T00:00:00Z'),
    data: {},
};
describe('GET /llms.txt', () => {
    beforeEach(() => {
        delete globalThis.__actuateConfig;
    });
    it('lists public content but excludes soft-deleted and internal docs', async () => {
        const docs = [PUBLIC_PAGE, SOFT_DELETED, INTERNAL_CONFIG];
        initDB(createMockDB(docs));
        const handler = handleActuateAPI({
            prismaClient: createMockDB(docs),
            config: {
                seo: { siteUrl: 'https://example.com' },
                collections: {
                    pages: { slug: 'pages', labels: { singular: 'Page', plural: 'Pages' }, fields: {} },
                },
            },
        });
        const res = await handler(new Request('https://example.com/api/cms/llms.txt'));
        expect(res.status).toBe(200);
        const text = await res.text();
        expect(text).toContain('Public About Page');
        // Soft-deleted content must never surface publicly.
        expect(text).not.toContain('Deleted Secret Page');
        expect(text).not.toContain('deleted-secret');
        // Internal/system collections must never surface publicly.
        expect(text).not.toContain('__seo_config__');
        expect(text).not.toContain('SEO Config');
    });
});
//# sourceMappingURL=llms-txt.test.js.map