26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import * as shared from "../src/index.js";
|
|
|
|
function messageSchema(): { safeParse(value: unknown): { success: boolean } } {
|
|
const candidate = Reflect.get(shared, "MessageInputSchema");
|
|
expect(candidate, "MessageInputSchema must be exported").toBeDefined();
|
|
return candidate;
|
|
}
|
|
|
|
describe("MessageInputSchema", () => {
|
|
it("accepts text-only, image-only, and combined messages", () => {
|
|
expect(messageSchema().safeParse({ text: "hello", attachmentIds: [] }).success).toBe(true);
|
|
expect(messageSchema().safeParse({ text: "", attachmentIds: ["att_123"] }).success).toBe(true);
|
|
expect(messageSchema().safeParse({ text: "look", attachmentIds: ["att_123"] }).success).toBe(true);
|
|
});
|
|
|
|
it("rejects a message without text or attachments", () => {
|
|
expect(messageSchema().safeParse({ text: " ", attachmentIds: [] }).success).toBe(false);
|
|
});
|
|
|
|
it("rejects duplicate or malformed attachment ids", () => {
|
|
expect(messageSchema().safeParse({ text: "x", attachmentIds: ["att_1", "att_1"] }).success).toBe(false);
|
|
expect(messageSchema().safeParse({ text: "x", attachmentIds: ["../secret"] }).success).toBe(false);
|
|
});
|
|
});
|