38 lines
1.1 KiB
JavaScript
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 & Manga — Chapter 12 & a half/);
|
|
assert.match(xml, /A <Team>/);
|
|
assert.match(xml, /suwayomi:chapter:42/);
|
|
assert.match(xml, /x=1&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);
|
|
});
|