import { describe, expect, it } from "vitest"; import { EditVideoInputSchema, ExportVideoInputSchema } from "./media-video.js"; const edit = (steps: unknown[]) => EditVideoInputSchema.safeParse({ artifact_id: "a", title: "Reel", steps }); describe("edit_video input", () => { it("accepts ordered steps and fills defaults", () => { const parsed = EditVideoInputSchema.parse({ artifact_id: "a", title: " Reel ", steps: [ { op: "trim", start: 1, end: 5 }, { op: "reframe", preset: "vertical" }, { op: "extract_audio" }, ], }); expect(parsed.title).toBe("Reel"); expect(parsed.steps[1]).toEqual({ op: "reframe", preset: "vertical", fit: "crop" }); // The job stores the parsed input and parses it again when it runs. expect(EditVideoInputSchema.parse(parsed)).toEqual(parsed); }); it("rejects malformed step lists", () => { expect(edit([]).success).toBe(false); expect(edit([{ op: "trim", start: 5, end: 5 }]).success).toBe(false); expect(edit([{ op: "keep", segments: [{ start: 3, end: 1 }] }]).success).toBe(false); expect(edit([{ op: "speed", factor: 8 }]).success).toBe(false); expect(edit([{ op: "extract_audio" }, { op: "mute" }]).success).toBe(false); expect(edit([{ op: "poster", at: 1 }, { op: "extract_audio" }]).success).toBe(false); expect( edit([ { op: "poster", at: 1 }, { op: "poster", at: 2 }, ]).success, ).toBe(false); expect(edit([{ op: "blur" }]).success).toBe(false); expect(edit([{ op: "overlay", artifact_id: "logo", start: 4, end: 2 }]).success).toBe(false); expect(edit([{ op: "overlay", artifact_id: "logo", width: 1.5 }]).success).toBe(false); expect(edit([{ op: "overlay", artifact_id: "logo", opacity: 0 }]).success).toBe(false); expect(edit([{ op: "overlay", artifact_id: "logo", position: "middle" }]).success).toBe(false); expect(edit([{ op: "concat", artifact_ids: ["intro"], at: "middle" }]).success).toBe(false); expect( EditVideoInputSchema.safeParse({ artifact_id: "a", steps: [{ op: "mute" }] }).success, ).toBe(false); }); }); describe("edit_video branding steps", () => { it("defaults a logo to the top right at 15% of the width and clips to the end", () => { const parsed = EditVideoInputSchema.parse({ artifact_id: "a", title: "Reel", steps: [ { op: "concat", artifact_ids: ["intro"], at: "start" }, { op: "concat", artifact_ids: ["outro"] }, { op: "overlay", artifact_id: "logo" }, { op: "overlay", artifact_id: "mark", position: "center", opacity: 0.4, end: 3 }, ], }); expect(parsed.steps).toEqual([ { op: "concat", artifact_ids: ["intro"], at: "start" }, { op: "concat", artifact_ids: ["outro"], at: "end" }, { op: "overlay", artifact_id: "logo", position: "top_right", width: 0.15, opacity: 1 }, { op: "overlay", artifact_id: "mark", position: "center", width: 0.15, opacity: 0.4, end: 3 }, ]); expect(EditVideoInputSchema.parse(parsed)).toEqual(parsed); }); }); describe("export_video input", () => { it("needs at least one preset or platform and defaults to cropping", () => { expect(ExportVideoInputSchema.parse({ artifact_id: "a", presets: ["square"] })).toEqual({ artifact_id: "a", presets: ["square"], fit: "crop", }); expect(ExportVideoInputSchema.parse({ artifact_id: "a", platforms: ["tiktok"] })).toEqual({ artifact_id: "a", platforms: ["tiktok"], fit: "crop", }); expect(ExportVideoInputSchema.safeParse({ artifact_id: "a", presets: [] }).success).toBe(false); expect(ExportVideoInputSchema.safeParse({ artifact_id: "a" }).success).toBe(false); expect(ExportVideoInputSchema.safeParse({ artifact_id: "a", presets: ["imax"] }).success).toBe( false, ); expect( ExportVideoInputSchema.safeParse({ artifact_id: "a", platforms: ["myspace"] }).success, ).toBe(false); }); it("takes at most six targets across platforms and presets", () => { const platforms = ["tiktok", "youtube-shorts", "instagram-reels", "linkedin"]; expect( ExportVideoInputSchema.safeParse({ artifact_id: "a", platforms, presets: ["square", "portrait"], }).success, ).toBe(true); const tooMany = ExportVideoInputSchema.safeParse({ artifact_id: "a", platforms, presets: ["square", "portrait", "classic"], }); expect(tooMany.success).toBe(false); expect(tooMany.error?.issues[0]?.path).toEqual(["platforms"]); }); });