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
35 lines
1.3 KiB
TypeScript
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();
|
|
});
|
|
});
|