Rollen Chunk 7: Benutzerverwaltung und Sicherung strikt Admin-only
This commit is contained in:
1 parent
c08fe7a64f
commit
71dca44c1d
1 file changed
+36
@@ -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" }),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user