const { PermissionManager } = require('../src/util'); let perms = null; beforeEach(() => { perms = { developer: { default: 5 }, administrator: 10 }; }); test('Constructor', () => { expect(() => new PermissionManager()).toThrow(); }); 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); });