import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { extractFacebookLinks } from '../src/platforms/facebook-search.service.js'; import { FacebookSearchService } from '../src/platforms/facebook-search.service.js'; describe('extractFacebookLinks', () => { it('extracts profile URLs, dedups, skips junk paths', () => { const html = ` NASA dup share ESA other`; const out = extractFacebookLinks(html, 'ddg'); assert.deepEqual( out.map((r) => r.url), ['https://www.facebook.com/nasa', 'https://m.facebook.com/esa'], ); assert.ok(out.every((r) => r.source === 'ddg')); }); it('returns empty for no matches', () => { assert.deepEqual(extractFacebookLinks('

nothing

', 'google'), []); }); }); describe('FacebookSearchService.search', () => { it('rejects multi-word usernames without fetching', async () => { const svc = new FacebookSearchService(); const out = (await svc.search('two words')) as any; assert.equal(out.found, false); }); it('merges ddg + google, dedups by url', async () => { const svc = new FacebookSearchService(); const real = globalThis.fetch; (globalThis as any).fetch = async (url: string) => ({ ok: true, text: async () => url.includes('duckduckgo') ? 'a' : 'ab', }); try { const out = (await svc.search('nasa')) as any; assert.equal(out.found, true); assert.equal(out.results.length, 2); } finally { globalThis.fetch = real; } }); });