- Login copy describes the event CRM instead of orders and payouts.
- Role dialog has no parent field; the role routes require a trimmed name and forward only {name}.
- New-user banner says a temporary password was emailed; TEMP_PASSWORD_NOT_SENT shows a message and a link back to users.
- Username is read-only when editing.
- Password hint and an 8-character minimum match the backend admin password rules.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
53 lines
1.8 KiB
TypeScript
53 lines
1.8 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 { GET, POST } from "./route";
|
|
|
|
function getReq() {
|
|
return new Request("http://localhost/api/roles") as unknown as Parameters<typeof GET>[0];
|
|
}
|
|
function postReq(body: unknown) {
|
|
return new Request("http://localhost/api/roles", {
|
|
method: "POST",
|
|
body: JSON.stringify(body),
|
|
}) as unknown as Parameters<typeof POST>[0];
|
|
}
|
|
|
|
beforeEach(() => {
|
|
mocks.callMobileApi.mockReset();
|
|
mocks.getToken.mockReset();
|
|
});
|
|
|
|
describe("GET /api/roles", () => {
|
|
it("forwards to GET /api/admin/roles", async () => {
|
|
mocks.getToken.mockResolvedValue("jwt-abc");
|
|
mocks.callMobileApi.mockResolvedValue({ ok: true, data: [] });
|
|
await GET(getReq());
|
|
expect(mocks.callMobileApi).toHaveBeenCalledWith("/api/admin/roles", { token: "jwt-abc" });
|
|
});
|
|
});
|
|
|
|
describe("POST /api/roles", () => {
|
|
it("requires a name (no parent needed)", async () => {
|
|
mocks.getToken.mockResolvedValue("jwt-abc");
|
|
const res = await POST(postReq({}));
|
|
expect(res.status).toBe(400);
|
|
expect((await POST(postReq({ name: " " }))).status).toBe(400);
|
|
expect(mocks.callMobileApi).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("forwards only the name to POST /api/admin/roles", async () => {
|
|
mocks.getToken.mockResolvedValue("jwt-abc");
|
|
mocks.callMobileApi.mockResolvedValue({ ok: true, data: { id: 200, name: "ROLE_NEW" } });
|
|
await POST(postReq({ name: "ROLE_NEW", parent: { id: 4 } }));
|
|
expect(mocks.callMobileApi).toHaveBeenCalledWith("/api/admin/roles", {
|
|
method: "POST",
|
|
body: { name: "ROLE_NEW" },
|
|
token: "jwt-abc",
|
|
});
|
|
});
|
|
});
|