Add store/email/phone filtering, richer call-line formatting, CDR feed pagination and queueing, and split Jira poller enrichment into testable modules. Co-authored-by: Cursor <cursoragent@cursor.com>
154 lines
4.7 KiB
JavaScript
154 lines
4.7 KiB
JavaScript
// tests/callReport.renderer.test.js
|
|
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { renderCallReportMarkdown } from '../services/renderers/callReportRenderer.js';
|
|
import { CALL_BUCKETS } from '../services/callReport/groupCdrCalls.js';
|
|
|
|
const sampleCall = {
|
|
start: '2026-07-23T13:06:24.316Z',
|
|
duration: 184,
|
|
direction: 'inbound',
|
|
callingLineId: 'WIRELESS CALLER',
|
|
callingNumber: '+17189864017',
|
|
calledNumber: '+12122194600',
|
|
storeMainNumber: '+12122194600',
|
|
finalNumber: '52477',
|
|
model: 'DBS-210-3PC',
|
|
disposition: 'Success',
|
|
outcome: 'Success',
|
|
reachedPhone: true,
|
|
normalOutcome: true,
|
|
abnormal: false,
|
|
legCount: 3,
|
|
wan: { mos: 4.1, jitter: 3.4, loss: 2.4 },
|
|
};
|
|
|
|
test('renderCallReportMarkdown summary and sections', () => {
|
|
const md = renderCallReportMarkdown({
|
|
ok: true,
|
|
store: { storeNum: '782', locationName: 'Store 0782', dialNumber: '+17247795574', kind: 'store' },
|
|
window: {
|
|
label: '2026-07-23',
|
|
mode: 'fullDay',
|
|
timeZone: 'America/New_York',
|
|
startTime: '2026-07-23T13:00:00.000Z',
|
|
endTime: '2026-07-24T01:00:00.000Z',
|
|
},
|
|
cdr: { available: true, rawCount: 10 },
|
|
prisma: {
|
|
available: true,
|
|
appAudio: { appName: 'Webex_Calling_RTP', mos: { min: 2.7, max: 4.41 }, detailsUrl: 'https://example.com' },
|
|
},
|
|
joined: {
|
|
summary: {
|
|
total: 2,
|
|
inbound: 2,
|
|
outbound: 0,
|
|
inboundReachedPhone: 1,
|
|
inboundAaOnly: 0,
|
|
outboundConnected: 0,
|
|
abnormal: 1,
|
|
outcomes: { Success: 1, 'Failed / Busy': 1 },
|
|
},
|
|
buckets: {
|
|
[CALL_BUCKETS.inboundReachedPhone]: [sampleCall],
|
|
[CALL_BUCKETS.inboundAaOnly]: [],
|
|
[CALL_BUCKETS.outboundConnected]: [],
|
|
[CALL_BUCKETS.other]: [],
|
|
},
|
|
abnormalCalls: [{
|
|
...sampleCall,
|
|
abnormal: true,
|
|
normalOutcome: false,
|
|
disposition: 'Failed / Busy',
|
|
wan: { mos: 4.1, jitter: 3.4, loss: 2.4 },
|
|
}],
|
|
},
|
|
elapsedMs: 42,
|
|
});
|
|
assert.match(md, /Call report — Store 782/);
|
|
assert.match(md, /Total calls.*2/);
|
|
assert.match(md, /Inbound — reached a phone/);
|
|
assert.match(md, /\*\*Abnormal outcomes:\*\* 1/);
|
|
assert.doesNotMatch(md, /### Abnormal outcomes/);
|
|
assert.doesNotMatch(md, /Compact index/);
|
|
assert.doesNotMatch(md, /\*\*Scope:\*\*/);
|
|
assert.match(md, /✅ 9:06am/);
|
|
assert.match(md, /WIRELESS CALLER/);
|
|
assert.match(md, /\*\*Worst MOS in window:\*\* 2\.7/);
|
|
assert.match(md, /\*\*Best MOS:\*\* 4\.41/);
|
|
});
|
|
|
|
test('renderCallReportMarkdown shows scoped user header', () => {
|
|
const md = renderCallReportMarkdown({
|
|
ok: true,
|
|
target: {
|
|
kind: 'user',
|
|
label: 'mcqueenj@ae.com',
|
|
email: 'mcqueenj@ae.com',
|
|
storeNum: '782',
|
|
locationName: 'Store 0782',
|
|
dialNumber: '+14123694426',
|
|
filter: { kind: 'user', email: 'mcqueenj@ae.com' },
|
|
},
|
|
store: {
|
|
kind: 'user',
|
|
label: 'mcqueenj@ae.com',
|
|
email: 'mcqueenj@ae.com',
|
|
storeNum: '782',
|
|
locationName: 'Store 0782',
|
|
dialNumber: '+14123694426',
|
|
},
|
|
window: {
|
|
label: '2026-07-23',
|
|
mode: 'fullDay',
|
|
timeZone: 'America/New_York',
|
|
startTime: '2026-07-23T13:00:00.000Z',
|
|
endTime: '2026-07-24T01:00:00.000Z',
|
|
},
|
|
cdr: { available: true, rawCount: 5 },
|
|
prisma: { available: false },
|
|
joined: {
|
|
summary: { total: 0, inbound: 0, outbound: 0, outcomes: {} },
|
|
buckets: {
|
|
[CALL_BUCKETS.inboundReachedPhone]: [],
|
|
[CALL_BUCKETS.inboundAaOnly]: [],
|
|
[CALL_BUCKETS.outboundConnected]: [],
|
|
[CALL_BUCKETS.other]: [],
|
|
},
|
|
abnormalCalls: [],
|
|
},
|
|
elapsedMs: 12,
|
|
});
|
|
assert.match(md, /Call report — mcqueenj@ae\.com/);
|
|
assert.match(md, /\*\*Scope:\*\* user mcqueenj@ae\.com/);
|
|
assert.match(md, /No calls matched scope/);
|
|
});
|
|
|
|
test('renderCallReportMarkdown truncates per section', () => {
|
|
const calls = Array.from({ length: 30 }, (_, i) => ({
|
|
...sampleCall,
|
|
start: `2026-07-23T14:${String(i).padStart(2, '0')}:00.000Z`,
|
|
}));
|
|
const md = renderCallReportMarkdown({
|
|
ok: true,
|
|
store: { storeNum: '782', locationName: 'Store 0782' },
|
|
window: { label: '2026-07-23', mode: 'fullDay', timeZone: 'America/New_York', startTime: 'x', endTime: 'y' },
|
|
cdr: { available: true },
|
|
prisma: { available: false },
|
|
joined: {
|
|
summary: { total: 30, inbound: 30, outbound: 0, outcomes: {} },
|
|
buckets: {
|
|
[CALL_BUCKETS.inboundReachedPhone]: calls,
|
|
[CALL_BUCKETS.inboundAaOnly]: [],
|
|
[CALL_BUCKETS.outboundConnected]: [],
|
|
[CALL_BUCKETS.other]: [],
|
|
},
|
|
abnormalCalls: [],
|
|
},
|
|
elapsedMs: 1,
|
|
});
|
|
assert.match(md, /more in this section/);
|
|
});
|