import { describe, expect, it } from 'vitest';
import { resolveContentDates } from '../../seo/page-meta.js';
import { generateLlmsTxt } from '../../seo/llms-txt.js';
import { buildJsonFeed, buildRssFeed } from '../../seo/feeds.js';
describe('resolveContentDates', () => {
    it('prefers DB publishedAt/updatedAt', () => {
        const pub = new Date('2024-01-01T00:00:00.000Z');
        const upd = new Date('2024-06-01T00:00:00.000Z');
        expect(resolveContentDates({ doc: { publishedAt: pub, updatedAt: upd } })).toEqual({
            datePublished: pub.toISOString(),
            dateModified: upd.toISOString(),
        });
    });
    it('falls back to editorial date fields for publication', () => {
        const r = resolveContentDates({
            doc: { updatedAt: new Date('2024-06-01T00:00:00.000Z') },
            data: { publishedDate: '2024-01-15' },
        });
        expect(r.datePublished).toBe(new Date('2024-01-15').toISOString());
    });
    it('never lets dateModified predate publication', () => {
        const r = resolveContentDates({
            doc: { publishedAt: new Date('2024-01-01T00:00:00.000Z') },
            data: {},
        });
        expect(r.dateModified).toBe(r.datePublished);
    });
    it('returns empty object when no dates are available', () => {
        expect(resolveContentDates({ doc: {} })).toEqual({});
    });
});
describe('llms.txt freshness', () => {
    it('appends an Updated: date to each entry', () => {
        const out = generateLlmsTxt({ siteName: 'Acme', siteUrl: 'https://acme.test' }, [
            {
                title: 'Hello',
                url: 'https://acme.test/hello',
                description: 'A post',
                updatedAt: '2024-06-01T12:00:00.000Z',
                collection: 'posts',
            },
        ]);
        expect(out).toContain('- [Hello](https://acme.test/hello): A post — Updated: 2024-06-01');
    });
    it('omits the date marker when updatedAt is absent', () => {
        const out = generateLlmsTxt({ siteName: 'Acme', siteUrl: 'https://acme.test' }, [
            { title: 'Hello', url: 'https://acme.test/hello', collection: 'posts' },
        ]);
        expect(out).toContain('- [Hello](https://acme.test/hello)');
        expect(out).not.toContain('Updated:');
    });
});
describe('feed date_modified', () => {
    const channel = {
        title: 'Acme',
        homeUrl: 'https://acme.test',
        feedUrl: 'https://acme.test/feed.json',
    };
    it('emits date_modified in JSON Feed when present', () => {
        const json = JSON.parse(buildJsonFeed(channel, [
            {
                url: 'https://acme.test/a',
                title: 'A',
                date: '2024-01-01T00:00:00.000Z',
                dateModified: '2024-06-01T00:00:00.000Z',
            },
        ]));
        expect(json.items[0].date_published).toBe('2024-01-01T00:00:00.000Z');
        expect(json.items[0].date_modified).toBe('2024-06-01T00:00:00.000Z');
    });
    it('omits date_modified when not provided', () => {
        const json = JSON.parse(buildJsonFeed(channel, [
            { url: 'https://acme.test/a', title: 'A', date: '2024-01-01T00:00:00.000Z' },
        ]));
        expect(json.items[0].date_modified).toBeUndefined();
    });
    it('RSS still emits pubDate from the publication date', () => {
        const rss = buildRssFeed(channel, [
            {
                url: 'https://acme.test/a',
                title: 'A',
                date: '2024-01-01T00:00:00.000Z',
                dateModified: '2024-06-01T00:00:00.000Z',
            },
        ]);
        expect(rss).toContain('<pubDate>');
    });
});
//# sourceMappingURL=freshness.test.js.map