Files
yingxiangli-duanju/tests/normalize.test.mjs
2026-07-31 13:41:09 +08:00

35 lines
1.6 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import {
extractVideoTaskId,
extractVideoUrl,
normalizeAssetReference,
normalizeVideoStatus,
} from "../lib/normalize.mjs";
test("素材审核返回值统一为 asset 协议并保留大小写", () => {
assert.equal(normalizeAssetReference({ asset_url: "Asset://asset-1" }), "asset://asset-1");
assert.equal(normalizeAssetReference({ downstream_asset_id: "asset-2" }), "asset://asset-2");
assert.equal(normalizeAssetReference({ Id: "asset-3" }), "asset://asset-3");
assert.equal(normalizeAssetReference({ asset_id: "mat_ADyx4iQv" }), "asset://mat_ADyx4iQv");
});
test("兼容视频任务 id 和状态字段", () => {
assert.equal(extractVideoTaskId({ task_id: "task-1" }), "task-1");
assert.equal(extractVideoTaskId({ data: { id: "task-2" } }), "task-2");
assert.equal(normalizeVideoStatus({ status: "succeeded" }), "completed");
assert.equal(normalizeVideoStatus({ data: { status: "failed" } }), "failed");
});
test("从常见响应位置提取视频地址", () => {
assert.equal(extractVideoUrl({ output: { video_url: "https://example.com/demo.mp4" } }), "https://example.com/demo.mp4");
});
test("生成时长提供 5 到 14 秒全部整数选项", () => {
const html = readFileSync(new URL("../public/index.html", import.meta.url), "utf8");
const durationSelect = html.match(/<select id="duration">([\s\S]*?)<\/select>/)?.[1] || "";
const values = [...durationSelect.matchAll(/<option value="(\d+)">/g)].map((match) => Number(match[1]));
assert.deepEqual(values, [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]);
});