- 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
61 lines
2.1 KiB
TypeScript
61 lines
2.1 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, PUT } from "./route";
|
|
|
|
function ctx(id: string) {
|
|
return { params: Promise.resolve({ id }) };
|
|
}
|
|
function getReq() {
|
|
return new Request("http://localhost/api/roles/4") as unknown as Parameters<typeof GET>[0];
|
|
}
|
|
function putReq(body: unknown) {
|
|
return new Request("http://localhost/api/roles/4", {
|
|
method: "PUT",
|
|
body: JSON.stringify(body),
|
|
}) as unknown as Parameters<typeof PUT>[0];
|
|
}
|
|
|
|
beforeEach(() => {
|
|
mocks.callMobileApi.mockReset();
|
|
mocks.getToken.mockReset();
|
|
});
|
|
|
|
describe("GET /api/roles/[id]", () => {
|
|
it("returns 401 when there is no session", async () => {
|
|
mocks.getToken.mockResolvedValue(null);
|
|
const res = await GET(getReq(), ctx("4"));
|
|
expect(res.status).toBe(401);
|
|
});
|
|
|
|
it("forwards to GET /api/admin/roles/{id}", async () => {
|
|
mocks.getToken.mockResolvedValue("jwt-abc");
|
|
mocks.callMobileApi.mockResolvedValue({ ok: true, data: { id: 4 } });
|
|
await GET(getReq(), ctx("4"));
|
|
expect(mocks.callMobileApi).toHaveBeenCalledWith("/api/admin/roles/4", { token: "jwt-abc" });
|
|
});
|
|
});
|
|
|
|
describe("PUT /api/roles/[id]", () => {
|
|
it("requires a name, then forwards only the name to PUT /api/admin/roles/{id}", async () => {
|
|
mocks.getToken.mockResolvedValue("jwt-abc");
|
|
|
|
const invalid = await PUT(putReq({}), ctx("4"));
|
|
expect(invalid.status).toBe(400);
|
|
expect((await PUT(putReq({ name: " " }), ctx("4"))).status).toBe(400);
|
|
expect(mocks.callMobileApi).not.toHaveBeenCalled();
|
|
|
|
const body = { id: 4, name: "ROLE_NEW", parent: { id: 1 } };
|
|
mocks.callMobileApi.mockResolvedValue({ ok: true, data: { ...body } });
|
|
await PUT(putReq(body), ctx("4"));
|
|
expect(mocks.callMobileApi).toHaveBeenCalledWith("/api/admin/roles/4", {
|
|
method: "PUT",
|
|
body: { name: "ROLE_NEW" },
|
|
token: "jwt-abc",
|
|
});
|
|
});
|
|
});
|