import fc from 'fast-check'; import { describe, expect, it } from 'vitest'; import { isLikelySpam, MIN_FILL_MS } from './isLikelySpam'; describe('isLikelySpam', () => { it('lets a person through and stops a filled honeypot or a hurry', () => { expect(isLikelySpam({ honeypot: '', shownAt: 0, now: 10_000 })).toBe( false, ); expect( isLikelySpam({ honeypot: 'https://x.nl', shownAt: 0, now: 10_000 }), ).toBe(true); expect(isLikelySpam({ honeypot: '', shownAt: 0, now: 1_000 })).toBe( true, ); }); it('is spam exactly when the honeypot is filled or under 3 s (oracle)', () => { fc.assert( fc.property( fc.oneof(fc.constant(''), fc.string()), fc.integer({ min: 0, max: 1e9 }), fc.integer({ min: 0, max: 20_000 }), (honeypot, shownAt, elapsed) => { expect( isLikelySpam({ honeypot, shownAt, now: shownAt + elapsed, }), ).toBe(honeypot !== '' || elapsed < MIN_FILL_MS); }, ), ); }); });