Skip to content

Commit

Permalink
fix test for permission-context.entity
Browse files Browse the repository at this point in the history
  • Loading branch information
EzzatOmar committed Nov 29, 2023
1 parent 10ed32e commit 2c0e66a
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { permissionContextFactory, setupEntities, userFactory } from '@shared/testing';
import { UserDelta } from './permission-context.entity';
import { Permission } from '../interface';
import { PermissionCrud, UserDelta } from './permission-context.entity';

describe('PermissionContextEntity Entity', () => {
beforeAll(async () => {
Expand All @@ -16,21 +15,21 @@ describe('PermissionContextEntity Entity', () => {
const parentUserDelta = new UserDelta([
{
userId: user.id,
included_permissions: [Permission.ACCOUNT_EDIT, Permission.ADMIN_EDIT],
excluded_permissions: [],
includedPermissions: [PermissionCrud.CREATE, PermissionCrud.READ],
excludedPermissions: [],
},
{ userId: 'SOME OTHER USER', included_permissions: [Permission.ACCOUNT_CREATE], excluded_permissions: [] },
{ userId: 'SOME OTHER USER', includedPermissions: [PermissionCrud.DELETE], excludedPermissions: [] },
]);

const parentCtx = permissionContextFactory.withUserDelta(parentUserDelta).buildWithId();

const childUserDelta = new UserDelta([
{
userId: user.id,
included_permissions: [Permission.ADD_SCHOOL_MEMBERS],
excluded_permissions: [Permission.ADMIN_EDIT],
includedPermissions: [PermissionCrud.UPDATE],
excludedPermissions: [PermissionCrud.CREATE],
},
{ userId: 'SOME OTHER USER', included_permissions: [Permission.BASE_VIEW], excluded_permissions: [] },
{ userId: 'SOME OTHER USER', includedPermissions: [PermissionCrud.READ], excludedPermissions: [] },
]);

const permissionContext = permissionContextFactory
Expand All @@ -41,10 +40,10 @@ describe('PermissionContextEntity Entity', () => {
return { user, permissionContext };
};

it('should resolve nested permissions', () => {
it('should resolve nested permissions', async () => {
const { user, permissionContext } = setup();
const resolvedPermissions = permissionContext.resolvedPermissions(user.id);
expect(resolvedPermissions.sort()).toEqual([Permission.ADD_SCHOOL_MEMBERS, Permission.ACCOUNT_EDIT].sort());
const resolvedPermissions = await permissionContext.resolvedPermissions(user.id);
expect(resolvedPermissions.sort()).toEqual([PermissionCrud.READ, PermissionCrud.UPDATE].sort());
});
});
});
Expand Down

0 comments on commit 2c0e66a

Please sign in to comment.