Add JSON definition subscriptions
This commit is contained in:
parent
7e17470356
commit
bedeb8495d
15 changed files with 321 additions and 37 deletions
25
tests/subscriptions.test.ts
Normal file
25
tests/subscriptions.test.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { subscriptionIsDue } from "../src/shared/subscriptions";
|
||||
import { validateDefinitionCollection } from "../src/shared/site-definitions";
|
||||
|
||||
const definition = {
|
||||
id: "example",
|
||||
name: "Example",
|
||||
urlPatterns: ["https://example.test/*"],
|
||||
requiredSelectors: ["main"],
|
||||
post: { rootSelectors: ["article"], textSelectors: [".content"] }
|
||||
};
|
||||
|
||||
describe("definition subscriptions", () => {
|
||||
it("validates versioned collections and rejects duplicate IDs", () => {
|
||||
const result = validateDefinitionCollection({ schemaVersion: 1, collectionId: "example-source", name: "Example", definitions: [definition, definition] });
|
||||
expect(result.valid).toBe(false);
|
||||
});
|
||||
|
||||
it("is due when never updated or at least seven days old", () => {
|
||||
const now = Date.parse("2026-08-25T00:00:00Z");
|
||||
expect(subscriptionIsDue({ id: "x", name: "X", url: "https://example.test/x.json", enabled: true, priority: 0 }, now)).toBe(true);
|
||||
expect(subscriptionIsDue({ id: "x", name: "X", url: "https://example.test/x.json", enabled: true, priority: 0, lastSuccessfulUpdate: "2026-08-18T00:00:00Z" }, now)).toBe(true);
|
||||
expect(subscriptionIsDue({ id: "x", name: "X", url: "https://example.test/x.json", enabled: true, priority: 0, lastSuccessfulUpdate: "2026-08-24T00:00:00Z" }, now)).toBe(false);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue