Files
co-lite/solvway-admin-portal/app/lib/server/mobileApi.problemProps.test.ts
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

34 lines
1.5 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { callMobileApi } from "./mobileApi";
let fetchMock: ReturnType<typeof vi.fn>;
const fail = (body: unknown) =>
fetchMock.mockResolvedValue({ ok: false, status: 400, text: async () => JSON.stringify(body) } as Response);
beforeEach(() => {
vi.stubEnv("MOBILE_API_BASE_URL", "https://mobile.example.test");
vi.stubEnv("MOBILE_API_KEY", "k");
fetchMock = vi.fn();
vi.stubGlobal("fetch", fetchMock);
});
afterEach(() => {
vi.unstubAllGlobals();
vi.unstubAllEnvs();
});
describe("callMobileApi — ProblemDetail properties", () => {
it("surfaces param, value and users as details", async () => {
fail({ detail: "PASSWORD_RULE", code: "PASSWORD_RULE", param: "INPUT_LENGTH_MIN", value: 8 });
expect(await callMobileApi("/x", { token: "t" })).toMatchObject({ code: "PASSWORD_RULE", details: { param: "INPUT_LENGTH_MIN", value: 8 } });
fail({ detail: "ROLE_IN_USE", code: "ROLE_IN_USE", users: 3 });
expect(await callMobileApi("/x", { token: "t" })).toMatchObject({ code: "ROLE_IN_USE", details: { users: 3 } });
});
it("omits a null value (flag rules)", async () => {
fail({ detail: "PASSWORD_RULE", code: "PASSWORD_RULE", param: "SPACE_NOT_ALLOWED", value: null });
const r = await callMobileApi("/x", { token: "t" });
expect(r).toMatchObject({ details: { param: "SPACE_NOT_ALLOWED" } });
expect((r as { details: object }).details).not.toHaveProperty("value");
});
});