Files
n8n-enterprise-unlocked/packages/@n8n/permissions/src/utilities/__tests__/has-global-scope.test.ts
कारतोफ्फेलस्क्रिप्ट™ 3a2a70f193 chore: Enfore consistent file-name casing on all backend packages (#15755)
2025-05-27 16:45:50 +02:00

51 lines
1.3 KiB
TypeScript

import type { GlobalRole, Scope } from '../../types.ee';
import { hasGlobalScope } from '../has-global-scope.ee';
describe('hasGlobalScope', () => {
describe('single scope checks', () => {
test.each([
{ role: 'global:owner', scope: 'workflow:create', expected: true },
{ role: 'global:admin', scope: 'user:delete', expected: true },
{ role: 'global:member', scope: 'workflow:read', expected: false },
{ role: 'non:existent', scope: 'workflow:read', expected: false },
] as Array<{ role: GlobalRole; scope: Scope; expected: boolean }>)(
'$role with $scope -> $expected',
({ role, scope, expected }) => {
expect(hasGlobalScope({ role }, scope)).toBe(expected);
},
);
});
describe('multiple scopes', () => {
test('oneOf mode (default)', () => {
expect(
hasGlobalScope({ role: 'global:member' }, [
'tag:create',
'user:list',
// a member cannot create users
'user:create',
]),
).toBe(true);
});
test('allOf mode', () => {
expect(
hasGlobalScope(
{ role: 'global:member' },
[
'tag:create',
'user:list',
// a member cannot create users
'user:create',
],
{ mode: 'allOf' },
),
).toBe(false);
});
});
test('edge cases', () => {
expect(hasGlobalScope({ role: 'global:owner' }, [])).toBe(false);
});
});