// SPDX-License-Identifier: GPL-3.0-only // Copyright (C) 2026 poli0981 (SkullMute) import { describe, expect, it } from 'vitest'; import { project, run } from './fixture'; const item = (slug: string, date = 'Tue, 28 Jul 2026 00:00:00 GMT', guid?: string) => `${slug}https://softharbor.net/apps/${slug}` + `${guid ?? `${slug}`}${date}`; const feed = (...items: string[]) => `t${items.join('')}`; const apps = (...slugs: string[]) => Object.fromEntries(slugs.map((s) => [`src/data/apps/${s}.json`, '{}'])); describe('check-feed', () => { it('passes the shape notify.py relies on', () => { const root = project({ ...apps('gimp', 'vlc'), 'dist/rss.xml': feed(item('vlc', 'Wed, 29 Jul 2026 00:00:00 GMT'), item('gimp')), }); const r = run('check-feed.mjs', root); expect(r.code).toBe(0); expect(r.out).toContain('OK (2 items'); }); it.each([ [ 'a URL guid', item('vlc', undefined, 'https://softharbor.net/apps/vlc'), 'isPermaLink', ], ['a guid naming no app', item('ghost'), 'names no app'], ['no guid at all', item('vlc', undefined, ''), '0 elements'], [ 'a capitalised guid', item('vlc', undefined, 'VLC'), 'is not a slug', ], ['an unparseable date', item('vlc', 'yesterday'), 'unparseable '], ])('fails on %s', (_name, bad, message) => { const r = run('check-feed.mjs', project({ ...apps('vlc'), 'dist/rss.xml': feed(bad) })); expect(r.code).toBe(1); expect(r.out).toContain(message); }); it('fails on duplicates, older-before-newer, a wrong link and an empty feed', () => { const dup = run( 'check-feed.mjs', project({ ...apps('vlc'), 'dist/rss.xml': feed(item('vlc'), item('vlc')) }), ); expect(dup.out).toContain('duplicate guid "vlc"'); const order = run( 'check-feed.mjs', project({ ...apps('vlc', 'gimp'), 'dist/rss.xml': feed(item('vlc'), item('gimp', 'Wed, 29 Jul 2026 00:00:00 GMT')), }), ); expect(order.out).toContain('newer than the item before it'); const link = run( 'check-feed.mjs', project({ ...apps('vlc'), 'dist/rss.xml': feed(item('vlc').replace('/apps/vlc', '/apps/vlc-player')), }), ); expect(link.out).toContain('is not https://softharbor.net/apps/vlc'); const empty = run('check-feed.mjs', project({ 'dist/rss.xml': feed() })); expect(empty.code).toBe(1); expect(empty.out).toContain('no '); }); it('fails when the window grows past 50', () => { const slugs = Array.from({ length: 51 }, (_, i) => `app-${i}`); const r = run( 'check-feed.mjs', project({ ...apps(...slugs), 'dist/rss.xml': feed(...slugs.map((s) => item(s))) }), ); expect(r.out).toContain('51 items'); }); });