mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-30 09:46:35 +00:00
25 lines
1015 B
TypeScript
25 lines
1015 B
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { attachmentMime } from "./files"
|
|
|
|
describe("attachmentMime", () => {
|
|
test("keeps PDFs when the browser reports the mime", async () => {
|
|
const file = new File(["%PDF-1.7"], "guide.pdf", { type: "application/pdf" })
|
|
expect(await attachmentMime(file)).toBe("application/pdf")
|
|
})
|
|
|
|
test("normalizes structured text types to text/plain", async () => {
|
|
const file = new File(['{"ok":true}\n'], "data.json", { type: "application/json" })
|
|
expect(await attachmentMime(file)).toBe("text/plain")
|
|
})
|
|
|
|
test("accepts text files even with a misleading browser mime", async () => {
|
|
const file = new File(["export const x = 1\n"], "main.ts", { type: "video/mp2t" })
|
|
expect(await attachmentMime(file)).toBe("text/plain")
|
|
})
|
|
|
|
test("rejects binary files", async () => {
|
|
const file = new File([Uint8Array.of(0, 255, 1, 2)], "blob.bin", { type: "application/octet-stream" })
|
|
expect(await attachmentMime(file)).toBeUndefined()
|
|
})
|
|
})
|