71 lines
2.2 KiB
JavaScript
71 lines
2.2 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-assets/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 { buildMediaLibraryRows, resolveDraftPreviewMarkdown } = moduleExports;
|
|
|
|
const assets = [
|
|
{
|
|
id: "asset-approved",
|
|
article_id: "article-1",
|
|
section_id: "section-1",
|
|
asset_type: "hero_image",
|
|
title: "Hero visual",
|
|
prompt: "hero prompt",
|
|
object_key: "articles/article-1/assets/asset-approved/r2/hero.png",
|
|
file_url: "file:///tmp/hero.png",
|
|
alt_text: "Approved hero visual",
|
|
caption: "Used for section one",
|
|
status: "APPROVED",
|
|
history: [],
|
|
created_at: "2026-05-21T00:00:00Z",
|
|
updated_at: "2026-05-21T00:00:00Z",
|
|
},
|
|
{
|
|
id: "asset-rejected",
|
|
article_id: "article-1",
|
|
section_id: "section-1",
|
|
asset_type: "diagram",
|
|
title: "Rejected visual",
|
|
prompt: "diagram prompt",
|
|
object_key: "articles/article-1/assets/asset-rejected/r1/rejected.png",
|
|
file_url: "file:///tmp/rejected.png",
|
|
alt_text: "Rejected visual",
|
|
caption: "Do not publish",
|
|
status: "REJECTED",
|
|
history: [],
|
|
created_at: "2026-05-21T00:00:01Z",
|
|
updated_at: "2026-05-21T00:00:01Z",
|
|
},
|
|
];
|
|
|
|
const rows = buildMediaLibraryRows(assets);
|
|
assert.equal(rows.length, 2);
|
|
assert.equal(rows[0].title, "Hero visual");
|
|
assert.equal(rows[0].publishReady, true);
|
|
assert.equal(rows[1].publishReady, false);
|
|
|
|
const markdown = [
|
|
"## Intro",
|
|
"",
|
|
"",
|
|
"",
|
|
].join("\n");
|
|
const resolved = resolveDraftPreviewMarkdown(markdown, assets);
|
|
assert.ok(resolved.includes("file:///tmp/hero.png"));
|
|
assert.ok(resolved.includes("placeholder://section-1/2"));
|
|
assert.ok(!resolved.includes("file:///tmp/rejected.png"));
|