import { describe, expect, test } from "bun:test"; import { GuestCommentValidationError, normalizeGuestDisplayName, validateGuestCommentBody, } from "./post-comment-guest"; describe("normalizeGuestDisplayName", () => { test("trims and accepts valid name", () => { expect(normalizeGuestDisplayName(" ada ")).toBe("ada"); }); test("rejects empty", () => { expect(() => normalizeGuestDisplayName(" ")).toThrow(GuestCommentValidationError); }); test("rejects too long", () => { expect(() => normalizeGuestDisplayName("a".repeat(33))).toThrow(GuestCommentValidationError); }); }); describe("validateGuestCommentBody", () => { test("accepts plain text", () => { expect(validateGuestCommentBody("你好,世界")).toBe("你好,世界"); }); test("rejects http URL", () => { expect(() => validateGuestCommentBody("see http://x.com")).toThrow(GuestCommentValidationError); }); test("rejects markdown link", () => { expect(() => validateGuestCommentBody("[a](http://b)")).toThrow(GuestCommentValidationError); }); test("rejects too long", () => { expect(() => validateGuestCommentBody("z".repeat(501))).toThrow(GuestCommentValidationError); }); });