Files
co-lite/solvway-admin-portal/app/api/public/password-rules/route.test.ts
T
ngqileandClaude Opus 5.5 8ce9fcf471 feat: portal password hints, company hint, interest and role delete, dashboard notes
- Login: company-code hint after an invalid-credentials failure with an empty company.
- Password forms show the active rules (label-first, count-safe) and tie hint and refusal to the input.
- Interests and roles: soft delete with confirm dialogs; deactivate now confirms too.
- Dashboard figure explanations.

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

26 lines
1.2 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
const mocks = vi.hoisted(() => ({ callMobileApi: vi.fn() }));
vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileApi }));
import { GET } from "./route";
type Req = Parameters<typeof GET>[0];
const req = (init: RequestInit = {}) => new Request("http://localhost/api/public/password-rules", init) as unknown as Req;
beforeEach(() => mocks.callMobileApi.mockReset().mockResolvedValue({ ok: true, data: [{ param: "INPUT_LENGTH_MIN", value: 8 }] }));
describe("/api/public/password-rules", () => {
it("forwards without a session, with only the last-hop visitor IP, and returns the rules", async () => {
const res = await GET(req({ headers: { "x-forwarded-for": "6.6.6.6, 203.0.113.7" } }));
expect(res.status).toBe(200);
expect(await res.json()).toEqual([{ param: "INPUT_LENGTH_MIN", value: 8 }]);
expect(mocks.callMobileApi).toHaveBeenCalledWith("/api/public/password-rules", { headers: { "X-Forwarded-For": "203.0.113.7" } });
});
it("passes upstream failures with their status", async () => {
mocks.callMobileApi.mockResolvedValue({ ok: false, error: "Too many requests", status: 429 });
expect((await GET(req())).status).toBe(429);
});
});