Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/routes/auth.password-policy-remind.test.ts
T

44 lines
1.7 KiB
TypeScript

/**
* Phase 01 / #27 — resource-route test for the password-policy "Remind me
* in 7 days" cookie roundtrip.
*
* The handler must:
* - require an authenticated session
* - return 200 `{ ok: true }` with a Set-Cookie header that the
* banner-decision helper can parse back into a future timestamp
* - reject GET requests with 405
*/
import { describe, expect, it, vi } from "vitest";
vi.mock("~/utils/session.server", () => ({
requireUserId: vi.fn().mockResolvedValue("u1"),
}));
import {
PASSWORD_POLICY_REMIND_COOKIE,
readRemindAfterCookie,
} from "~/services/auth/password-policy-banner.server";
import { action, loader } from "./auth.password-policy-remind";
describe("auth.password-policy-remind", () => {
it("returns ok:true and a Set-Cookie that places the snooze in the future", async () => {
const req = new Request("https://app.example.com/auth/password-policy-remind", { method: "POST" });
const before = Date.now();
const response = (await action({ request: req, params: {}, context: {} } as Parameters<typeof action>[0])) as Response;
expect(response.status).toBe(200);
await expect(response.json()).resolves.toEqual({ ok: true });
const setCookie = response.headers.get("Set-Cookie");
expect(setCookie).toBeTruthy();
expect(setCookie).toContain(PASSWORD_POLICY_REMIND_COOKIE);
const parsed = readRemindAfterCookie(setCookie!.split(";")[0]);
expect(parsed).toBeDefined();
expect(parsed!).toBeGreaterThan(before);
});
it("rejects GET requests with 405", async () => {
const response = loader() as Response;
expect(response.status).toBe(405);
expect(response.headers.get("Allow")).toBe("POST");
});
});