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>
116 lines
3.2 KiB
JavaScript
116 lines
3.2 KiB
JavaScript
// tests/callTest.twilioEnrichment.test.js
|
|
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import {
|
|
renderCallTestTwilioDetailsMarkdown,
|
|
renderCallTestTwilioInsightsMarkdown,
|
|
renderCallTestCdrMatchMarkdown,
|
|
} from '../services/renderers/callTestRenderer.js';
|
|
import {
|
|
scheduleTwilioEnrichment,
|
|
_clearTwilioEnrichmentTimersForTests,
|
|
} from '../services/callTest/twilioEnrichment.js';
|
|
import {
|
|
createSession,
|
|
_clearAllSessionsForTests,
|
|
getSession,
|
|
} from '../services/callTest/sessionStore.js';
|
|
|
|
const TEST_ID = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
|
|
|
|
function clearTimers() {
|
|
_clearTwilioEnrichmentTimersForTests();
|
|
}
|
|
|
|
test('renderCallTestTwilioDetailsMarkdown shows call fields', () => {
|
|
const md = renderCallTestTwilioDetailsMarkdown(
|
|
{ testId: TEST_ID, callSid: 'CA123' },
|
|
{
|
|
available: true,
|
|
data: {
|
|
sid: 'CA123',
|
|
status: 'completed',
|
|
duration: 75,
|
|
from: '+15550001111',
|
|
to: '+17247795574',
|
|
price: '-0.0140',
|
|
priceUnit: 'USD',
|
|
},
|
|
},
|
|
);
|
|
assert.match(md, /Twilio details/);
|
|
assert.match(md, /completed/);
|
|
assert.match(md, /75s/);
|
|
});
|
|
|
|
test('renderCallTestTwilioInsightsMarkdown handles unavailable', () => {
|
|
const md = renderCallTestTwilioInsightsMarkdown(
|
|
{ testId: TEST_ID },
|
|
{ available: false, reason: 'not enabled' },
|
|
);
|
|
assert.match(md, /Unavailable/);
|
|
assert.match(md, /Advanced Features/);
|
|
});
|
|
|
|
test('renderCallTestTwilioInsightsMarkdown shows quality highlights', () => {
|
|
const md = renderCallTestTwilioInsightsMarkdown(
|
|
{ testId: TEST_ID },
|
|
{
|
|
available: true,
|
|
summary: { duration: 75, processingState: 'complete' },
|
|
metrics: { highlights: { maxJitter: 12, maxPacketLoss: 0.5, minMos: 4.1 } },
|
|
},
|
|
);
|
|
assert.match(md, /jitter/i);
|
|
assert.match(md, /MOS/);
|
|
});
|
|
|
|
test('renderCallTestCdrMatchMarkdown shows matched leg', () => {
|
|
const md = renderCallTestCdrMatchMarkdown(
|
|
{ testId: TEST_ID },
|
|
{
|
|
available: true,
|
|
location: 'Store 0782',
|
|
rawCount: 3,
|
|
window: { startTime: '2026-07-23T21:00:00.000Z', endTime: '2026-07-23T21:10:00.000Z' },
|
|
match: {
|
|
start: '2026-07-23T21:05:00.000Z',
|
|
direction: 'INBOUND',
|
|
duration: 75,
|
|
status: 'SUCCESS',
|
|
callingNumber: '+15551234567',
|
|
calledNumber: '+17247795574',
|
|
score: 120,
|
|
},
|
|
},
|
|
);
|
|
assert.match(md, /CDR match/);
|
|
assert.match(md, /INBOUND/);
|
|
assert.match(md, /Match score/);
|
|
});
|
|
|
|
test('scheduleTwilioEnrichment is no-op without callSid', () => {
|
|
clearTimers();
|
|
scheduleTwilioEnrichment({ testId: TEST_ID, roomId: 'room-1', config: { twilioEnrich: true } }, async () => {});
|
|
clearTimers();
|
|
});
|
|
|
|
test('scheduleTwilioEnrichment registers timers for valid session', () => {
|
|
_clearAllSessionsForTests();
|
|
clearTimers();
|
|
createSession(TEST_ID, {
|
|
callSid: 'CA555',
|
|
roomId: 'room-1',
|
|
config: {
|
|
twilioEnrich: true,
|
|
twilioDetailsDelayMs: 300_000,
|
|
twilioInsightsDelayMs: 300_000,
|
|
},
|
|
});
|
|
const session = getSession(TEST_ID);
|
|
scheduleTwilioEnrichment(session, async () => {});
|
|
scheduleTwilioEnrichment(session, async () => {});
|
|
clearTimers();
|
|
});
|