import { describe, expect, test } from "bun:test"; import { parsePublicPostCreateCommentBody, parseUnlistedCreateCommentBody } from "./comments-create-body"; globalThis.createError ??= ((input: { statusCode: number; statusMessage: string }) => { const error = new Error(input.statusMessage) as Error & { statusCode: number; statusMessage: string }; error.statusCode = input.statusCode; error.statusMessage = input.statusMessage; return error; }) as any; describe("parsePublicPostCreateCommentBody", () => { test("passes through guestEmail and guestIsAnonymous for public endpoint", () => { const parsed = parsePublicPostCreateCommentBody({ parentId: 11, guestDisplayName: "访客A", guestEmail: "guest@example.com", guestIsAnonymous: true, body: "hello", }); expect(parsed).toEqual({ parentId: 11, guestDisplayName: "访客A", guestEmail: "guest@example.com", guestIsAnonymous: true, body: "hello", }); }); test("keeps guestIsAnonymous as undefined when field is missing", () => { const parsed = parsePublicPostCreateCommentBody({ guestDisplayName: "访客C", guestEmail: undefined, body: "legacy", }); expect(parsed).toEqual({ parentId: null, guestDisplayName: "访客C", guestEmail: undefined, guestIsAnonymous: undefined, body: "legacy", }); }); }); describe("parseUnlistedCreateCommentBody", () => { test("passes through guestEmail and guestIsAnonymous for unlisted endpoint", () => { const parsed = parseUnlistedCreateCommentBody({ parentId: null, guestDisplayName: "访客B", guestEmail: "anon@example.com", guestIsAnonymous: false, body: "world", }); expect(parsed).toEqual({ parentId: null, guestDisplayName: "访客B", guestEmail: "anon@example.com", guestIsAnonymous: false, body: "world", }); }); });