const assert = require("node:assert/strict"); const { calculateEnterpriseVideoCredits, getEnterpriseVideoCreditRate, getEnterpriseVideoPricingConfig, } = require("../src/enterpriseVideoBilling"); function getRule(config, id) { const rule = config.rules.find((item) => item.id === id); assert(rule, `missing enterprise video pricing rule: ${id}`); return rule; } const config = getEnterpriseVideoPricingConfig(); assert.equal(config.currency, "CNY"); assert.equal(config.creditsPerCny, 100); assert.equal(config.billingUnit, "per_second"); assert.deepEqual(config.resolutions, ["720P", "1080P"]); assert.equal(getRule(config, "happyhorse").rates["720P"], 0.72); assert.equal(getRule(config, "happyhorse").rates["1080P"], 1.28); assert.equal(getRule(config, "wanxiang-i2v").rates["720P"], 0.6); assert.equal(getRule(config, "kling-muted").rates["1080P"], 0.8); assert.equal( getEnterpriseVideoCreditRate({ model: "happyhorse-1.0", resolution: "1080P", }), getRule(config, "happyhorse").rates["1080P"], ); assert.equal( getEnterpriseVideoCreditRate({ model: "kling-3.0-dashscope", resolution: "720P", muted: true, hasReferenceVideo: false, }), getRule(config, "kling-muted").rates["720P"], ); assert.equal( calculateEnterpriseVideoCredits({ model: "vidu-q3-turbo", resolution: "1080P", durationSeconds: 5, }), 500, ); console.log("enterprise video pricing contract tests passed");