import { expect, tap } from '@git.zone/tstest/tapbundle'; import * as smartfeed from '../ts/index.js'; let testSmartFeed: smartfeed.Smartfeed; let testFeed: smartfeed.Feed; tap.test('setup', async () => { testSmartFeed = new smartfeed.Smartfeed(); testFeed = testSmartFeed.createFeed({ domain: 'central.eu', title: 'central.eu - ideas for Europe', category: 'Politics', company: 'Lossless GmbH', companyDomain: 'https://lossless.com', companyEmail: 'hello@lossless.com', description: 'ideas for Europe', }); testFeed.addItem({ title: 'A better European Union', authorName: 'Phil', imageUrl: 'https://central.eu/someimage.png', timestamp: Date.now(), url: 'https://central.eu/article/somearticle', content: 'somecontent', }); }); tap.test('should export RSS 2.0 feed', async () => { const rssFeed = testFeed.exportRssFeedString(); expect(rssFeed).toInclude(''); expect(rssFeed).toInclude('central.eu - ideas for Europe'); expect(rssFeed).toInclude('https://central.eu'); expect(rssFeed).toInclude('ideas for Europe'); expect(rssFeed).toInclude('@push.rocks/smartfeed'); expect(rssFeed).toInclude('Politics'); expect(rssFeed).toInclude(''); expect(rssFeed).toInclude('A better European Union'); }); tap.test('should export Atom 1.0 feed', async () => { const atomFeed = testFeed.exportAtomFeed(); expect(atomFeed).toInclude(''); expect(atomFeed).toInclude(''); expect(atomFeed).toInclude('central.eu - ideas for Europe'); expect(atomFeed).toInclude('ideas for Europe'); expect(atomFeed).toInclude('@push.rocks/smartfeed'); expect(atomFeed).toInclude(''); expect(atomFeed).toInclude('A better European Union'); }); tap.test('should export JSON Feed 1.0', async () => { const jsonFeedString = testFeed.exportJsonFeed(); const jsonFeed = JSON.parse(jsonFeedString); expect(jsonFeed.version).toEqual('https://jsonfeed.org/version/1'); expect(jsonFeed.title).toEqual('central.eu - ideas for Europe'); expect(jsonFeed.home_page_url).toEqual('https://central.eu'); expect(jsonFeed.description).toEqual('ideas for Europe'); expect(jsonFeed.items).toBeArray(); expect(jsonFeed.items.length).toEqual(1); expect(jsonFeed.items[0].title).toEqual('A better European Union'); }); tap.test('should include correct item data in RSS', async () => { const rssFeed = testFeed.exportRssFeedString(); expect(rssFeed).toInclude('https://central.eu/article/somearticle'); expect(rssFeed).toInclude('https://central.eu/someimage.png'); expect(rssFeed).toInclude('somecontent'); expect(rssFeed).toInclude(' { const rssFeed = testFeed.exportRssFeedString(); const atomFeed = testFeed.exportAtomFeed(); // RSS doesn't always include dc:creator, but Atom should have author expect(atomFeed).toInclude('Phil'); }); tap.test('should handle multiple items in export', async () => { const feed = testSmartFeed.createFeed({ domain: 'multi.example.com', title: 'Multi-item Feed', category: 'Test', company: 'Test Inc', companyDomain: 'https://example.com', companyEmail: 'test@example.com', description: 'Testing multiple items', }); for (let i = 1; i <= 5; i++) { feed.addItem({ title: `Article ${i}`, authorName: 'Author', imageUrl: `https://example.com/image${i}.png`, timestamp: Date.now() + i, url: `https://example.com/article/${i}`, content: `Content for article ${i}`, }); } const rssFeed = feed.exportRssFeedString(); const jsonFeedString = feed.exportJsonFeed(); const jsonFeed = JSON.parse(jsonFeedString); expect(jsonFeed.items.length).toEqual(5); expect(rssFeed).toInclude('Article 1'); expect(rssFeed).toInclude('Article 5'); }); tap.test('should export feed with custom item IDs', async () => { const feed = testSmartFeed.createFeed({ domain: 'example.com', title: 'Custom ID Feed', category: 'Test', company: 'Test Inc', companyDomain: 'https://example.com', companyEmail: 'test@example.com', description: 'Testing custom IDs', }); feed.addItem({ title: 'Article with custom ID', authorName: 'Author', imageUrl: 'https://example.com/image.png', timestamp: Date.now(), url: 'https://example.com/article/custom', content: 'Content', id: 'custom-uuid-123', }); const rssFeed = feed.exportRssFeedString(); expect(rssFeed).toInclude('custom-uuid-123'); }); export default tap.start();