Groups cdr_feed legs by Correlation ID for call-level summaries, fixes report-column field parsing and Docker proxy routing, and adds /calltest post-call Twilio and CDR enrichment. Co-authored-by: Cursor <cursoragent@cursor.com>
86 lines
2.4 KiB
JavaScript
86 lines
2.4 KiB
JavaScript
// tests/callTest.cdrMatcher.test.js
|
|
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import {
|
|
computeCdrWindow,
|
|
phoneDigits,
|
|
scoreCdrLeg,
|
|
pickBestCdrLeg,
|
|
} from '../services/callTest/cdrMatcher.js';
|
|
|
|
test('phoneDigits normalizes US numbers', () => {
|
|
assert.equal(phoneDigits('+17247795574'), '17247795574');
|
|
assert.equal(phoneDigits('7247795574'), '17247795574');
|
|
});
|
|
|
|
test('computeCdrWindow clamps to 12h and 5min API lag', () => {
|
|
const now = Date.now();
|
|
const session = {
|
|
createdAt: new Date(now - 10 * 60_000).toISOString(),
|
|
events: {
|
|
initiated: new Date(now - 8 * 60_000).toISOString(),
|
|
completed: new Date(now - 6 * 60_000).toISOString(),
|
|
},
|
|
};
|
|
const w = computeCdrWindow(session, 60_000);
|
|
const endMs = new Date(w.endTime).getTime();
|
|
const startMs = new Date(w.startTime).getTime();
|
|
assert.ok(endMs <= now - 5 * 60 * 1000 + 1000);
|
|
assert.ok(startMs < endMs);
|
|
});
|
|
|
|
test('pickBestCdrLeg matches inbound store leg from Twilio', () => {
|
|
const session = {
|
|
dialNumber: '+17247795574',
|
|
durationSec: 75,
|
|
events: { coreStartedAt: '2026-07-23T21:28:09.295Z' },
|
|
};
|
|
const items = [
|
|
{
|
|
direction: 'INBOUND',
|
|
calledNumber: '+17247795574',
|
|
callingNumber: '+15551234567',
|
|
startTime: '2026-07-23T21:28:08.000Z',
|
|
durationSeconds: 74,
|
|
},
|
|
{
|
|
direction: 'OUTBOUND',
|
|
calledNumber: '+19998887777',
|
|
callingNumber: '+17247795574',
|
|
durationSeconds: 10,
|
|
},
|
|
];
|
|
const picked = pickBestCdrLeg(items, session);
|
|
assert.ok(picked);
|
|
assert.equal(picked.leg.calledNumber, '+17247795574');
|
|
assert.ok(picked.score >= 100);
|
|
});
|
|
|
|
test('pickBestCdrLeg matches destination even without caller match', () => {
|
|
const session = {
|
|
dialNumber: '+17247795574',
|
|
events: { initiated: '2026-07-23T21:28:09.295Z' },
|
|
};
|
|
const items = [
|
|
{
|
|
calledNumber: '+17247795574',
|
|
callingNumber: '+19998887777',
|
|
startTime: '2026-07-23T21:28:08.000Z',
|
|
durationSeconds: 77,
|
|
},
|
|
];
|
|
const picked = pickBestCdrLeg(items, session);
|
|
assert.ok(picked);
|
|
assert.equal(picked.leg.calledNumber, '+17247795574');
|
|
});
|
|
|
|
test('scoreCdrLeg returns zero for unrelated destination', () => {
|
|
const session = { dialNumber: '+17247795574', durationSec: 60, events: {} };
|
|
const score = scoreCdrLeg(
|
|
{ direction: 'OUTBOUND', calledNumber: '+19998887777', callingNumber: '+11112223333' },
|
|
session,
|
|
);
|
|
assert.equal(score, 0);
|
|
});
|