刘光辉
8 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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');
  });
});