import { describe, it, expect } from "vitest"; import { errorResponse } from "./apiRoute"; import { SIGNED_IN_ELSEWHERE_COOKIE } from "@/app/lib/signedInElsewhere"; import { sessionCookieName } from "@/app/lib/sessionCookieName"; // one-session-per-account: any portal API route that meets SESSION_REPLACED ends the session and leaves the marker, // so the next page (the login redirect) can say the account signed in elsewhere. describe("errorResponse: SESSION_REPLACED", () => { it("answers 401, clears the session and sets the marker", () => { const res = errorResponse({ ok: false, error: "Token revoked: signed in elsewhere", status: 401, code: "SESSION_REPLACED" }); expect(res.status).toBe(401); expect(res.cookies.get(sessionCookieName())?.value).toBe(""); expect(res.cookies.get(SIGNED_IN_ELSEWHERE_COOKIE)?.value).toBe("1"); }); it("sets no marker for any other failure", () => { const res = errorResponse({ ok: false, error: "Token revoked", status: 401 }); expect(res.cookies.get(SIGNED_IN_ELSEWHERE_COOKIE)).toBeUndefined(); }); });