Files
BetterDesk/web-nodejs/tests/deviceGroupService.scope.test.js
T
UNITRONIX 154279f7ed fix(ui): compact Devices/Dashboard chrome and stop sticky overlaps
Tighten the Devices rail and toolbar (status select, quieter create actions,
RDP/VNC under groups), compact the dashboard client-config tools, protect the
Default device group, and keep Settings topic tabs above branding content.

Thanks: INSOLVE (Honorary); Marco Jakobs (@jacotec); MyNameisStitch (@MyNameisStitch); Redspin (@playerumpknow); muopc (@muopc)
2026-11-18 15:13:13 +01:00

68 lines
2.4 KiB
JavaScript

const deviceGroupService = require('../services/deviceGroupService');
describe('isProtectedDefaultDeviceGroup', () => {
test('protects the seeded Default device group', () => {
expect(deviceGroupService.isProtectedDefaultDeviceGroup({
name: 'Default',
note: 'Default device group',
team_id: ''
})).toBe(true);
expect(deviceGroupService.isProtectedDefaultDeviceGroup({
name: 'Default',
note: '',
team_id: ''
})).toBe(true);
});
test('allows org defaults and custom groups to be deleted', () => {
expect(deviceGroupService.isProtectedDefaultDeviceGroup({
name: 'Acme',
note: 'Default group created with organization (commercialization)',
team_id: 'org-1'
})).toBe(false);
expect(deviceGroupService.isProtectedDefaultDeviceGroup({
name: 'Operators',
note: '',
team_id: ''
})).toBe(false);
});
});
describe('deviceGroupService scope (#227)', () => {
const devices = [
{ id: '100', folder_id: 1 },
{ id: '200', folder_id: 2 },
{ id: '300', folder_id: null }
];
test('open default returns null when no ACL or grants', async () => {
const db = {
getAllDeviceGroups: jest.fn().mockResolvedValue([]),
getUserPeerGrants: jest.fn().mockResolvedValue([])
};
const user = { id: 5, username: 'op1', role: 'operator' };
const scope = await deviceGroupService.getDeviceScopeForUser(db, user, devices);
expect(scope).toBeNull();
});
test('direct peer grants are always visible in open overlay mode', async () => {
const db = {
getAllDeviceGroups: jest.fn().mockResolvedValue([
{
guid: 'folder_1',
folder_id: 1,
allowed_users: ['other'],
allowed_groups: [],
source_type: 'manual'
}
]),
getUserGroupsForUser: jest.fn().mockResolvedValue([]),
getUserPeerGrants: jest.fn().mockResolvedValue(['300'])
};
const user = { id: 5, username: 'op1', role: 'operator', user_groups: [] };
const scope = await deviceGroupService.getDeviceScopeForUser(db, user, devices);
expect(scope).not.toBeNull();
expect(scope.has('300')).toBe(true);
});
});