chat.test.js
1 import { describe, expect, it } from 'vitest'; 2 import { __test__ } from './chat.js'; 3 describe('xianyu chat helpers', () => { 4 it('builds goofish im urls from ids', () => { 5 expect(__test__.buildChatUrl('1038951278192', '3650092411')).toBe('https://www.goofish.com/im?itemId=1038951278192&peerUserId=3650092411'); 6 }); 7 it('normalizes numeric ids', () => { 8 expect(__test__.normalizeNumericId('1038951278192', 'item_id', '1038951278192')).toBe('1038951278192'); 9 expect(__test__.normalizeNumericId(3650092411, 'user_id', '3650092411')).toBe('3650092411'); 10 }); 11 it('rejects non-numeric ids', () => { 12 expect(() => __test__.normalizeNumericId('abc', 'item_id', '1038951278192')).toThrow(); 13 expect(() => __test__.normalizeNumericId('3650092411x', 'user_id', '3650092411')).toThrow(); 14 }); 15 });