import { describe, expect, it } from "vitest"; import { isHoneypotTriggered } from "./honeypot.js"; import { HONEYPOT_FIELD_KEY } from "./schema.js"; /** * Edge-case coverage for {@link isHoneypotTriggered}: the non-primitive * fall-through branch and the numeric / boolean "looks empty" boundaries * that decide whether a request is silently dropped. */ describe("isHoneypotTriggered — non-primitive values", () => { it("treats an object value as a trigger (final fall-through branch)", () => { // Bots that POST structured JSON into the hidden field still get flagged. expect(isHoneypotTriggered({ [HONEYPOT_FIELD_KEY]: { nested: "x" } })).toBe(true); }); it("treats an array value as a trigger", () => { expect(isHoneypotTriggered({ [HONEYPOT_FIELD_KEY]: ["a", "b"] })).toBe(true); }); }); describe("isHoneypotTriggered — numeric boundaries", () => { it("does not trigger on a literal zero", () => { // A numeric honeypot defaulting to 0 must not produce false positives. expect(isHoneypotTriggered({ [HONEYPOT_FIELD_KEY]: 0 })).toBe(false); }); it("triggers on a negative number", () => { expect(isHoneypotTriggered({ [HONEYPOT_FIELD_KEY]: -1 })).toBe(true); }); it("triggers on NaN (NaN !== 0)", () => { expect(isHoneypotTriggered({ [HONEYPOT_FIELD_KEY]: Number.NaN })).toBe(true); }); }); describe("isHoneypotTriggered — boolean / whitespace boundaries", () => { it("does not trigger on boolean false", () => { expect(isHoneypotTriggered({ [HONEYPOT_FIELD_KEY]: false })).toBe(false); }); it("does not trigger on whitespace beyond plain spaces (tabs / newlines)", () => { expect(isHoneypotTriggered({ [HONEYPOT_FIELD_KEY]: "\t\n \r" })).toBe(false); }); });