Files
AndreaSlopFotografie/web/src/lib/isLikelySpam.test.ts
T
SluijsensandClaude Opus 5.5 0fce403ebc Adds the Contact section to the homepage
Adds the contact form with the live fields, validation and browser-side
anti-spam, behind a coming-soon notice with a mail button until the API
exists. A "Boek" link on a price card selects its package, tidies the
URL and moves focus to the form. The form loads only when it comes near
the screen, so the hero does not wait for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 00:36:43 +02:00

37 lines
1.2 KiB
TypeScript

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);
},
),
);
});
});