Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SkeLLLa committed Jun 18, 2021
1 parent f5dc8ef commit db53f6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
12 changes: 4 additions & 8 deletions test/cornercases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ describe('rbac', () => {
},
},
});
console.log(rbac['_rules']);
console.log(rbac['_rulesCompiled']);
test('extend:overrrides', async () => {
await expect(rbac.can('user', 'foo', 'read', {})).resolves.toEqual(false);
await expect(rbac.can('admin', 'foo', 'read', {})).resolves.toEqual(true);
await expect(rbac.can('superadmin', 'foo', 'read', {})).resolves.toEqual(
true
);
test('extend:overrrides', () => {
void expect(rbac.can('user', 'foo', 'read', {})).toEqual(false);
void expect(rbac.can('admin', 'foo', 'read', {})).toEqual(true);
void expect(rbac.can('superadmin', 'foo', 'read', {})).toEqual(true);
});
});
});
18 changes: 9 additions & 9 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('rbac', () => {
name: 'foo',
operation: 'create',
when: (ctx: { userId: string; ownerId: string }) => {
return ctx.userId === ctx.ownerId;
return Promise.resolve(ctx.userId === ctx.ownerId);
},
},
],
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('rbac', () => {
name: 'foo',
operation: 'create',
when: (ctx: { userId: string; ownerId: string }) => {
return ctx.userId === ctx.ownerId;
return Promise.resolve(ctx.userId === ctx.ownerId);
},
},
],
Expand Down Expand Up @@ -308,7 +308,7 @@ describe('rbac', () => {
expect(rbac['_rulesCompiled']['guest:foo:read']).toEqual(true);
expect(rbac['_rulesCompiled']['guest:bar:read']).toEqual(true);
});
test('hierarchical:can:true', async () => {
test('hierarchical:can:true', () => {
const rbac = new RBAC({
roles: {
guest: {
Expand All @@ -335,12 +335,12 @@ describe('rbac', () => {
expect(rbac['_rulesCompiled']['user:foo:remove']).toEqual(true);
expect(rbac.can('admin', 'foo', 'create')).toEqual(true);
expect(rbac['_rulesCompiled']['admin:foo:create']).toBeDefined();
await expect(
rbac.can('admin', 'foo', 'create', { a: 1, b: 1 })
).resolves.toEqual(true);
await expect(
rbac.can('admin', 'foo', 'create', { a: 1, b: 2 })
).resolves.toEqual(false);
void expect(rbac.can('admin', 'foo', 'create', { a: 1, b: 1 })).toEqual(
true
);
void expect(rbac.can('admin', 'foo', 'create', { a: 1, b: 2 })).toEqual(
false
);
});
});
describe('remove', () => {
Expand Down

0 comments on commit db53f6b

Please sign in to comment.