collabSupport/tests/callReport.groupCdrCalls.test.js
jmcqueen a25fc08fe2 Rename /voicereport to /callreport with scoped user and phone targets.
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>
2026-07-27 10:10:03 -04:00

106 lines
3.6 KiB
JavaScript

// tests/callReport.groupCdrCalls.test.js
import test from 'node:test';
import assert from 'node:assert/strict';
import {
assignCallBucket,
groupCdrIntoCalls,
summarizeCalls,
classifyCallDirection,
CALL_BUCKETS,
} from '../services/callReport/groupCdrCalls.js';
const SAMPLE_LEGS = [
{
'Answer time': '2026-07-23T13:06:24.325Z',
Answered: 'true',
Direction: 'TERMINATING',
'Calling line ID': 'WIRELESS CALLER',
'Start time': '2026-07-23T13:06:24.316Z',
'Call type': 'SIP_INBOUND',
'Correlation ID': '3c7f5c7c-6f48-40f2-925c-133f6a84dcdb',
Duration: 184,
'Report ID': 'fd1debbf-d2b4-331c-846a-2f2a79de9b08',
'User type': 'AutomatedAttendantVideo',
User: 'Store 2477',
'Called number': '+12122194600',
'Site main number': '+12122194600',
'Calling number': '+17189864017',
'Call outcome': 'Success',
'Call outcome reason': 'Normal',
'Answer indicator': 'Yes',
'Auto Attendant Key Pressed': '1',
},
{
'Answer time': '2026-07-23T13:07:14.337Z',
Answered: 'true',
Direction: 'ORIGINATING',
'Start time': '2026-07-23T13:06:26.570Z',
'Call type': 'SIP_ENTERPRISE',
'Correlation ID': '3c7f5c7c-6f48-40f2-925c-133f6a84dcdb',
Duration: 134,
'Report ID': '9541d7ea-8ced-3d39-a8ef-c2fc5e341700',
'User type': 'AutomatedAttendantVideo',
'Called number': '52477',
'Calling number': '+17189864017',
'Call outcome': 'Success',
'Call outcome reason': 'Normal',
'Answer indicator': 'Yes',
},
{
'Answer time': '2026-07-23T13:07:14.337Z',
Answered: 'true',
Direction: 'TERMINATING',
'Start time': '2026-07-23T13:06:26.739Z',
'Call type': 'SIP_ENTERPRISE',
'Client type': 'WXC_DEVICE',
'Correlation ID': '3c7f5c7c-6f48-40f2-925c-133f6a84dcdb',
Duration: 134,
'Report ID': '829fcf5b-975c-3f5d-9150-af4743232bd3',
'User type': 'User',
User: 'Store 02477',
Model: 'DBS-210-3PC',
'Called number': '52477',
'Calling number': '+17189864017',
'Call outcome': 'Success',
'Call outcome reason': 'Normal',
'Answer indicator': 'Yes',
'Release time': '2026-07-23T13:09:28.784Z',
},
];
test('classifyCallDirection detects inbound from SIP_INBOUND leg', () => {
assert.equal(classifyCallDirection(SAMPLE_LEGS), 'inbound');
});
test('groupCdrIntoCalls collapses legs with same correlation ID', () => {
const calls = groupCdrIntoCalls(SAMPLE_LEGS);
assert.equal(calls.length, 1);
assert.equal(calls[0].legCount, 3);
assert.equal(calls[0].direction, 'inbound');
assert.equal(calls[0].callingNumber, '+17189864017');
assert.equal(calls[0].reachedPhone, true);
assert.equal(calls[0].endpointUser, 'Store 02477');
assert.equal(calls[0].aaKeyPress, '1');
assert.equal(calls[0].callingLineId, 'WIRELESS CALLER');
assert.equal(calls[0].finalNumber, '52477');
assert.equal(calls[0].model, 'DBS-210-3PC');
assert.equal(calls[0].storeMainNumber, '+12122194600');
assert.equal(assignCallBucket(calls[0]), CALL_BUCKETS.inboundReachedPhone);
assert.equal(calls[0].normalOutcome, true);
});
test('summarizeCalls aggregates inbound reach stats', () => {
const calls = groupCdrIntoCalls(SAMPLE_LEGS);
const summary = summarizeCalls(calls);
assert.equal(summary.total, 1);
assert.equal(summary.inbound, 1);
assert.equal(summary.inboundReachedPhone, 1);
assert.equal(summary.abnormal, 0);
});
test('legs without correlation ID stay separate', () => {
const a = { ...SAMPLE_LEGS[0], 'Correlation ID': 'a', 'Report ID': 'r1' };
const b = { ...SAMPLE_LEGS[0], 'Correlation ID': 'b', 'Report ID': 'r2' };
assert.equal(groupCdrIntoCalls([a, b]).length, 2);
});