Files
co-lite/solvway-admin-portal/middleware.public.test.ts
T
ngqileandClaude Opus 5.5 08c45e9109 feat(portal): QR self-registration page, event QR card, My QR codes, privacy notice editor
The public /r/<code> page (no admin shell, never redirects a visitor to the
staff login), its proxy sending only the last X-Forwarded-For hop, the event
page's Registration QR card, a My QR codes page in the user menu, and the
super-admin privacy notice editor on Companies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-12-01 12:57:18 +08:00

27 lines
1.1 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { NextRequest } from "next/server";
import { middleware } from "./middleware";
// add-qr-self-registration: the QR landing page and its proxy are reachable signed out; admin paths still are not.
const get = (path: string) => middleware(new NextRequest(new URL(path, "https://portal.test")));
describe("middleware: public registration paths", () => {
it("lets a signed-out visitor open /r/<token>", async () => {
const res = await get("/r/abc123");
expect(res.headers.get("x-middleware-next")).toBe("1");
expect(res.headers.get("location")).toBeNull();
});
it("lets a signed-out visitor reach the public registration proxy", async () => {
const res = await get("/api/public/registration/abc123");
expect(res.headers.get("x-middleware-next")).toBe("1");
});
it("still redirects a signed-out visitor from admin paths", async () => {
for (const path of ["/events", "/my-qr", "/r", "/r/"]) {
const res = await get(path);
expect(res.headers.get("location"), path).toContain("/login");
}
});
});