import { describe, expect, it } from 'vitest';
import { parseFeed } from './rss.feed.js';
const RSS2 = `
Some Feed
-
First headline
https://example.com/first
-
ignored
-
https://example.com/empty-title
`;
const ATOM = `
An Atom feed
Only entry
`;
describe('parseFeed', () => {
it('parses RSS 2.0 items in document order, keeping links where present and skipping empty titles', () => {
expect(parseFeed(RSS2)).toEqual([
{ title: 'First headline', link: 'https://example.com/first' },
{ title: 'Second: with CDATA' },
]);
});
it('parses Atom entries (single entry object, link as href attribute)', () => {
expect(parseFeed(ATOM)).toEqual([
{ title: 'Only entry', link: 'https://example.com/atom' },
]);
});
it('returns [] for malformed XML', () => {
expect(parseFeed('this is not xml at all')).toEqual([]);
expect(parseFeed('- broken')).toEqual([]);
});
it('returns [] when there are no items or none with a usable title', () => {
expect(
parseFeed('x'),
).toEqual([]);
expect(
parseFeed(''),
).toEqual([]);
expect(
parseFeed(
'
-
',
),
).toEqual([]);
});
});