mirror of https://github.com/openclaw/openclaw.git
77 lines
2.2 KiB
TypeScript
77 lines
2.2 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import { imageResult, parseAvailableTags } from "./common.js";
|
|
|
|
const PNG_1X1_BASE64 =
|
|
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Wn8n0sAAAAASUVORK5CYII=";
|
|
|
|
describe("parseAvailableTags", () => {
|
|
test("returns undefined for non-array inputs", () => {
|
|
expect(parseAvailableTags(undefined)).toBeUndefined();
|
|
expect(parseAvailableTags(null)).toBeUndefined();
|
|
expect(parseAvailableTags("oops")).toBeUndefined();
|
|
});
|
|
|
|
test("drops entries without a string name and returns undefined when empty", () => {
|
|
expect(parseAvailableTags([{ id: "1" }])).toBeUndefined();
|
|
expect(parseAvailableTags([{ name: 123 }])).toBeUndefined();
|
|
});
|
|
|
|
test("keeps falsy ids and sanitizes emoji fields", () => {
|
|
const result = parseAvailableTags([
|
|
{ id: "0", name: "General", emoji_id: null },
|
|
{ id: "1", name: "Docs", emoji_name: "📚" },
|
|
{ name: "Bad", emoji_id: 123 },
|
|
]);
|
|
expect(result).toEqual([
|
|
{ id: "0", name: "General", emoji_id: null },
|
|
{ id: "1", name: "Docs", emoji_name: "📚" },
|
|
{ name: "Bad" },
|
|
]);
|
|
});
|
|
});
|
|
describe("imageResult", () => {
|
|
test("stores media delivery in details.media instead of MEDIA text", async () => {
|
|
const result = await imageResult({
|
|
label: "test:image",
|
|
path: "/tmp/test.png",
|
|
base64: PNG_1X1_BASE64,
|
|
mimeType: "image/png",
|
|
});
|
|
|
|
expect(result.content).toEqual([
|
|
{
|
|
type: "image",
|
|
data: PNG_1X1_BASE64,
|
|
mimeType: "image/png",
|
|
},
|
|
]);
|
|
expect(result.details).toEqual({
|
|
path: "/tmp/test.png",
|
|
media: {
|
|
mediaUrl: "/tmp/test.png",
|
|
},
|
|
});
|
|
});
|
|
|
|
test("keeps extra text without MEDIA text fallback", async () => {
|
|
const result = await imageResult({
|
|
label: "test:image",
|
|
path: "/tmp/test.png",
|
|
base64: PNG_1X1_BASE64,
|
|
mimeType: "image/png",
|
|
extraText: "label text",
|
|
});
|
|
|
|
expect(result.content?.[0]).toEqual({
|
|
type: "text",
|
|
text: "label text",
|
|
});
|
|
expect(result.content?.[1]).toEqual({
|
|
type: "image",
|
|
data: PNG_1X1_BASE64,
|
|
mimeType: "image/png",
|
|
});
|
|
expect(JSON.stringify(result.content)).not.toContain("MEDIA:");
|
|
});
|
|
});
|