31 lines
882 B
TypeScript
31 lines
882 B
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { validateImageUploadFile } from "./cdn-images";
|
|
|
|
const png = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
|
|
describe("image upload validation", () => {
|
|
test("accepts a valid PNG signature", () => {
|
|
expect(() =>
|
|
validateImageUploadFile(
|
|
{ name: "avatar.png", type: "image/png", size: png.length },
|
|
png
|
|
)
|
|
).not.toThrow();
|
|
});
|
|
|
|
test("rejects content that does not match the declared type", () => {
|
|
expect(() =>
|
|
validateImageUploadFile(
|
|
{ name: "avatar.png", type: "image/png", size: 4 },
|
|
new Uint8Array([1, 2, 3, 4])
|
|
)
|
|
).toThrow("contents do not match");
|
|
});
|
|
|
|
test("rejects empty files", () => {
|
|
expect(() =>
|
|
validateImageUploadFile({ name: "avatar.png", type: "image/png", size: 0 })
|
|
).toThrow("cannot be empty");
|
|
});
|
|
});
|