Files
co-lite/solvway-admin-portal/app/api/auth/change-password/route.clientContext.test.ts
T
ngqileandClaude Opus 5.5 dd9bbbe036 fix: browser context on password-change history, plain settings errors, New password label
Found in the browser check: change-password history rows had no browser
or IP, settings errors named internal fields, and the dialog's new
password field read just "Password".

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

30 lines
1.2 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
const mocks = vi.hoisted(() => ({ callMobileApi: vi.fn(), getToken: vi.fn() }));
vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileApi }));
vi.mock("@/app/lib/server/session", () => ({ getToken: mocks.getToken }));
import { POST } from "./route";
beforeEach(() => {
mocks.callMobileApi.mockReset();
mocks.getToken.mockReset();
});
describe("POST /api/auth/change-password: client context", () => {
it("forwards the browser IP and user agent for the login history", async () => {
mocks.getToken.mockResolvedValue("jwt-abc");
mocks.callMobileApi.mockResolvedValue({ ok: true, data: null });
const req = new Request("http://localhost/api/auth/change-password", {
method: "POST",
headers: { "x-forwarded-for": "198.51.100.7", "user-agent": "Browser/1.0" },
body: JSON.stringify({ currentPassword: "a", newPassword: "b", confirmPassword: "b" }),
}) as unknown as Parameters<typeof POST>[0];
await POST(req);
expect(mocks.callMobileApi.mock.calls[0][1].headers).toEqual({
"X-Client-Ip": "198.51.100.7",
"X-Client-User-Agent": "Browser/1.0",
});
});
});