examples/live-notes Public
import assert from "node:assert/strict";import { test } from "node:test";import { route } from "../src/routes.ts";test("routes a note and its socket", () => { assert.deepEqual(route("/notes/groceries"), { kind: "note", id: "groceries" }); assert.deepEqual(route("/notes/team_standup-42/ws"), { kind: "socket", id: "team_standup-42" });});test("routes a note's snapshots and one snapshot by version", () => { assert.deepEqual(route("/notes/groceries/snapshots"), { kind: "snapshots", id: "groceries" }); assert.deepEqual(route("/notes/groceries/snapshots/300"), { kind: "snapshot", id: "groceries", version: 300 });});test("refuses other paths and odd ids", () => { for (const p of [ "/", "/notes", "/notes/", "/notes/a/b", "/notes/a%20b", "/notes/../x", `/notes/${"a".repeat(65)}`, "/notes/a/ws/x", "/notes/a/ws/100", "/notes/a/snapshots/0", "/notes/a/snapshots/007", "/notes/a/snapshots/1e3", "/notes/a/snapshots/", `/notes/a/snapshots/${"9".repeat(13)}`, ]) { assert.equal(route(p), null, p); }});