mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-20 22:03:48 +00:00
test(websub): add hub route tests
Add comprehensive tests for POST /hub validation (missing fields, unknown mode, non-HTTPS callback, invalid URL, wrong domain, secret > 200 bytes) and happy-path subscribe/unsubscribe (202). Also fix hub.ts to use a waitUntilSafe wrapper so executionCtx.waitUntil doesn't throw in Node test environments. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+14
-3
@@ -1,10 +1,19 @@
|
||||
import { Hono } from "hono";
|
||||
import { Hono, type Context } from "hono";
|
||||
import { Env } from "../types";
|
||||
import {
|
||||
verifyAndStoreSubscription,
|
||||
verifyAndDeleteSubscription,
|
||||
} from "../utils/websub";
|
||||
|
||||
function waitUntilSafe(c: Context, promise: Promise<unknown>) {
|
||||
// Hono throws when ExecutionContext isn't present (e.g. Node unit tests).
|
||||
try {
|
||||
c.executionCtx.waitUntil(promise);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_LEASE_SECONDS = 86400;
|
||||
const MAX_LEASE_SECONDS = 30 * 24 * 3600; // 30 days
|
||||
|
||||
@@ -82,7 +91,8 @@ hubRouter.post("/", async (c) => {
|
||||
|
||||
// Return 202 immediately; verification is async
|
||||
if (mode === "subscribe") {
|
||||
c.executionCtx.waitUntil(
|
||||
waitUntilSafe(
|
||||
c,
|
||||
verifyAndStoreSubscription(
|
||||
feedId,
|
||||
callbackUrl as string,
|
||||
@@ -92,7 +102,8 @@ hubRouter.post("/", async (c) => {
|
||||
),
|
||||
);
|
||||
} else {
|
||||
c.executionCtx.waitUntil(
|
||||
waitUntilSafe(
|
||||
c,
|
||||
verifyAndDeleteSubscription(feedId, callbackUrl as string, env),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user