Files
social-mcp/apps/xhh-mcp/test/xhh-extractors.test.ts
T

37 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
detectCaptchaText,
extractLinkIdFromUrl,
extractUserIdFromUrl,
firstNonEmpty,
parseCountString,
} from '../src/platforms/xiaoheihe/extractors.js';
describe('xhh extractors', () => {
it('parses count strings', () => {
expect(parseCountString('123')).toBe(123);
expect(parseCountString('1.2万')).toBe(12000);
expect(parseCountString('')).toBe(0);
});
it('detects captcha text', () => {
expect(detectCaptchaText('show_captcha')).toBe(true);
expect(detectCaptchaText('请完成验证码')).toBe(true);
expect(detectCaptchaText('normal page')).toBe(false);
});
it('extracts link_id and user_id from url', () => {
expect(extractLinkIdFromUrl('https://www.xiaoheihe.cn/app/bbs/link/123456')).toBe('123456');
expect(extractLinkIdFromUrl('/app/bbs/link/998877')).toBe('998877');
expect(extractUserIdFromUrl('https://www.xiaoheihe.cn/app/user/profile/112233')).toBe('112233');
expect(extractUserIdFromUrl('/app/user/profile/778899')).toBe('778899');
});
it('returns first non-empty value', () => {
expect(firstNonEmpty('', ' ', 'x', 'y')).toBe('x');
expect(firstNonEmpty('', ' ')).toBe('');
});
});