import { describe, expect, test } from "bun:test"; import { captchaConsume, captchaCreate } from "./store"; describe("captcha store", () => { test("consume succeeds once then fails", () => { const { captchaId } = captchaCreate("ab12"); expect(captchaConsume(captchaId, "ab12")).toBe(true); expect(captchaConsume(captchaId, "ab12")).toBe(false); }); test("wrong answer invalidates challenge", () => { const { captchaId } = captchaCreate("ab12"); expect(captchaConsume(captchaId, "xxxx")).toBe(false); expect(captchaConsume(captchaId, "ab12")).toBe(false); }); test("trim + lowercase on user input", () => { const { captchaId } = captchaCreate("ab12"); expect(captchaConsume(captchaId, " AB12 ")).toBe(true); }); test("length mismatch fails without throwing", () => { const { captchaId } = captchaCreate("ab12"); expect(captchaConsume(captchaId, "x")).toBe(false); }); test("expired challenge fails", () => { const { captchaId } = captchaCreate("ab12", { ttlMs: -1000 }); expect(captchaConsume(captchaId, "ab12")).toBe(false); }); });