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
| import { describe, expect, it } from 'vitest';
|
| import { parsePluginContext } from '../../src/domain/plugin-context';
|
| const context = {
| apiBaseUrl: 'http://localhost:30000',
| documentId: 'file-1',
| bizDataId: 'record-1',
| bizModule: 'eln.template',
| bizScene: 'eln.template.annotate',
| pluginVersion: '0.1.0',
| canAnnotate: true,
| };
|
| describe('plugin context', () => {
| it('从 ONLYOFFICE 传给当前插件的扁平 options 读取运行上下文副本', () => {
| const result = parsePluginContext(context);
|
| expect(result).toEqual(context);
| expect(result).not.toBe(context);
| });
|
| it.each([
| undefined,
| {},
| { ...context, documentId: '' },
| { ...context, bizModule: 'other' },
| { ...context, bizScene: 'other' },
| { ...context, pluginVersion: '0.2.0' },
| { ...context, canAnnotate: 'true' },
| { ...context, apiBaseUrl: '' },
| { ...context, apiBaseUrl: 'javascript:alert(1)' },
| ])('拒绝缺失或非法的运行上下文', (options) => {
| expect(() => parsePluginContext(options)).toThrow('插件运行上下文无效');
| });
| });
|
|