Files
omniai-web/src/utils/enterpriseVideoPolicy.test.ts
T

86 lines
2.0 KiB
TypeScript
Raw Normal View History

2026-06-09 11:34:56 +08:00
import { describe, expect, it } from "../test/testHarness";
import {
calculateEnterpriseVideoCredits,
2026-06-10 14:27:42 +08:00
type EnterpriseVideoPricingConfig,
2026-06-09 11:34:56 +08:00
getEnterpriseVideoCreditRate,
normalizeEnterpriseResolution,
} from "./enterpriseVideoPolicy";
describe("enterpriseVideoPolicy", () => {
it("keeps video billing at 1 CNY to 100 credits", () => {
expect(
calculateEnterpriseVideoCredits({
model: "happyhorse-1.0",
resolution: "1080P",
durationSeconds: 5,
}),
).toBe(640);
expect(
calculateEnterpriseVideoCredits({
model: "wan2.7-i2v",
resolution: "720P",
durationSeconds: 5,
}),
).toBe(300);
});
it("rounds duration up to the next second before billing", () => {
expect(
calculateEnterpriseVideoCredits({
model: "vidu-q3-turbo",
resolution: "1080P",
durationSeconds: 5.2,
}),
).toBe(600);
});
it("normalizes unsupported resolutions to 1080P", () => {
expect(normalizeEnterpriseResolution("4K")).toBe("1080P");
expect(
getEnterpriseVideoCreditRate({
model: "pixverse-c1",
resolution: "4K",
durationSeconds: 5,
}),
).toBe(1);
});
2026-06-10 14:27:42 +08:00
it("uses server-provided pricing config before fallback pricing", () => {
const serverPricing: EnterpriseVideoPricingConfig = {
creditsPerCny: 100,
defaultResolution: "1080P",
rules: [
{
id: "happyhorse-server",
modelIncludes: ["happyhorse"],
rates: { "720P": 2, "1080P": 3 },
},
],
};
expect(
getEnterpriseVideoCreditRate(
{
model: "happyhorse-1.0",
resolution: "1080P",
durationSeconds: 5,
},
serverPricing,
),
).toBe(3);
expect(
calculateEnterpriseVideoCredits(
{
model: "happyhorse-1.0",
resolution: "1080P",
durationSeconds: 5,
},
serverPricing,
),
).toBe(1500);
});
2026-06-09 11:34:56 +08:00
});