Files
buzz-sheet/lib/media/inspect.test.ts
T
gunshiz 87e6bcd96f
CI / Verify and audit (push) Successful in 2m33s
CI / Build, scan and deploy immutable images (push) Failing after 1m29s
feat : 6 astra improve it
2026-09-22 18:28:18 +07:00

17 lines
855 B
TypeScript

import sharp from "sharp";
import { describe, expect, it } from "vitest";
import { inspectImage } from "./inspect";
describe("image decoding before publication", () => {
it("accepts real decoded image dimensions", async () => {
const bytes = await sharp({ create: { width: 8, height: 12, channels: 3, background: "red" } }).png().toBuffer();
await expect(inspectImage(bytes, "image/png")).resolves.toEqual({ width: 8, height: 12 });
await expect(inspectImage(bytes, "image/jpeg")).rejects.toMatchObject({ status: 422 });
await expect(inspectImage(bytes.subarray(0, 40), "image/png")).rejects.toMatchObject({ status: 422 });
});
it("rejects a magic-byte-only fake", async () => {
await expect(inspectImage(Uint8Array.from([137, 80, 78, 71, 13, 10, 26, 10]), "image/png"))
.rejects.toMatchObject({ status: 422 });
});
});