56 lines
1.8 KiB
JavaScript
56 lines
1.8 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/research-manifest/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 { buildResearchSourceRows } = moduleExports;
|
|
|
|
const rows = buildResearchSourceRows([
|
|
{
|
|
id: "11111111-1111-1111-1111-111111111111",
|
|
article_id: "22222222-2222-2222-2222-222222222222",
|
|
agent_job_id: "33333333-3333-3333-3333-333333333333",
|
|
s3_prefix: "research/article/run",
|
|
created_at: "2026-05-21T00:00:00Z",
|
|
artifacts: [
|
|
{
|
|
artifact_type: "source_section_snapshot",
|
|
source_url: "https://example.com/source",
|
|
object_key: "research/article/run/source-1/section.json",
|
|
content_hash: "abc123",
|
|
metadata: {
|
|
source_title: "Source title",
|
|
domain: "example.com",
|
|
source_type: "primary_reference",
|
|
summary: "Useful source summary",
|
|
retrieved_at: "2026-05-21T00:00:01Z",
|
|
artifact_link: "research/article/run/source-1/section.json",
|
|
},
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
|
|
assert.equal(rows.length, 1);
|
|
assert.equal(rows[0].sourceUrl, "https://example.com/source");
|
|
assert.equal(rows[0].title, "Source title");
|
|
assert.equal(rows[0].domain, "example.com");
|
|
assert.equal(rows[0].type, "primary_reference");
|
|
assert.equal(rows[0].summary, "Useful source summary");
|
|
assert.equal(rows[0].artifactLink, "research/article/run/source-1/section.json");
|