Files
community-rule/tests/unit/oneTimeLinkToken.test.ts
T
adilallo a725cf1a32 Spend login, invite, and email-change links only after a confirm POST so mail scanners cannot use them up.
GET still shows a one-button page, a used invitation can resend or reopen for the signed-in invitee, and an email-change GET no longer signs the account out.
2026-11-22 16:58:30 -07:00

32 lines
1.1 KiB
TypeScript

import { NextRequest } from "next/server";
import { describe, expect, it } from "vitest";
import { readOneTimeLinkToken } from "../../lib/server/oneTimeLinkToken";
describe("readOneTimeLinkToken", () => {
it("reads a token from the query string", async () => {
const request = new NextRequest(
"https://x.test/api/auth/magic-link/verify?token=abcdefghijkl",
);
await expect(readOneTimeLinkToken(request)).resolves.toBe("abcdefghijkl");
});
it("returns null for a short query token", async () => {
const request = new NextRequest(
"https://x.test/api/auth/magic-link/verify?token=short",
);
await expect(readOneTimeLinkToken(request)).resolves.toBeNull();
});
it("reads a token from a JSON body when the query is empty", async () => {
const request = new NextRequest(
"https://x.test/api/auth/magic-link/verify",
{
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ token: "abcdefghijkl" }),
},
);
await expect(readOneTimeLinkToken(request)).resolves.toBe("abcdefghijkl");
});
});