| 1 | import * as Schema from "effect/Schema"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { AttachmentCreateUploadUrlInput } from "./assets.ts"; |
| 5 | import { |
| 6 | PROVIDER_SEND_TURN_MAX_FILE_BYTES, |
| 7 | PROVIDER_SEND_TURN_MAX_IMAGE_BYTES, |
| 8 | } from "./chatAttachment.ts"; |
| 9 | |
| 10 | const isUploadInput = Schema.is(AttachmentCreateUploadUrlInput); |
| 11 | |
| 12 | const uploadInput = { |
| 13 | name: "screenshot.png", |
| 14 | mimeType: "image/png", |
| 15 | sizeBytes: 3, |
| 16 | } as const; |
| 17 | |
| 18 | describe("AttachmentCreateUploadUrlInput", () => { |
| 19 | it("accepts supported image attachments", () => { |
| 20 | expect(isUploadInput(uploadInput)).toBe(true); |
| 21 | }); |
| 22 | |
| 23 | it("rejects image types that providers do not support", () => { |
| 24 | expect(isUploadInput({ ...uploadInput, mimeType: "image/svg+xml" })).toBe(false); |
| 25 | }); |
| 26 | |
| 27 | it("accepts generic files without treating them as provider images", () => { |
| 28 | expect( |
| 29 | isUploadInput({ |
| 30 | type: "file", |
| 31 | name: "report.pdf", |
| 32 | mimeType: "application/pdf", |
| 33 | sizeBytes: PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + 1, |
| 34 | }), |
| 35 | ).toBe(true); |
| 36 | expect( |
| 37 | isUploadInput({ |
| 38 | type: "file", |
| 39 | name: "diagram.svg", |
| 40 | mimeType: "image/svg+xml", |
| 41 | sizeBytes: 3, |
| 42 | }), |
| 43 | ).toBe(true); |
| 44 | }); |
| 45 | |
| 46 | it("rejects empty and oversized uploads", () => { |
| 47 | expect(isUploadInput({ ...uploadInput, sizeBytes: 0 })).toBe(false); |
| 48 | expect( |
| 49 | isUploadInput({ ...uploadInput, sizeBytes: PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + 1 }), |
| 50 | ).toBe(false); |
| 51 | expect( |
| 52 | isUploadInput({ |
| 53 | type: "file", |
| 54 | name: "archive.zip", |
| 55 | mimeType: "application/zip", |
| 56 | sizeBytes: PROVIDER_SEND_TURN_MAX_FILE_BYTES + 1, |
| 57 | }), |
| 58 | ).toBe(false); |
| 59 | }); |
| 60 | }); |