Skip to content

Commit

Permalink
fix check function
Browse files Browse the repository at this point in the history
  • Loading branch information
kikeztw committed Dec 1, 2022
1 parent 9049eee commit b43c091
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/__tests__/module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,29 @@ test('Test default rules', () => {
rule.setDefaultRole(Roles.MANAGER);
}).toThrow('Role not fund in rules');
});

test('Test simple Check', () => {
enum Roles {
ADMIN = 'ADMIN',
MANAGER = 'MANAGER',
}
enum Permissions {
DASHBOARD = 'DASHBOARD',
SETTINGS = 'SETTINGS',
}

const staticRules = new RBAC<Roles, Permissions>(Roles.ADMIN);

staticRules.createRule(Roles.ADMIN, Permissions.DASHBOARD, true);
staticRules.createRule(Roles.ADMIN, Permissions.SETTINGS, true);
staticRules.createRule(Roles.MANAGER, Permissions.DASHBOARD, false);
expect(
staticRules.simpleCheck(Roles.ADMIN, Permissions.DASHBOARD),
).toStrictEqual(true);
expect(
staticRules.simpleCheck(Roles.ADMIN, Permissions.SETTINGS),
).toStrictEqual(true);
expect(
staticRules.simpleCheck(Roles.MANAGER, Permissions.DASHBOARD),
).toStrictEqual(false);
});

0 comments on commit b43c091

Please sign in to comment.