CODE · 1.7 KB
test/domain.test.js
Workspace snapshot · 09/04 14:52
import test from "node:test";
import assert from "node:assert/strict";
import { BUDGET_LIMIT_YEN, buildPublicReport, createProject, estimateProjectCost, remainingBudget, scoreQuality } from "../src/domain.js";
test("quality gate requires 80 points and no blocker", () => {
const review = { hook:15, clarity:15, originality:12, brand:8, motion:8, audio:8, platform:8, cta:4, technical:8, blockers:[] };
assert.equal(scoreQuality(review).score, 86);
assert.equal(scoreQuality(review).passed, true);
assert.equal(scoreQuality({ ...review, blockers:["字幕切れ"] }).passed, false);
});
test("GPT subscription image cost is fixed to zero", () => {
const estimate = estimateProjectCost({ patternId:"generated-hook", provider:"veo-fast", retryFactor:2 });
assert.equal(estimate.imageYen, 0);
assert.ok(estimate.estimatedTotalYen <= 2500);
});
test("budget reserves planned quality work", () => {
globalThis.crypto ??= { randomUUID: () => "project-1" };
const project = createProject({ title:"test", sourceText:"idea", formatId:"shorts", patternId:"generated-hook", provider:"veo-fast" }, 1);
const budget = remainingBudget([project]);
assert.equal(budget.budget, BUDGET_LIMIT_YEN);
assert.equal(budget.available, BUDGET_LIMIT_YEN - project.estimate.estimatedTotalYen);
});
test("public report excludes source text and internal prompts", () => {
globalThis.crypto ??= { randomUUID: () => "project-2" };
const project = createProject({ title:"公開実験", sourceText:"非公開情報 API_KEY=secret", formatId:"shorts", patternId:"motion-editorial", provider:"veo-fast" }, 1);
const report = buildPublicReport(project);
assert.doesNotMatch(JSON.stringify(report), /非公開情報|API_KEY|secret/);
});