2023-02-11 17:01:56 +01:00
|
|
|
const { PermissionManager } = require('../src/util');
|
|
|
|
let perms = null;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
perms = { developer: { default: 5 }, administrator: 10 };
|
|
|
|
});
|
|
|
|
|
2023-02-13 01:06:29 +01:00
|
|
|
describe('PermissionManager', () => {
|
|
|
|
test('Constructor', () => {
|
|
|
|
expect(() => new PermissionManager()).toThrow();
|
|
|
|
});
|
2023-02-11 17:01:56 +01:00
|
|
|
|
2023-02-13 01:06:29 +01:00
|
|
|
test('Ensure permission', () => {
|
|
|
|
|
|
|
|
expect(() => PermissionManager.ensurePermission()).toThrow();
|
|
|
|
|
|
|
|
expect(PermissionManager.DefaultPermissions).toEqual({});
|
|
|
|
|
|
|
|
PermissionManager.ensurePermission('administrator:removeuser:force:bruh:moment:broo');
|
|
|
|
PermissionManager.ensurePermission('developer:toggledebug');
|
|
|
|
PermissionManager.ensurePermission('developer');
|
|
|
|
|
|
|
|
expect(PermissionManager.DefaultPermissions).toHaveProperty('administrator.removeuser.force');
|
|
|
|
expect(PermissionManager.DefaultPermissions).toHaveProperty('developer.toggledebug');
|
|
|
|
expect(PermissionManager.DefaultPermissions).not.toHaveProperty('developer.removeuser.force');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test permission merge', () => {
|
|
|
|
|
|
|
|
expect(perms).toHaveProperty('administrator', 10);
|
|
|
|
PermissionManager.ensurePermission('administrator:removeuser:force');
|
|
|
|
PermissionManager.merge(perms, PermissionManager.DefaultPermissions);
|
|
|
|
expect(perms).toHaveProperty('administrator.removeuser.force');
|
|
|
|
expect(perms).toHaveProperty('administrator.default', 10);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Check for permission', () => {
|
|
|
|
|
|
|
|
expect(() => PermissionManager.checkPermissions()).toThrow();
|
|
|
|
expect(() => PermissionManager.checkPermissions(perms)).toThrow();
|
|
|
|
|
|
|
|
expect(PermissionManager.checkPermissions(perms, 'administrator', 10)).toBe(true);
|
|
|
|
expect(PermissionManager.checkPermissions(perms, 'developer', 5)).toBe(true);
|
|
|
|
expect(PermissionManager.checkPermissions(perms, 'developer', 10)).toBe(false);
|
|
|
|
|
|
|
|
expect(PermissionManager.checkPermissions(perms, 'bargus', 0)).toBe(false);
|
|
|
|
|
|
|
|
});
|
2023-02-11 17:01:56 +01:00
|
|
|
});
|