Files
dukang/server/dukang-api/src/integrations/wecom/wecom-plugin.util.test.ts
T
jacy 976bde37cc feat(wecom): 企微 API 插件增加 MCP Streamable HTTP 端点
与 REST/OpenAPI 并存,按实例权限自动 tools/list,免手填工具。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-08 16:57:42 +08:00

27 lines
941 B
TypeScript

import { BadRequestException } from '@nestjs/common';
import { describe, expect, it } from 'vitest';
import { wecomPluginCaller, wecomPluginMcpErrorText, wecomPluginQueryArg } from './wecom-plugin.util';
describe('wecomPluginCaller', () => {
it('prefers X-WeCom-User-Id', () => {
expect(wecomPluginCaller({ headers: { 'x-wecom-userid': 'alice', userid: 'bob' } })).toBe('alice');
});
it('falls back to plugin', () => {
expect(wecomPluginCaller({ headers: {} })).toBe('plugin');
});
});
describe('wecomPluginMcpErrorText', () => {
it('unwraps Nest HttpException message', () => {
expect(wecomPluginMcpErrorText(new BadRequestException('请提供查询关键词 q'))).toBe('请提供查询关键词 q');
});
});
describe('wecomPluginQueryArg', () => {
it('stringifies numbers and drops empty', () => {
expect(wecomPluginQueryArg(2)).toBe('2');
expect(wecomPluginQueryArg(' ')).toBeUndefined();
});
});