// @vitest-environment node
import { describe, expect, it } from "vitest";
import { createPendingAttachment } from "@/lib/db/attachments";
class RecordingDatabase {
queryText = "";
async query<Row>(text: string) {
this.queryText = text;
return {
rows: [
{
id: "00000000-0000-4000-8000-000000000077",
original_name: "report.txt",
content_type: "text/plain",
byte_size: "12",
gate_file_id: "file-opaque_123",
object_key: null,
},
] as Row[],
};
}
}
describe("attachment insert query", () => {
it("casts the owner UUID and stores the opaque Gate file ID", async () => {
const database = new RecordingDatabase();
await createPendingAttachment(
database,
"00000000-0000-4000-8000-000000000001",
{
name: "report.txt",
contentType: "text/plain",
size: 12,
gateFileId: "file-opaque_123",
},
);
expect(database.queryText).toContain("VALUES ($1::uuid, $2, $3, $4");
expect(database.queryText).toContain("byte_size, gate_file_id, state");
expect(database.queryText).not.toContain("concat('users/'");
});
});