// @vitest-environment node
import { describe, expect, it } from "vitest";
import { AttachmentValidationError, validateAttachmentUpload } from "@/lib/chat/attachments";
describe("attachment validation", () => {
it("rejects an executable renamed as PDF", async () => {
const file = new File([new Uint8Array([0x4d, 0x5a])], "invoice.pdf", {
type: "application/pdf",
});
await expect(validateAttachmentUpload(file)).rejects.toBeInstanceOf(
AttachmentValidationError,
);
});
it("accepts a plain text attachment and normalizes its name", async () => {
const attachment = await validateAttachmentUpload(
new File(["brief"], "../brief.txt", { type: "text/plain" }),
);
expect(attachment).toMatchObject({ name: "brief.txt", contentType: "text/plain", size: 5 });
});
});