You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.2 KiB
38 lines
1.2 KiB
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);
|
|
});
|
|
});
|
|
|