刘光辉
3 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { describe, expect, it } from 'vitest';
 
import { allowsFileAction } from './fileAccess';
 
describe('upload file action gates', () => {
  it('preserves legacy controls when no runtime permissions are supplied', () => {
    expect(allowsFileAction(undefined, 'DOWNLOAD')).toBe(true);
  });
  it('fails closed while loading or after a failed refresh', () => {
    expect(allowsFileAction({ status: 'loading', actions: { DOWNLOAD: true } }, 'DOWNLOAD')).toBe(false);
    expect(allowsFileAction({ status: 'error', actions: { DOWNLOAD: true } }, 'DOWNLOAD')).toBe(false);
  });
  it('separates viewing, downloading and editing', () => {
    const access = { status: 'ready' as const, actions: { VIEW: true, DOWNLOAD: false, EDIT: true } };
    expect(allowsFileAction(access, 'VIEW')).toBe(true);
    expect(allowsFileAction(access, 'EDIT')).toBe(true);
    expect(allowsFileAction(access, 'DOWNLOAD')).toBe(false);
    expect(allowsFileAction(access, 'REMOVE')).toBe(false);
  });
  it('does not interpret malformed values as grants', () => {
    expect(allowsFileAction({ status: 'ready', actions: { DOWNLOAD: 'true' } } as any, 'DOWNLOAD')).toBe(false);
    expect(allowsFileAction(null as any, 'VIEW')).toBe(false);
  });
});