import { describe, expect, it } from 'vitest';
import { buildRssFeed, buildJsonFeed } from '../../seo/feeds.js';
const channel = {
    title: 'Acme Blog',
    homeUrl: 'https://example.com',
    feedUrl: 'https://example.com/feed.xml',
    description: 'News & guides',
    language: 'en',
};
const items = [
    {
        url: 'https://example.com/blog/hello',
        title: 'Hello & welcome',
        description: 'First post',
        date: '2026-03-01T00:00:00.000Z',
    },
    {
        url: 'https://example.com/blog/second',
        title: 'Second',
        date: '2026-02-01T00:00:00.000Z',
    },
];
describe('buildRssFeed', () => {
    it('emits a valid RSS 2.0 channel with items', () => {
        const xml = buildRssFeed(channel, items);
        expect(xml).toContain('<?xml version="1.0" encoding="UTF-8"?>');
        expect(xml).toContain('<rss version="2.0"');
        expect(xml).toContain('<title>Acme Blog</title>');
        expect(xml).toContain('<atom:link href="https://example.com/feed.xml" rel="self" type="application/rss+xml" />');
        expect(xml).toContain('<link>https://example.com/blog/hello</link>');
        expect(xml).toContain('<guid isPermaLink="true">https://example.com/blog/hello</guid>');
        expect(xml).toContain('<pubDate>Sun, 01 Mar 2026 00:00:00 GMT</pubDate>');
    });
    it('escapes XML special characters in titles', () => {
        const xml = buildRssFeed(channel, items);
        expect(xml).toContain('<title>Hello &amp; welcome</title>');
        expect(xml).not.toContain('Hello & welcome');
    });
});
describe('buildJsonFeed', () => {
    it('emits a valid JSON Feed 1.1 document', () => {
        const parsed = JSON.parse(buildJsonFeed(channel, items));
        expect(parsed.version).toBe('https://jsonfeed.org/version/1.1');
        expect(parsed.title).toBe('Acme Blog');
        expect(parsed.home_page_url).toBe('https://example.com');
        expect(parsed.feed_url).toBe('https://example.com/feed.xml');
        expect(parsed.items).toHaveLength(2);
        expect(parsed.items[0]).toMatchObject({
            id: 'https://example.com/blog/hello',
            url: 'https://example.com/blog/hello',
            title: 'Hello & welcome',
            summary: 'First post',
            date_published: '2026-03-01T00:00:00.000Z',
        });
    });
    it('omits optional fields when absent', () => {
        const parsed = JSON.parse(buildJsonFeed(channel, items));
        expect(parsed.items[1].summary).toBeUndefined();
    });
});
//# sourceMappingURL=feeds.test.js.map