Files
content-factory/apps/frontend/tests/article_dashboard.test.mjs
T

64 lines
2.0 KiB
JavaScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import ts from "typescript";
const testDir = path.dirname(fileURLToPath(import.meta.url));
const sourcePath = path.resolve(
testDir,
"../src/features/article-dashboard/model.ts",
);
const source = readFileSync(sourcePath, "utf8");
const compiled = ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
});
const moduleExports = {};
new Function("exports", compiled.outputText)(moduleExports);
const { buildDashboardRows } = moduleExports;
const rows = buildDashboardRows(
[
{
id: "11111111-1111-1111-1111-111111111111",
target_site_id: "22222222-2222-2222-2222-222222222222",
status: "ARTICLE_BRIEF_CREATED",
publishing_status: "PUBLISH_NOT_STARTED",
brief_description: "Build AI article intake shell",
working_title: "AI Intake Shell",
language: "en",
content_type: "longform_guide",
primary_keyword: "AI workflow",
assigned_editor_id: null,
created_at: "2025-01-01T00:00:00Z",
updated_at: "2025-01-01T00:00:00Z",
},
],
[
{
id: "22222222-2222-2222-2222-222222222222",
name: "Editorial site",
slug: "editorial-site",
publishing_type: "git_next",
default_language: "en",
brand_voice: "Balanced",
audience: "Editor teams",
seo_rules: {},
visual_rules: {},
source_rules: {},
publishing_rules: {},
active_script_config_version_id: null,
created_at: "2025-01-01T00:00:00Z",
updated_at: "2025-01-01T00:00:00Z",
},
],
);
assert.equal(rows.length, 1, "one row should be built");
assert.equal(rows[0].targetSiteName, "Editorial site", "target site name should map");
assert.equal(rows[0].nextAction, "Run boundary questions", "next action should match status mapping");
assert.equal(rows[0].assignedEditor, "Unassigned", "missing editor id should render Unassigned");