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[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", }); }); });