import { describe, expect, it } from 'vitest'; import { OfferedUrls } from '../../src/background/capture/offered-urls.js'; describe('OfferedUrls', () => { it('remembers a URL for the TTL, then forgets it', () => { let now = 0; const o = new OfferedUrls({ ttlMs: 1000, now: () => now }); o.mark('https://x/a.zip'); expect(o.has('https://x/a.zip')).toBe(true); now = 1001; expect(o.has('https://x/a.zip')).toBe(false); expect(o.size).toBe(0); }); it('re-mark refreshes the TTL', () => { let now = 0; const o = new OfferedUrls({ ttlMs: 1000, now: () => now }); o.mark('u'); now = 900; o.mark('u'); now = 1800; // 900 since the last mark expect(o.has('u')).toBe(true); }); it('evicts the oldest past the size cap', () => { const o = new OfferedUrls({ maxEntries: 2, ttlMs: 10_000, now: () => 0 }); o.mark('a'); o.mark('b'); o.mark('c'); expect(o.has('a')).toBe(false); expect(o.has('b')).toBe(true); expect(o.has('c')).toBe(true); }); it('is false for a URL it has never seen', () => { expect(new OfferedUrls().has('nope')).toBe(false); }); });