feat(admin): add user role dialog

Admins change a user's role and see the change log. The last admin
gets a clear error when deleting their own account.
This commit is contained in:
lobo committed 2026-10-04 20:09:22 +02:00
1 parent e5091de50e
commit 13b0d5e7e9
11 files changed
+391 -18

No files matched your search

+25 -1
View File
@@ -1,7 +1,7 @@
// @vitest-environment jsdom
import {describe, expect, it} from 'vitest';
import {refreshSession} from './api.js';
import {viewAs} from './admin.js';
import {changeUserRole, fetchRoleChanges, viewAs} from './admin.js';
import {fetchRoutes, json} from '../test/fetchRoutes.js';
describe('viewAs', () => {
@@ -25,3 +25,27 @@ describe('viewAs', () => {
await switching;
});
});
describe('role changes', () => {
it('changeUserRole puts the new and the expected role', async () => {
fetchRoutes({'PUT /api/admin/users/7/role': json(204)});
await changeUserRole(7, 'AUDITOR', 'USER');
const [url, init] = fetch.mock.calls[0];
expect(url).toMatch(/\/api\/admin\/users\/7\/role$/);
expect(init.method).toBe('PUT');
expect(JSON.parse(init.body)).toEqual({role: 'AUDITOR', expectedRole: 'USER'});
});
it('fetchRoleChanges gets the log of the user', async () => {
fetchRoutes({'GET /api/admin/users/7/role-changes': json(200, {results: []})});
const signal = new AbortController().signal;
await fetchRoleChanges(7, {signal});
const [url, init] = fetch.mock.calls[0];
expect(url).toMatch(/\/api\/admin\/users\/7\/role-changes$/);
expect(init.signal).toBe(signal);
});
});