import { describe, expect, it } from 'vitest'; import { cleanupUrl, mergeReadMoreLinks } from '../src/links/url.js'; import { ExtractedLink } from '../src/parsing/types.js'; describe('URL cleanup', () => { it('strips tracking parameters and unwraps supported redirect URLs', () => { const result = cleanupUrl( 'https://newsletter.example/redirect?url=https%3A%2F%2Fexample.com%2Fpost%3Futm_source%3Dx%26id%3D1&mc_cid=abc', { trackingParams: ['utm_*', 'mc_cid'], unwrapRedirects: true } ); expect(result).toBe('https://example.com/post?id=1'); }); }); describe('read-more merging', () => { it('merges a read-more link into the preceding link with the same normalized URL', () => { const links: ExtractedLink[] = [ { url: 'https://example.com/a', normalizedUrl: 'https://example.com/a', title: 'Great article', description: 'A useful summary', sourceText: 'Great article', section: 'Python' }, { url: 'https://example.com/a?utm_source=x', normalizedUrl: 'https://example.com/a', title: 'Read more', description: '', sourceText: 'Read more' } ]; expect(mergeReadMoreLinks(links, /^(read more)$/i)).toHaveLength(1); }); });