刘光辉
8 小时以前 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { describe, expect, it } from 'vitest';
 
import { PLUGIN_GUID, parsePluginContext } from '../../src/domain/context';
 
describe('签批页插件运行上下文', () => {
  it('接受后端签发的可标注上下文', () => {
    expect(parsePluginContext({
      apiBaseUrl: 'http://localhost:30000/', bizModule: 'dms', bizScene: 'dms.qianpiye',
      canAnnotate: true, documentId: 'file-1', pluginVersion: '0.1.0',
      scope: 'onlyoffice:dms-qianpiye', ticket: 'short-lived-ticket',
    })).toMatchObject({ apiBaseUrl: 'http://localhost:30000', documentId: 'file-1' });
  });
 
  it('兼容 OnlyOffice 传入的 JSON 上下文和旧版空业务记录', () => {
    expect(parsePluginContext(JSON.stringify({
      apiBaseUrl: 'http://localhost:30000', bizDataId: null, bizModule: 'dms', bizScene: 'dms.qianpiye',
      canAnnotate: true, documentId: 'file-1', pluginVersion: '0.1.0',
      scope: 'onlyoffice:dms-qianpiye', ticket: 'short-lived-ticket',
    }))).toMatchObject({ canAnnotate: true, documentId: 'file-1' });
  });
 
  it('兼容按插件 GUID 嵌套的上下文', () => {
    expect(parsePluginContext({
      [PLUGIN_GUID]: {
        apiBaseUrl: 'http://localhost:30000', bizModule: 'dms', bizScene: 'dms.qianpiye',
        canAnnotate: true, documentId: 'file-1', pluginVersion: '0.1.0',
        scope: 'onlyoffice:dms-qianpiye', ticket: 'short-lived-ticket',
      },
    })).toMatchObject({ canAnnotate: true, documentId: 'file-1' });
  });
 
  it('接受只读上下文,不要求标注票据', () => {
    expect(parsePluginContext({
      apiBaseUrl: 'http://localhost:30000', bizModule: 'dms', bizScene: 'dms.qianpiye',
      canAnnotate: false, documentId: 'file-1', pluginVersion: '0.1.0',
    })).toMatchObject({ canAnnotate: false, documentId: 'file-1' });
  });
 
  it('拒绝缺失凭证或错误场景的上下文', () => {
    expect(() => parsePluginContext({
      apiBaseUrl: 'http://localhost:30000', bizModule: 'dms', bizScene: 'dms.qianpiye',
      canAnnotate: true, documentId: 'file-1', pluginVersion: '0.1.0', scope: 'onlyoffice:dms-qianpiye',
    })).toThrow('签批页标注插件运行上下文无效');
  });
 
  it('仅报告无效字段名,不暴露票据内容', () => {
    expect(() => parsePluginContext({
      apiBaseUrl: 'http://localhost:30000', bizModule: 'dms', bizScene: 'dms.qianpiye',
      canAnnotate: true, documentId: 'file-1', pluginVersion: '0.1.0', scope: 'onlyoffice:dms-qianpiye',
    })).toThrow('缺少或无效字段:ticket');
  });
});