Files
co-lite/solvway-admin-portal/app/api/auth/login/route.locked.test.ts
T
ngqileandClaude Opus 5.5 6598b58cb8 feat: locked sign-in message and Change password dialog in the portal
mobile-api now records the browser user agent the portal forwards as
X-Client-User-Agent instead of the portal server's own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-30 14:16:11 +08:00

35 lines
1.3 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
const mocks = vi.hoisted(() => ({ callMobileApi: vi.fn(), setSession: vi.fn() }));
vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileApi }));
vi.mock("@/app/lib/server/session", () => ({ setSession: mocks.setSession }));
import { POST } from "./route";
function req() {
return new Request("http://localhost/api/auth/login", {
method: "POST",
body: JSON.stringify({ username: "sales1", password: "x" }),
}) as unknown as Parameters<typeof POST>[0];
}
beforeEach(() => {
mocks.callMobileApi.mockReset();
});
describe("POST /api/auth/login: locked account", () => {
it("keeps the ACCOUNT_LOCKED code on the 401", async () => {
mocks.callMobileApi.mockResolvedValue({ ok: false, status: 401, error: "Too many failed sign-ins.", code: "ACCOUNT_LOCKED" });
const res = await POST(req());
expect(res.status).toBe(401);
expect(await res.json()).toMatchObject({ error: "Too many failed sign-ins.", code: "ACCOUNT_LOCKED" });
});
it("leaves other 401s without a code", async () => {
mocks.callMobileApi.mockResolvedValue({ ok: false, status: 401, error: "Invalid username or password" });
const res = await POST(req());
expect(res.status).toBe(401);
expect((await res.json()).code).toBeUndefined();
});
});