import { describe, it, expect } from "bun:test";
import type { Hono } from "hono";
describe("editor module", () => {
it("exports a Hono router as the default export", async () => {
const mod = await import("../routes/editor");
const router = mod.default;
expect(typeof router).toBe("object");
expect(router).not.toBeNull();
expect(typeof (router as Hono).fetch).toBe("function");
expect(Array.isArray((router as Hono).routes)).toBe(true);
});
it("registers at least one route for /:owner/:repo/edit/:ref", async () => {
const mod = await import("../routes/editor");
const router = mod.default as Hono;
const editRoutes = router.routes.filter(
(r) => r.path.includes("/edit/") || r.path.includes("edit")
);
expect(editRoutes.length).toBeGreaterThan(0);
});
});
describe("GET /:owner/:repo/edit/:ref — auth guard", () => {
it("redirects or returns 401/403/404 for unauthenticated users", async () => {
const { default: app } = await import("../app");
const res = await app.request(
"/alice/myrepo/edit/README.md",
{ method: "GET", redirect: "manual" }
);
const acceptable = [301, 302, 303, 307, 308, 401, 403, 404, 503];
expect(acceptable).toContain(res.status);
if ([302, 303, 307].includes(res.status)) {
const loc = res.headers.get("location") || "";
expect(loc).toContain("/login");
}
});
});
|