test: consolidate nodes screen helpers

This commit is contained in:
Peter Steinberger
2026-02-16 02:00:59 +00:00
parent f835301aed
commit 88033002ba
2 changed files with 50 additions and 37 deletions

View File

@@ -9,6 +9,7 @@ import {
writeBase64ToFile,
writeUrlToFile,
} from "./nodes-camera.js";
import { parseScreenRecordPayload, screenRecordTempPath } from "./nodes-screen.js";
describe("nodes camera helpers", () => {
it("parses camera.snap payload", () => {
@@ -104,3 +105,52 @@ describe("nodes camera helpers", () => {
);
});
});
describe("nodes screen helpers", () => {
it("parses screen.record payload", () => {
const payload = parseScreenRecordPayload({
format: "mp4",
base64: "Zm9v",
durationMs: 1000,
fps: 12,
screenIndex: 0,
hasAudio: true,
});
expect(payload.format).toBe("mp4");
expect(payload.base64).toBe("Zm9v");
expect(payload.durationMs).toBe(1000);
expect(payload.fps).toBe(12);
expect(payload.screenIndex).toBe(0);
expect(payload.hasAudio).toBe(true);
});
it("drops invalid optional fields instead of throwing", () => {
const payload = parseScreenRecordPayload({
format: "mp4",
base64: "Zm9v",
durationMs: "nope",
fps: null,
screenIndex: "0",
hasAudio: 1,
});
expect(payload.durationMs).toBeUndefined();
expect(payload.fps).toBeUndefined();
expect(payload.screenIndex).toBeUndefined();
expect(payload.hasAudio).toBeUndefined();
});
it("rejects invalid screen.record payload", () => {
expect(() => parseScreenRecordPayload({ format: "mp4" })).toThrow(
/invalid screen\.record payload/i,
);
});
it("builds screen record temp path", () => {
const p = screenRecordTempPath({
ext: "mp4",
tmpDir: "/tmp",
id: "id1",
});
expect(p).toBe(path.join("/tmp", "openclaw-screen-record-id1.mp4"));
});
});

View File

@@ -1,37 +0,0 @@
import path from "node:path";
import { describe, expect, it } from "vitest";
import { parseScreenRecordPayload, screenRecordTempPath } from "./nodes-screen.js";
describe("nodes screen helpers", () => {
it("parses screen.record payload", () => {
const payload = parseScreenRecordPayload({
format: "mp4",
base64: "Zm9v",
durationMs: 1000,
fps: 12,
screenIndex: 0,
hasAudio: true,
});
expect(payload.format).toBe("mp4");
expect(payload.base64).toBe("Zm9v");
expect(payload.durationMs).toBe(1000);
expect(payload.fps).toBe(12);
expect(payload.screenIndex).toBe(0);
expect(payload.hasAudio).toBe(true);
});
it("rejects invalid screen.record payload", () => {
expect(() => parseScreenRecordPayload({ format: "mp4" })).toThrow(
/invalid screen\.record payload/i,
);
});
it("builds screen record temp path", () => {
const p = screenRecordTempPath({
ext: "mp4",
tmpDir: "/tmp",
id: "id1",
});
expect(p).toBe(path.join("/tmp", "openclaw-screen-record-id1.mp4"));
});
});