Files
suwayomi-rss/test/rss.test.js
T
2026-07-19 21:28:54 +00:00

38 lines
1.1 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { buildRss, FeedService } from "../src/rss.js";
import { baseConfig, chapter } from "./helpers.js";
test("buildRss emits valid escaped RSS fields and a stable GUID", () => {
const xml = buildRss([chapter], baseConfig.feed, 1700000200000);
assert.match(xml, /<rss version="2.0"/);
assert.match(xml, /Example &amp; Manga — Chapter 12 &amp; a half/);
assert.match(xml, /A &lt;Team&gt;/);
assert.match(xml, /suwayomi:chapter:42/);
assert.match(xml, /x=1&amp;y=2/);
assert.match(xml, /atom:link/);
});
test("FeedService caches responses and coalesces concurrent refreshes", async () => {
let calls = 0;
let now = 1000;
const client = {
async recentLibraryChapters(limit) {
calls += 1;
assert.equal(limit, 25);
await Promise.resolve();
return [chapter];
},
};
const service = new FeedService(client, baseConfig.feed, () => now);
const [first, second] = await Promise.all([service.get(), service.get()]);
assert.strictEqual(first, second);
assert.equal(calls, 1);
now += 301000;
await service.get();
assert.equal(calls, 2);
});