You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.6 KiB
45 lines
1.6 KiB
import { checkPermissions } from './CheckPermissions.js';
|
|
|
|
const target = 'ok';
|
|
const error = 'error';
|
|
|
|
describe('test CheckPermissions', () => {
|
|
it('Correct string permission authentication', () => {
|
|
expect(checkPermissions('user', 'user', target, error)).toEqual('ok');
|
|
});
|
|
it('Correct string permission authentication', () => {
|
|
expect(checkPermissions('user', 'NULL', target, error)).toEqual('error');
|
|
});
|
|
it('authority is undefined , return ok', () => {
|
|
expect(checkPermissions(null, 'NULL', target, error)).toEqual('ok');
|
|
});
|
|
it('currentAuthority is undefined , return error', () => {
|
|
expect(checkPermissions('admin', null, target, error)).toEqual('error');
|
|
});
|
|
it('Wrong string permission authentication', () => {
|
|
expect(checkPermissions('admin', 'user', target, error)).toEqual('error');
|
|
});
|
|
it('Correct Array permission authentication', () => {
|
|
expect(checkPermissions(['user', 'admin'], 'user', target, error)).toEqual(
|
|
'ok'
|
|
);
|
|
});
|
|
it('Wrong Array permission authentication,currentAuthority error', () => {
|
|
expect(
|
|
checkPermissions(['user', 'admin'], 'user,admin', target, error)
|
|
).toEqual('error');
|
|
});
|
|
it('Wrong Array permission authentication', () => {
|
|
expect(checkPermissions(['user', 'admin'], 'guest', target, error)).toEqual(
|
|
'error'
|
|
);
|
|
});
|
|
it('Wrong Function permission authentication', () => {
|
|
expect(checkPermissions(() => false, 'guest', target, error)).toEqual(
|
|
'error'
|
|
);
|
|
});
|
|
it('Correct Function permission authentication', () => {
|
|
expect(checkPermissions(() => true, 'guest', target, error)).toEqual('ok');
|
|
});
|
|
});
|
|
|