opportunity-report.test.js 1.5 KB

1234567891011121314151617181920212223242526
  1. import { test } from 'node:test';
  2. import assert from 'node:assert/strict';
  3. import { opportunityReportArtifact, opportunitiesForReport, reportOpportunity } from '../src/core/opportunity/report.js';
  4. const structured = { id:'report', report:{ chapters:[{ sections:[{kind:'para',text:'已保存的报告正文'}] }] } };
  5. const text = { id:'text', rawText:'已保存的来源原文,保留原有内容,不补造分析。' };
  6. const empty = { id:'empty', title:'只有标题' };
  7. const o1 = { id:'o1', linkedArtifactIds:['missing','empty','text','report'] };
  8. const o2 = { id:'o2', linkedArtifactIds:['report'] };
  9. const db = { artifactById:{ report:structured,text,empty }, opportunities:[o1,o2], opportunityById:{o1,o2} };
  10. test('机会报告只按显式关系找正文,优先结构化报告,再用已保存原文', () => {
  11. assert.equal(opportunityReportArtifact(db,'o1'),structured);
  12. assert.equal(opportunityReportArtifact({...db,artifactById:{text,empty}},'o1'),text);
  13. assert.equal(opportunityReportArtifact({...db,artifactById:{empty}},'o1'),null);
  14. assert.equal(opportunityReportArtifact(db,'不存在'),null);
  15. });
  16. test('共用报告必须明确评分对象,错误绑定不能误落到另一张机会卡', () => {
  17. assert.deepEqual(opportunitiesForReport(db,'report'),[o1,o2]);
  18. assert.equal(reportOpportunity(db,'report'),null);
  19. assert.equal(reportOpportunity(db,'report','o2'),o2);
  20. assert.equal(reportOpportunity(db,'text'),o1);
  21. assert.equal(reportOpportunity(db,'text','o2'),null);
  22. assert.deepEqual(opportunitiesForReport(db,'missing'),[]);
  23. });