import { describe, expect, it } from "../test/testHarness"; import { calculateEnterpriseVideoCredits, type EnterpriseVideoPricingConfig, 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); }); 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); }); });