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