diff --git a/frontend/src/__tests__/group-edit-empty-permissions.test.ts b/frontend/src/__tests__/group-edit-empty-permissions.test.ts new file mode 100644 index 000000000..32ab24953 --- /dev/null +++ b/frontend/src/__tests__/group-edit-empty-permissions.test.ts @@ -0,0 +1,145 @@ +/** + * Regression tests for issue #237: removing every permission row from the + * group edit form and saving reported "Group updated successfully" while + * silently leaving the group's stored permissions untouched. + * + * collectPermissions() (groupModals.ts) skips any row whose action or + * resource is still the empty "Select Action"/"Select Resource" placeholder, + * so clicking Remove on every real row -- or leaving only a placeholder row + * -- collects as permissions: []. The update API's documented contract + * (applyUpdateGroupRequest, internal/auth/service_api.go) treats an empty + * permissions list as "not sent" and leaves the group's permissions + * unchanged -- there is no way for this endpoint to express "clear all + * permissions". So the form would show success and reload a group that + * still carried its old privileges (possibly admin:*). + * + * The fix refuses to submit when collectPermissions() returns [], with an + * explicit error telling the operator to delete the group instead. + */ + +import './setup'; + +jest.mock('../api', () => ({ + getGroup: jest.fn(), + updateGroup: jest.fn(), + createGroup: jest.fn(), +})); + +jest.mock('../users/userActions', () => ({ + loadUsers: jest.fn().mockResolvedValue(undefined), +})); + +jest.mock('../confirmDialog', () => ({ + confirmDialog: jest.fn().mockResolvedValue(true), +})); + +jest.mock('../users/utils', () => ({ + ...jest.requireActual('../users/utils'), + showError: jest.fn(), + showSuccess: jest.fn(), +})); + +import * as api from '../api'; +import * as groupState from '../groups/state'; +import * as groupModals from '../groups/groupModals'; +import { showError, showSuccess } from '../users/utils'; + +function setUpModalDom(): void { + document.body.innerHTML = ` +