Rollen Chunk 7: Benutzerverwaltung und Sicherung strikt Admin-only
Docker Image / test (push) Canceled after 0s
Docker Image / image (push) Canceled after 0s

This commit is contained in:
loki committed 2026-10-11 20:35:56 +02:00
1 parent c08fe7a64f
commit 71dca44c1d
1 file changed
+36
+36
View File
@@ -30,3 +30,39 @@ describe("api-client 401-Handling", () => {
expect(isUnauthorized(null)).toBe(false);
});
});
describe("api-client Benutzerverwaltung", () => {
test("listUsers ruft GET /api/users", async () => {
const { listUsers } = await import("./api-client");
const fetchMock = vi.fn().mockResolvedValue(
new Response(JSON.stringify({ users: [] }), {
status: 200,
headers: { "content-type": "application/json" },
}),
);
vi.stubGlobal("fetch", fetchMock);
await expect(listUsers()).resolves.toEqual({ users: [] });
expect(fetchMock).toHaveBeenCalledWith("/api/users", expect.anything());
});
test("createUser legt mit POST an", async () => {
const { createUser } = await import("./api-client");
const fetchMock = vi.fn().mockResolvedValue(
new Response(
JSON.stringify({ user: { id: "u-9", role: "benutzer" } }),
{ status: 201, headers: { "content-type": "application/json" } },
),
);
vi.stubGlobal("fetch", fetchMock);
await createUser({
name: "Neu",
email: "neu@example.org",
password: "geheim-geheim!",
role: "benutzer",
});
expect(fetchMock).toHaveBeenCalledWith(
"/api/users",
expect.objectContaining({ method: "POST" }),
);
});
});