import { describe, expect, it } from "vitest"; import { reroute } from "./hooks"; const at = (path: string) => reroute({ url: new URL(`https://x${path}`), fetch }); describe("reroute", () => { const encoded = encodeURIComponent("at://did:plc:abc/sh.tangled.repo.pull/3xyz"); it("encodes a raw at-uri", () => { expect(at("/alice/repo/pulls/at://did:plc:abc/sh.tangled.repo.pull/3xyz/latest")).toBe( `/alice/repo/pulls/${encoded}/latest` ); }); it("encodes a collapsed at-uri", () => { expect(at("/alice/repo/pulls/at:/did:plc:abc/sh.tangled.repo.pull/3xyz")).toBe( `/alice/repo/pulls/${encoded}` ); }); it("leaves encoded and unrelated urls alone", () => { expect(at(`/alice/repo/pulls/${encoded}/1/a..b`)).toBe( `/alice/repo/pulls/${encoded}/1/a..b` ); expect(at("/alice/repo/pulls")).toBe("/alice/repo/pulls"); }); });