import { describe, expect, it } from 'vitest';
|
|
import {
|
actionsForResource,
|
canExcludeRead,
|
normalizePrincipalId,
|
principalDisplayName,
|
principalDisplayTitle,
|
principalSearchValue,
|
scopesForResource,
|
} from '../permissionRules';
|
|
describe('dMS permission form rules', () => {
|
it('allows CREATE only on folders', () => {
|
expect(actionsForResource('FOLDER').map((item) => item.value)).toContain('CREATE');
|
expect(actionsForResource('DOCUMENT').map((item) => item.value)).not.toContain('CREATE');
|
expect(actionsForResource('FILE_VERSION').map((item) => item.value)).not.toContain('CREATE');
|
});
|
|
it('allows SUBTREE only on folders', () => {
|
expect(scopesForResource('FOLDER').map((item) => item.value)).toContain('SUBTREE');
|
expect(scopesForResource('DOCUMENT').map((item) => item.value)).toEqual(['SELF']);
|
});
|
|
it('allows READ exclusions only on documents and file versions', () => {
|
expect(canExcludeRead('FOLDER')).toBe(false);
|
expect(canExcludeRead('DOCUMENT')).toBe(true);
|
expect(canExcludeRead('FILE_VERSION')).toBe(true);
|
});
|
|
it('removes selector suffixes before sending principal ids', () => {
|
expect(normalizePrincipalId('org-1--progenyOrg')).toBe('org-1');
|
expect(normalizePrincipalId('pos-1--pos')).toBe('pos-1');
|
expect(normalizePrincipalId('user-1')).toBe('user-1');
|
});
|
|
it('prefers a user display name while retaining the id in the tooltip', () => {
|
expect(principalDisplayName('张三(zhangsan)', 'user-1')).toBe('张三(zhangsan)');
|
expect(principalDisplayTitle('张三(zhangsan)', 'user-1')).toContain('user-1');
|
expect(principalDisplayTitle('张三(zhangsan)', 'user-1')).toContain('张三(zhangsan)');
|
});
|
|
it('falls back to the id and keeps both name and id searchable', () => {
|
expect(principalDisplayName(undefined, 'user-1')).toBe('user-1');
|
expect(principalSearchValue('张三(zhangsan)', 'user-1')).toContain('张三(zhangsan)');
|
expect(principalSearchValue('张三(zhangsan)', 'user-1')).toContain('user-1');
|
});
|
});
|