import { describe, it, expect } from "vitest"; import { NextRequest } from "next/server"; import { middleware } from "./middleware"; // admin-login-return-to: a signed-out visit to a page is sent to /login with the page to come back to. const at = (path: string) => middleware(new NextRequest(new URL(path, "https://portal.test"))); describe("middleware: return to the page after login", () => { it("a page carries returnTo", async () => { const res = await at("/members?tab=kyc"); expect(res.headers.get("location")).toBe("https://portal.test/login?returnTo=%2Fmembers%3Ftab%3Dkyc"); }); it("the home page needs none", async () => { const res = await at("/"); expect(res.headers.get("location")).toBe("https://portal.test/login"); }); });