Something went wrong. Try again.
static site frontend for mapped.at mapped.at
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109import { assertEquals } from "jsr:@std/assert@1.0.19";import { handler } from "./main.ts";
// ── Routing ───────────────────────────────────────────────────────────────────
Deno.test("GET /register returns 405", async () => { const res = await handler( new Request("http://localhost/register", { method: "GET" }), ); assertEquals(res.status, 405); const body = await res.json(); assertEquals(body.error, "Method not allowed");});
Deno.test("POST /unknown returns 404", async () => { const res = await handler( new Request("http://localhost/unknown", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({}), }), ); assertEquals(res.status, 404); const body = await res.json(); assertEquals(body.error, "Not found");});
// ── /register validation ──────────────────────────────────────────────────────
Deno.test("POST /register rejects invalid JSON", async () => { const res = await handler( new Request("http://localhost/register", { method: "POST", headers: { "Content-Type": "application/json" }, body: "not json", }), ); assertEquals(res.status, 400); const body = await res.json(); assertEquals(body.error, "Invalid JSON");});
Deno.test("POST /register rejects missing did", async () => { const res = await handler( new Request("http://localhost/register", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({}), }), ); assertEquals(res.status, 400); const body = await res.json(); assertEquals(body.error, "Missing required field: did");});
Deno.test("POST /register rejects non-DID string", async () => { const res = await handler( new Request("http://localhost/register", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ did: "alice.bsky.social" }), }), ); assertEquals(res.status, 400); const body = await res.json(); assertEquals(body.error, "Invalid DID format");});
// ── /submit-trail validation ──────────────────────────────────────────────────
Deno.test("POST /submit-trail rejects missing did", async () => { const res = await handler( new Request("http://localhost/submit-trail", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ trail: { name: "Test Trail" } }), }), ); assertEquals(res.status, 400); const body = await res.json(); assertEquals(body.error, "Missing required field: did");});
Deno.test("POST /submit-trail rejects missing trail.name", async () => { const res = await handler( new Request("http://localhost/submit-trail", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ did: "did:plc:test", trail: {} }), }), ); assertEquals(res.status, 400); const body = await res.json(); assertEquals(body.error, "Missing required field: trail.name");});
Deno.test("POST /submit-trail rejects non-DID string", async () => { const res = await handler( new Request("http://localhost/submit-trail", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ did: "not-a-did", trail: { name: "Trail" } }), }), ); assertEquals(res.status, 400); const body = await res.json(); assertEquals(body.error, "Invalid DID format");});