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');
|
});
|
});
|