@talkpilot/core-db 1.3.0 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -30
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +10 -0
- package/dist/connection.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/municipal/tickets/index.d.ts +1 -2
- package/dist/municipal/tickets/index.d.ts.map +1 -1
- package/dist/municipal/tickets/index.js +0 -1
- package/dist/municipal/tickets/index.js.map +1 -1
- package/dist/municipal/tickets/tickets.getters.d.ts +11 -0
- package/dist/municipal/tickets/tickets.getters.d.ts.map +1 -1
- package/dist/municipal/tickets/tickets.getters.js +128 -0
- package/dist/municipal/tickets/tickets.getters.js.map +1 -1
- package/dist/municipal/tickets/tickets.types.d.ts +5 -10
- package/dist/municipal/tickets/tickets.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.types.d.ts +2 -1
- package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.types.js +3 -0
- package/dist/talkpilot/calls/calls.types.js.map +1 -1
- package/dist/talkpilot/calls/dashboard/calls.dashboard.d.ts +1 -33
- package/dist/talkpilot/calls/dashboard/calls.dashboard.d.ts.map +1 -1
- package/dist/talkpilot/calls/dashboard/calls.dashboard.js +146 -131
- package/dist/talkpilot/calls/dashboard/calls.dashboard.js.map +1 -1
- package/dist/talkpilot/calls/dashboard/calls.dashboard.types.d.ts +6 -27
- package/dist/talkpilot/calls/dashboard/calls.dashboard.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/index.d.ts +0 -3
- package/dist/talkpilot/calls/index.d.ts.map +1 -1
- package/dist/talkpilot/calls/index.js +0 -3
- package/dist/talkpilot/calls/index.js.map +1 -1
- package/dist/test-utils/db-utils.d.ts.map +1 -1
- package/dist/test-utils/db-utils.js +2 -0
- package/dist/test-utils/db-utils.js.map +1 -1
- package/dist/test-utils/factories/index.d.ts +1 -0
- package/dist/test-utils/factories/index.d.ts.map +1 -1
- package/dist/test-utils/factories/index.js +1 -0
- package/dist/test-utils/factories/index.js.map +1 -1
- package/dist/test-utils/factories/websitalk/scans.d.ts +5 -0
- package/dist/test-utils/factories/websitalk/scans.d.ts.map +1 -0
- package/dist/test-utils/factories/websitalk/scans.js +25 -0
- package/dist/test-utils/factories/websitalk/scans.js.map +1 -0
- package/dist/websitalk/index.d.ts +7 -0
- package/dist/websitalk/index.d.ts.map +1 -0
- package/dist/websitalk/index.js +34 -0
- package/dist/websitalk/index.js.map +1 -0
- package/dist/websitalk/mongodb-client.d.ts +13 -0
- package/dist/websitalk/mongodb-client.d.ts.map +1 -0
- package/dist/websitalk/mongodb-client.js +56 -0
- package/dist/websitalk/mongodb-client.js.map +1 -0
- package/dist/websitalk/scans/index.d.ts +3 -0
- package/dist/websitalk/scans/index.d.ts.map +1 -0
- package/dist/websitalk/scans/index.js +19 -0
- package/dist/websitalk/scans/index.js.map +1 -0
- package/dist/websitalk/scans/scans.getters.d.ts +12 -0
- package/dist/websitalk/scans/scans.getters.d.ts.map +1 -0
- package/dist/websitalk/scans/scans.getters.js +74 -0
- package/dist/websitalk/scans/scans.getters.js.map +1 -0
- package/dist/websitalk/scans/scans.types.d.ts +45 -0
- package/dist/websitalk/scans/scans.types.d.ts.map +1 -0
- package/dist/{talkpilot/calls/calls.statistics.types.js → websitalk/scans/scans.types.js} +1 -1
- package/dist/websitalk/scans/scans.types.js.map +1 -0
- package/package.json +1 -1
- package/src/connection.ts +12 -0
- package/src/index.ts +9 -0
- package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +37 -1
- package/src/municipal/tickets/index.ts +1 -2
- package/src/municipal/tickets/tickets.getters.ts +140 -0
- package/src/municipal/tickets/tickets.types.ts +9 -14
- package/src/talkpilot/calls/__tests__/calls.dashboard.spec.ts +111 -8
- package/src/talkpilot/calls/calls.types.ts +2 -4
- package/src/talkpilot/calls/dashboard/calls.dashboard.ts +197 -148
- package/src/talkpilot/calls/dashboard/calls.dashboard.types.ts +12 -25
- package/src/talkpilot/calls/index.ts +0 -3
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +0 -7
- package/src/test-utils/db-utils.ts +3 -1
- package/src/test-utils/factories/index.ts +1 -0
- package/src/test-utils/factories/websitalk/scans.ts +23 -0
- package/src/websitalk/index.ts +15 -0
- package/src/websitalk/mongodb-client.ts +61 -0
- package/src/websitalk/scans/__tests__/scans.spec.ts +218 -0
- package/src/websitalk/scans/index.ts +2 -0
- package/src/websitalk/scans/scans.getters.ts +113 -0
- package/src/websitalk/scans/scans.types.ts +53 -0
- package/dist/municipal/tickets/tickets.constants.d.ts +0 -7
- package/dist/municipal/tickets/tickets.constants.d.ts.map +0 -1
- package/dist/municipal/tickets/tickets.constants.js +0 -10
- package/dist/municipal/tickets/tickets.constants.js.map +0 -1
- package/dist/municipal/tickets/tickets.deprecated.getters.d.ts +0 -12
- package/dist/municipal/tickets/tickets.deprecated.getters.d.ts.map +0 -1
- package/dist/municipal/tickets/tickets.deprecated.getters.js +0 -131
- package/dist/municipal/tickets/tickets.deprecated.getters.js.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts +0 -45
- package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.aggregation.js +0 -98
- package/dist/municipal/tickets/tickets.statistics.aggregation.js.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.dates.d.ts +0 -7
- package/dist/municipal/tickets/tickets.statistics.dates.d.ts.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.dates.js +0 -40
- package/dist/municipal/tickets/tickets.statistics.dates.js.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.getters.d.ts +0 -9
- package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.getters.js +0 -55
- package/dist/municipal/tickets/tickets.statistics.getters.js.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts +0 -53
- package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.pipeline.js +0 -112
- package/dist/municipal/tickets/tickets.statistics.pipeline.js.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.utils.d.ts +0 -7
- package/dist/municipal/tickets/tickets.statistics.utils.d.ts.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.utils.js +0 -40
- package/dist/municipal/tickets/tickets.statistics.utils.js.map +0 -1
- package/dist/talkpilot/calls/calls.constants.d.ts +0 -17
- package/dist/talkpilot/calls/calls.constants.d.ts.map +0 -1
- package/dist/talkpilot/calls/calls.constants.js +0 -20
- package/dist/talkpilot/calls/calls.constants.js.map +0 -1
- package/dist/talkpilot/calls/calls.statistics.getters.d.ts +0 -19
- package/dist/talkpilot/calls/calls.statistics.getters.d.ts.map +0 -1
- package/dist/talkpilot/calls/calls.statistics.getters.js +0 -375
- package/dist/talkpilot/calls/calls.statistics.getters.js.map +0 -1
- package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts +0 -12
- package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts.map +0 -1
- package/dist/talkpilot/calls/calls.statistics.ticketScope.js +0 -37
- package/dist/talkpilot/calls/calls.statistics.ticketScope.js.map +0 -1
- package/dist/talkpilot/calls/calls.statistics.tickets.d.ts +0 -17
- package/dist/talkpilot/calls/calls.statistics.tickets.d.ts.map +0 -1
- package/dist/talkpilot/calls/calls.statistics.tickets.js +0 -33
- package/dist/talkpilot/calls/calls.statistics.tickets.js.map +0 -1
- package/dist/talkpilot/calls/calls.statistics.types.d.ts +0 -39
- package/dist/talkpilot/calls/calls.statistics.types.d.ts.map +0 -1
- package/dist/talkpilot/calls/calls.statistics.types.js.map +0 -1
- package/dist/utils/date.utils.d.ts +0 -49
- package/dist/utils/date.utils.d.ts.map +0 -1
- package/dist/utils/date.utils.js +0 -103
- package/dist/utils/date.utils.js.map +0 -1
- package/dist/utils/statistics.aggregation.d.ts +0 -20
- package/dist/utils/statistics.aggregation.d.ts.map +0 -1
- package/dist/utils/statistics.aggregation.js +0 -43
- package/dist/utils/statistics.aggregation.js.map +0 -1
- package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +0 -104
- package/src/municipal/tickets/tickets.constants.ts +0 -8
- package/src/municipal/tickets/tickets.statistics.aggregation.ts +0 -113
- package/src/municipal/tickets/tickets.statistics.getters.ts +0 -93
- package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +0 -281
- package/src/talkpilot/calls/calls.constants.ts +0 -20
- package/src/talkpilot/calls/calls.statistics.getters.ts +0 -525
- package/src/talkpilot/calls/calls.statistics.types.ts +0 -44
- package/src/utils/date.utils.ts +0 -116
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
aggregateCallsHourlyByRange,
|
|
3
|
-
aggregateCallsRouting,
|
|
4
|
-
aggregateCallsSummary,
|
|
5
|
-
aggregateCallsTrend,
|
|
6
|
-
findCallSidsWithDraftTicketsByCity,
|
|
7
|
-
findCallSidsWithTicketsByCity,
|
|
8
|
-
getCallsCollection,
|
|
9
|
-
getDepartmentsSubjectsCollection,
|
|
10
|
-
getTicketsCollection,
|
|
11
|
-
findSubjectsByCallSids,
|
|
12
|
-
rangeDurationDays,
|
|
13
|
-
rangeDurationMonths,
|
|
14
|
-
resolveTimeBucketFromRange,
|
|
15
|
-
ticketStatsDateScopeFromYmd,
|
|
16
|
-
} from "../../../index";
|
|
17
|
-
import type { Call } from "../calls.types";
|
|
18
|
-
import type { CallsStatsFilter } from "../calls.statistics.types";
|
|
19
|
-
import {
|
|
20
|
-
createDepartmentSubject,
|
|
21
|
-
createIncomingCallDoc,
|
|
22
|
-
createOutGoingCallDoc,
|
|
23
|
-
createTicket,
|
|
24
|
-
} from "../../../test-utils/factories";
|
|
25
|
-
const CLIENT_ID = "stats-client";
|
|
26
|
-
const CITY = "tests" as const;
|
|
27
|
-
const TZ = "Asia/Jerusalem";
|
|
28
|
-
const at = (iso: string) => new Date(iso);
|
|
29
|
-
|
|
30
|
-
const insertCall = (call: Call) =>
|
|
31
|
-
getCallsCollection().insertOne({ ...call, env: call.env ?? "test" });
|
|
32
|
-
|
|
33
|
-
const incoming = (callSid: string, createdAt: string, extra?: Partial<Call>) =>
|
|
34
|
-
insertCall(
|
|
35
|
-
createIncomingCallDoc({
|
|
36
|
-
clientId: CLIENT_ID,
|
|
37
|
-
callSid,
|
|
38
|
-
createdAt: at(createdAt),
|
|
39
|
-
updatedAt: at(extra?.updatedAt?.toISOString() ?? createdAt),
|
|
40
|
-
...extra,
|
|
41
|
-
}),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const filter = (overrides?: Partial<CallsStatsFilter>): CallsStatsFilter => ({
|
|
45
|
-
clientId: CLIENT_ID,
|
|
46
|
-
startStr: "2026-05-01",
|
|
47
|
-
endStr: "2026-05-31",
|
|
48
|
-
timezone: TZ,
|
|
49
|
-
callSidsWithTickets: [],
|
|
50
|
-
callSidsWithDraftTickets: [],
|
|
51
|
-
...overrides,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const ticketDateScope = (statsFilter: CallsStatsFilter) =>
|
|
55
|
-
ticketStatsDateScopeFromYmd(statsFilter.startStr, statsFilter.endStr, statsFilter.timezone);
|
|
56
|
-
|
|
57
|
-
const summaryWithTicketSids = async (overrides?: Partial<CallsStatsFilter>) => {
|
|
58
|
-
const statsFilter = filter(overrides);
|
|
59
|
-
const dateScope = ticketDateScope(statsFilter);
|
|
60
|
-
const callSidsWithTickets = await findCallSidsWithTicketsByCity(CITY, dateScope);
|
|
61
|
-
const callSidsWithDraftTickets = await findCallSidsWithDraftTicketsByCity(CITY, dateScope);
|
|
62
|
-
return aggregateCallsSummary(filter({ callSidsWithTickets, callSidsWithDraftTickets, ...overrides }));
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
describe("calls statistics getters", () => {
|
|
66
|
-
beforeEach(async () => {
|
|
67
|
-
await incoming("CA-with-ticket", "2026-05-10T10:00:00.000Z", {
|
|
68
|
-
callLength: 120,
|
|
69
|
-
updatedAt: at("2026-05-10T10:02:00.000Z"),
|
|
70
|
-
});
|
|
71
|
-
await incoming("CA-transferred", "2026-05-11T14:00:00.000Z", {
|
|
72
|
-
callLength: 60,
|
|
73
|
-
redirectedCall: true,
|
|
74
|
-
updatedAt: at("2026-05-11T14:01:00.000Z"),
|
|
75
|
-
});
|
|
76
|
-
await incoming("CA-hijacked", "2026-05-12T09:00:00.000Z", {
|
|
77
|
-
callLength: 90,
|
|
78
|
-
isConferenceCall: true,
|
|
79
|
-
redirectedCall: false,
|
|
80
|
-
updatedAt: at("2026-05-12T09:01:30.000Z"),
|
|
81
|
-
});
|
|
82
|
-
await insertCall(
|
|
83
|
-
createOutGoingCallDoc({
|
|
84
|
-
clientId: CLIENT_ID,
|
|
85
|
-
callSid: "CA-outgoing",
|
|
86
|
-
createdAt: at("2026-05-10T11:00:00.000Z"),
|
|
87
|
-
updatedAt: at("2026-05-10T11:01:00.000Z"),
|
|
88
|
-
}),
|
|
89
|
-
);
|
|
90
|
-
await getTicketsCollection().insertOne(
|
|
91
|
-
createTicket({
|
|
92
|
-
cityName: CITY,
|
|
93
|
-
callSid: "CA-with-ticket",
|
|
94
|
-
createdAt: at("2026-05-10T10:00:00.000Z"),
|
|
95
|
-
updatedAt: at("2026-05-10T10:00:00.000Z"),
|
|
96
|
-
externalCallFields: { event_subject_id: "100" },
|
|
97
|
-
}),
|
|
98
|
-
);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("should exclude calls outside the filter date range from summary", async () => {
|
|
102
|
-
await incoming("CA-old", "2024-01-01T10:00:00.000Z", { callLength: 999 });
|
|
103
|
-
const summary = await aggregateCallsSummary(filter());
|
|
104
|
-
expect(summary).toMatchObject({ totalCalls: 3, avgDurationSeconds: 90 });
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("should aggregate summary with ticket sids and opened-ticket filter", async () => {
|
|
108
|
-
expect(await summaryWithTicketSids()).toEqual({
|
|
109
|
-
totalCalls: 3,
|
|
110
|
-
openTickets: 1,
|
|
111
|
-
draftTickets: 0,
|
|
112
|
-
avgDurationSeconds: 90,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const statsFilter = filter();
|
|
116
|
-
const callSidsWithTickets = await findCallSidsWithTicketsByCity(CITY, ticketDateScope(statsFilter));
|
|
117
|
-
const openedOnly = await aggregateCallsSummary(
|
|
118
|
-
filter({ callSidsWithTickets, ticketStatusFilters: ["opened"] }),
|
|
119
|
-
);
|
|
120
|
-
expect(openedOnly).toMatchObject({ totalCalls: 1, openTickets: 1 });
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should classify routing into mutually exclusive buckets", async () => {
|
|
124
|
-
expect(await aggregateCallsRouting(filter())).toEqual({
|
|
125
|
-
transferred: 1,
|
|
126
|
-
hijacked: 1,
|
|
127
|
-
aiHandled: 1,
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("should resolve subjects by callSid with optional limit", async () => {
|
|
132
|
-
await getDepartmentsSubjectsCollection().insertOne(
|
|
133
|
-
createDepartmentSubject({ cityName: CITY, subject_id: "100", subjectName: "Water" }),
|
|
134
|
-
);
|
|
135
|
-
expect(await findSubjectsByCallSids(CITY, ["CA-with-ticket"])).toEqual([
|
|
136
|
-
{ subject: "Water", count: 1 },
|
|
137
|
-
]);
|
|
138
|
-
|
|
139
|
-
await getDepartmentsSubjectsCollection().insertMany([
|
|
140
|
-
createDepartmentSubject({ cityName: CITY, subject_id: "200", subjectName: "Roads" }),
|
|
141
|
-
createDepartmentSubject({ cityName: CITY, subject_id: "300", subjectName: "Lighting" }),
|
|
142
|
-
]);
|
|
143
|
-
await getTicketsCollection().insertMany([
|
|
144
|
-
createTicket({ cityName: CITY, callSid: "CA-subject-1", externalCallFields: { event_subject_id: "200" } }),
|
|
145
|
-
createTicket({ cityName: CITY, callSid: "CA-subject-2", externalCallFields: { event_subject_id: "300" } }),
|
|
146
|
-
]);
|
|
147
|
-
const sids = ["CA-subject-1", "CA-subject-2"];
|
|
148
|
-
expect(await findSubjectsByCallSids(CITY, sids)).toHaveLength(2);
|
|
149
|
-
expect(await findSubjectsByCallSids(CITY, sids, 1)).toHaveLength(1);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("should aggregate hourly buckets with averages and optional hour window", async () => {
|
|
153
|
-
const statsFilter = filter();
|
|
154
|
-
const daysInRange = rangeDurationDays(statsFilter.startStr, statsFilter.endStr);
|
|
155
|
-
const full = await aggregateCallsHourlyByRange(statsFilter);
|
|
156
|
-
|
|
157
|
-
expect(full).toHaveLength(24);
|
|
158
|
-
expect(full[0]).toEqual({ hour: 0, totalCalls: 0, avgCalls: 0 });
|
|
159
|
-
expect(full.reduce((sum, h) => sum + h.totalCalls, 0)).toBe(3);
|
|
160
|
-
expect(full.find((h) => h.hour === 12)).toEqual({
|
|
161
|
-
hour: 12,
|
|
162
|
-
totalCalls: 1,
|
|
163
|
-
avgCalls: Math.round((1 / daysInRange) * 10) / 10,
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
expect(
|
|
167
|
-
(await aggregateCallsHourlyByRange(filter({ startStr: "2026-05-12", endStr: "2026-05-12" }))).find(
|
|
168
|
-
(h) => h.hour === 12,
|
|
169
|
-
),
|
|
170
|
-
).toEqual({ hour: 12, totalCalls: 1, avgCalls: 1 });
|
|
171
|
-
|
|
172
|
-
const avgForOneCall = Math.round((1 / daysInRange) * 10) / 10;
|
|
173
|
-
expect(await aggregateCallsHourlyByRange(filter({ hourFrom: 10, hourTo: 12 }))).toEqual([
|
|
174
|
-
{ hour: 10, totalCalls: 0, avgCalls: 0 },
|
|
175
|
-
{ hour: 11, totalCalls: 0, avgCalls: 0 },
|
|
176
|
-
{ hour: 12, totalCalls: 1, avgCalls: avgForOneCall },
|
|
177
|
-
]);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("should fill day trend buckets with zeros", async () => {
|
|
181
|
-
expect(await aggregateCallsTrend(filter({ startStr: "2026-05-10", endStr: "2026-05-14" }), "day")).toEqual([
|
|
182
|
-
{ bucket: "2026-05-10", totalCalls: 1, openTickets: 0 },
|
|
183
|
-
{ bucket: "2026-05-11", totalCalls: 1, openTickets: 0 },
|
|
184
|
-
{ bucket: "2026-05-12", totalCalls: 1, openTickets: 0 },
|
|
185
|
-
{ bucket: "2026-05-13", totalCalls: 0, openTickets: 0 },
|
|
186
|
-
{ bucket: "2026-05-14", totalCalls: 0, openTickets: 0 },
|
|
187
|
-
]);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("should bucket calls by calendar day in filter timezone", async () => {
|
|
191
|
-
await incoming("CA-jerusalem-midnight", "2026-05-09T21:00:00.000Z", { callLength: 45 });
|
|
192
|
-
expect(await aggregateCallsTrend(filter({ startStr: "2026-05-10", endStr: "2026-05-12" }), "day")).toEqual([
|
|
193
|
-
{ bucket: "2026-05-10", totalCalls: 2, openTickets: 0 },
|
|
194
|
-
{ bucket: "2026-05-11", totalCalls: 1, openTickets: 0 },
|
|
195
|
-
{ bucket: "2026-05-12", totalCalls: 1, openTickets: 0 },
|
|
196
|
-
]);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it("should pick month, week, or day bucket from calendar-month span", () => {
|
|
200
|
-
expect(rangeDurationMonths("2025-06-01", "2026-05-31")).toBe(12);
|
|
201
|
-
expect(resolveTimeBucketFromRange("2025-06-01", "2026-05-31")).toBe("month");
|
|
202
|
-
expect(resolveTimeBucketFromRange("2026-01-01", "2026-06-30")).toBe("week");
|
|
203
|
-
expect(resolveTimeBucketFromRange("2026-04-01", "2026-06-30")).toBe("day");
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it("should fill month trend buckets with zeros", async () => {
|
|
207
|
-
await incoming("CA-feb", "2026-02-15T10:00:00.000Z");
|
|
208
|
-
await incoming("CA-apr", "2026-04-15T10:00:00.000Z");
|
|
209
|
-
const month = await aggregateCallsTrend(filter({ startStr: "2026-01-01", endStr: "2026-06-30" }), "month");
|
|
210
|
-
expect(month.map((row) => row.bucket)).toEqual([
|
|
211
|
-
"2026-01-01",
|
|
212
|
-
"2026-02-01",
|
|
213
|
-
"2026-03-01",
|
|
214
|
-
"2026-04-01",
|
|
215
|
-
"2026-05-01",
|
|
216
|
-
"2026-06-01",
|
|
217
|
-
]);
|
|
218
|
-
expect(month.find((row) => row.bucket === "2026-02-01")).toMatchObject({ totalCalls: 1, openTickets: 0 });
|
|
219
|
-
expect(month.find((row) => row.bucket === "2026-05-01")).toMatchObject({ totalCalls: 3, openTickets: 0 });
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it("should fill week trend buckets with zeros", async () => {
|
|
223
|
-
await incoming("CA-week-2", "2026-05-18T10:00:00.000Z");
|
|
224
|
-
expect(
|
|
225
|
-
await aggregateCallsTrend(filter({ startStr: "2026-05-04", endStr: "2026-05-24" }), "week"),
|
|
226
|
-
).toEqual([
|
|
227
|
-
{ bucket: "2026-05-04/2026-05-09", totalCalls: 0, openTickets: 0 },
|
|
228
|
-
{ bucket: "2026-05-10/2026-05-16", totalCalls: 3, openTickets: 0 },
|
|
229
|
-
{ bucket: "2026-05-17/2026-05-23", totalCalls: 1, openTickets: 0 },
|
|
230
|
-
{ bucket: "2026-05-24/2026-05-24", totalCalls: 0, openTickets: 0 },
|
|
231
|
-
]);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it("should complete every day bucket across a 12-month range without hanging (DST regression)", async () => {
|
|
235
|
-
const startStr = "2025-07-02";
|
|
236
|
-
const endStr = "2026-06-02";
|
|
237
|
-
const startedAt = Date.now();
|
|
238
|
-
const trend = await aggregateCallsTrend(filter({ startStr, endStr }), "day");
|
|
239
|
-
const elapsedMs = Date.now() - startedAt;
|
|
240
|
-
|
|
241
|
-
expect(trend).toHaveLength(rangeDurationDays(startStr, endStr));
|
|
242
|
-
expect(trend[0]).toEqual({ bucket: startStr, totalCalls: 0, openTickets: 0 });
|
|
243
|
-
expect(trend[trend.length - 1].bucket).toBe(endStr);
|
|
244
|
-
expect(elapsedMs).toBeLessThan(5000);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it("should count draft tickets and distinct draft call sids", async () => {
|
|
248
|
-
const descriptionDraft = createTicket({
|
|
249
|
-
cityName: CITY,
|
|
250
|
-
callSid: "CA-hijacked",
|
|
251
|
-
createdAt: at("2026-05-12T09:00:00.000Z"),
|
|
252
|
-
updatedAt: at("2026-05-12T09:00:00.000Z"),
|
|
253
|
-
});
|
|
254
|
-
descriptionDraft.externalCallFields = { event_description: "draft ticket" };
|
|
255
|
-
await getTicketsCollection().insertMany([
|
|
256
|
-
createTicket({
|
|
257
|
-
cityName: CITY,
|
|
258
|
-
callSid: "CA-transferred",
|
|
259
|
-
createdAt: at("2026-05-11T14:00:00.000Z"),
|
|
260
|
-
updatedAt: at("2026-05-11T14:00:00.000Z"),
|
|
261
|
-
externalCallFields: { event_subject_id: "100" },
|
|
262
|
-
}),
|
|
263
|
-
descriptionDraft,
|
|
264
|
-
createTicket({
|
|
265
|
-
cityName: CITY,
|
|
266
|
-
callSid: "CA-whitespace-draft",
|
|
267
|
-
createdAt: at("2026-05-12T10:00:00.000Z"),
|
|
268
|
-
updatedAt: at("2026-05-12T10:00:00.000Z"),
|
|
269
|
-
externalCallFields: { event_subject_id: " " },
|
|
270
|
-
}),
|
|
271
|
-
]);
|
|
272
|
-
|
|
273
|
-
const statsFilter = filter();
|
|
274
|
-
const dateScope = ticketDateScope(statsFilter);
|
|
275
|
-
const callSidsWithDraftTickets = await findCallSidsWithDraftTicketsByCity(CITY, dateScope);
|
|
276
|
-
const summary = await summaryWithTicketSids();
|
|
277
|
-
|
|
278
|
-
expect(callSidsWithDraftTickets.sort()).toEqual(["CA-hijacked", "CA-whitespace-draft"].sort());
|
|
279
|
-
expect(summary).toMatchObject({ openTickets: 3, draftTickets: 1 });
|
|
280
|
-
});
|
|
281
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/** Customer role within a conference call. */
|
|
2
|
-
export const CONFERENCE_ROLE_CUSTOMER = "customer" as const;
|
|
3
|
-
|
|
4
|
-
/** Supervisor role within a conference call. */
|
|
5
|
-
export const CONFERENCE_ROLE_SUPERVISOR = "supervisor" as const;
|
|
6
|
-
|
|
7
|
-
/** Hours in a single day. */
|
|
8
|
-
export const HOURS_PER_DAY = 24;
|
|
9
|
-
|
|
10
|
-
/** Max execution time (ms) for calls statistics aggregations. */
|
|
11
|
-
export const STATS_MAX_TIME_MS = 30_000;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* When the client calls bar chart should group by week or month instead of day:
|
|
15
|
-
* > MONTH threshold -> one bar per month
|
|
16
|
-
* > WEEK threshold -> one bar per week
|
|
17
|
-
* otherwise -> one bar per day
|
|
18
|
-
*/
|
|
19
|
-
export const TREND_MONTH_BUCKET_MIN_MONTHS = 6;
|
|
20
|
-
export const TREND_WEEK_BUCKET_MIN_MONTHS = 3;
|