feat: add support for unit testing using vitest in editor-ui (#4184)
* feat: add support for unit testing using vitest in editor-ui * fix(editor): update tsconfig types and typeRoots * chore(editor): update package-lock.json
This commit is contained in:
47
packages/editor-ui/src/__tests__/permissions.spec.ts
Normal file
47
packages/editor-ui/src/__tests__/permissions.spec.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { parsePermissionsTable } from '@/permissions';
|
||||
import { IUser } from "@/Interface";
|
||||
|
||||
describe('parsePermissionsTable()', () => {
|
||||
const user: IUser = {
|
||||
id: "1",
|
||||
firstName: "John",
|
||||
lastName: "Doe",
|
||||
isDefaultUser: false,
|
||||
isOwner: true,
|
||||
isPending: false,
|
||||
isPendingUser: false,
|
||||
};
|
||||
|
||||
it('should return permissions object using generic permissions table', () => {
|
||||
const permissions = parsePermissionsTable(user, []);
|
||||
|
||||
expect(permissions.isInstanceOwner).toBe(true);
|
||||
});
|
||||
|
||||
it('should set permission based on permissions table row test function', () => {
|
||||
const permissions = parsePermissionsTable(user, [
|
||||
{ name: 'canRead', test: () => true },
|
||||
{ name: 'canUpdate', test: () => false },
|
||||
]);
|
||||
|
||||
expect(permissions.canRead).toBe(true);
|
||||
expect(permissions.canUpdate).toBe(false);
|
||||
});
|
||||
|
||||
it('should set permission based on previously computed permission', () => {
|
||||
const permissions = parsePermissionsTable(user, [
|
||||
{ name: 'canRead', test: ['isInstanceOwner'] },
|
||||
]);
|
||||
|
||||
expect(permissions.canRead).toBe(true);
|
||||
});
|
||||
|
||||
it('should set permission based on multiple previously computed permissions', () => {
|
||||
const permissions = parsePermissionsTable(user, [
|
||||
{ name: 'isResourceOwner', test: ['isInstanceOwner'] },
|
||||
{ name: 'canRead', test: ['isInstanceOwner', 'isResourceOwner'] },
|
||||
]);
|
||||
|
||||
expect(permissions.canRead).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user