Files
Agentic-AI/scripts/t-dashboard-tool.mjs
T
2026-09-02 09:23:53 +05:30

30 lines
1.4 KiB
JavaScript

/* Does crm_dashboard return the dashboard's own numbers, across every section? */
import dotenv from 'dotenv';
dotenv.config();
process.env.CRM_API_BASE = process.env.CRM_PUBLIC_URL || 'https://crm.wele.in';
const { crmDashboard } = await import('../src/tools/crm/dashboard.tools.js');
const cfg = { configurable: { user: { id: '6a00cefe524bebd27037a968', name: 'Test', role: 'admin' }, runtime: { toolCallCount: 0 } } };
const CASES = [
['leads', 'all_time'], ['leads', 'this_month'], ['marketing', 'this_month'],
['budget', 'this_month'], ['courses', 'this_month'], ['analytics', 'last_7_days'],
['retargeting', 'this_month'], ['meta_analytics', 'this_month'],
];
let pass = 0;
for (const [section, range] of CASES) {
try {
const raw = await crmDashboard.invoke({ section, range }, cfg);
const r = typeof raw === 'string' ? JSON.parse(raw) : raw;
if (r.ok === false) { console.log(`FAIL ${section}/${range}: ${r.error}`); continue; }
const d = r.data ?? r;
const head = d.cards ? JSON.stringify(d.cards) : (d.overview ? JSON.stringify(d.overview).slice(0,150) : Object.keys(d).slice(0,6).join(','));
console.log(`PASS ${section.padEnd(15)} ${range.padEnd(12)} ${d.period?.from}→${d.period?.to}`);
console.log(` ${head.slice(0, 190)}`);
pass++;
} catch (e) { console.log(`FAIL ${section}/${range}: ${e.message.slice(0,120)}`); }
}
console.log(`\n${pass}/${CASES.length} sections working`);
process.exit(0);