Files
openclaw/extensions/byteplus/video-generation-provider.test.ts
2026-04-08 09:58:22 +01:00

64 lines
1.9 KiB
TypeScript

import { beforeAll, describe, expect, it, vi } from "vitest";
import {
getProviderHttpMocks,
installProviderHttpMockCleanup,
} from "../../test/helpers/media-generation/provider-http-mocks.js";
const { postJsonRequestMock, fetchWithTimeoutMock } = getProviderHttpMocks();
let buildBytePlusVideoGenerationProvider: typeof import("./video-generation-provider.js").buildBytePlusVideoGenerationProvider;
beforeAll(async () => {
({ buildBytePlusVideoGenerationProvider } = await import("./video-generation-provider.js"));
});
installProviderHttpMockCleanup();
describe("byteplus video generation provider", () => {
it("creates a content-generation task, polls, and downloads the video", async () => {
postJsonRequestMock.mockResolvedValue({
response: {
json: async () => ({
id: "task_123",
}),
},
release: vi.fn(async () => {}),
});
fetchWithTimeoutMock
.mockResolvedValueOnce({
json: async () => ({
id: "task_123",
status: "succeeded",
content: {
video_url: "https://example.com/byteplus.mp4",
},
model: "seedance-1-0-lite-t2v-250428",
}),
})
.mockResolvedValueOnce({
headers: new Headers({ "content-type": "video/mp4" }),
arrayBuffer: async () => Buffer.from("mp4-bytes"),
});
const provider = buildBytePlusVideoGenerationProvider();
const result = await provider.generateVideo({
provider: "byteplus",
model: "seedance-1-0-lite-t2v-250428",
prompt: "A lantern floats upward into the night sky",
cfg: {},
});
expect(postJsonRequestMock).toHaveBeenCalledWith(
expect.objectContaining({
url: "https://ark.ap-southeast.bytepluses.com/api/v3/contents/generations/tasks",
}),
);
expect(result.videos).toHaveLength(1);
expect(result.metadata).toEqual(
expect.objectContaining({
taskId: "task_123",
}),
);
});
});