211e5369a0
- Extracted image metadata detection and MIME type utilities to @oh-my-pi/pi-utils package for shared use across projects. - Consolidated image-input.ts and mime.ts modules into image-loading.ts with simplified API removing redundant metadata parameters. - Updated all import paths across coding-agent to use readImageMetadata from @oh-my-pi/pi-utils instead of local utilities. - Added peek-file utility module to @oh-my-pi/pi-utils with buffer pooling for efficient file header reading.
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { afterEach, describe, expect, test, vi } from "bun:test";
|
|
import * as imageConvert from "../src/utils/image-convert";
|
|
import { ensureSupportedImageInput } from "../src/utils/image-loading";
|
|
|
|
describe("ensureSupportedImageInput", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
test("returns supported image input unchanged", async () => {
|
|
const convertToPngSpy = vi.spyOn(imageConvert, "convertToPng");
|
|
const input = { type: "image" as const, data: "abc", mimeType: "image/png" };
|
|
|
|
const result = await ensureSupportedImageInput(input);
|
|
|
|
expect(result).toEqual(input);
|
|
expect(convertToPngSpy).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test("converts unsupported image input to png", async () => {
|
|
const convertToPngSpy = vi
|
|
.spyOn(imageConvert, "convertToPng")
|
|
.mockResolvedValue({ data: "pngdata", mimeType: "image/png" });
|
|
|
|
const result = await ensureSupportedImageInput({ type: "image", data: "bmpdata", mimeType: "image/bmp" });
|
|
|
|
expect(convertToPngSpy).toHaveBeenCalledWith("bmpdata", "image/bmp");
|
|
expect(result).toEqual({ type: "image", data: "pngdata", mimeType: "image/png" });
|
|
});
|
|
});
|