@webex/contact-center 3.9.0 → 3.10.0-next.2
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/dist/cc.js +196 -47
- package/dist/cc.js.map +1 -1
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/logger-proxy.js +24 -1
- package/dist/logger-proxy.js.map +1 -1
- package/dist/metrics/MetricsManager.js +1 -1
- package/dist/metrics/MetricsManager.js.map +1 -1
- package/dist/metrics/behavioral-events.js +89 -0
- package/dist/metrics/behavioral-events.js.map +1 -1
- package/dist/metrics/constants.js +32 -2
- package/dist/metrics/constants.js.map +1 -1
- package/dist/services/AddressBook.js +271 -0
- package/dist/services/AddressBook.js.map +1 -0
- package/dist/services/EntryPoint.js +227 -0
- package/dist/services/EntryPoint.js.map +1 -0
- package/dist/services/Queue.js +261 -0
- package/dist/services/Queue.js.map +1 -0
- package/dist/services/config/constants.js +36 -2
- package/dist/services/config/constants.js.map +1 -1
- package/dist/services/config/index.js +29 -21
- package/dist/services/config/index.js.map +1 -1
- package/dist/services/config/types.js +33 -1
- package/dist/services/config/types.js.map +1 -1
- package/dist/services/core/GlobalTypes.js.map +1 -1
- package/dist/services/core/Utils.js +162 -2
- package/dist/services/core/Utils.js.map +1 -1
- package/dist/services/core/aqm-reqs.js +0 -4
- package/dist/services/core/aqm-reqs.js.map +1 -1
- package/dist/services/core/websocket/WebSocketManager.js +0 -4
- package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
- package/dist/services/task/TaskManager.js +114 -3
- package/dist/services/task/TaskManager.js.map +1 -1
- package/dist/services/task/TaskUtils.js +76 -0
- package/dist/services/task/TaskUtils.js.map +1 -0
- package/dist/services/task/constants.js +26 -1
- package/dist/services/task/constants.js.map +1 -1
- package/dist/services/task/contact.js +86 -0
- package/dist/services/task/contact.js.map +1 -1
- package/dist/services/task/index.js +418 -87
- package/dist/services/task/index.js.map +1 -1
- package/dist/services/task/types.js +14 -0
- package/dist/services/task/types.js.map +1 -1
- package/dist/types/cc.d.ts +115 -35
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/metrics/constants.d.ts +25 -1
- package/dist/types/services/AddressBook.d.ts +74 -0
- package/dist/types/services/EntryPoint.d.ts +67 -0
- package/dist/types/services/Queue.d.ts +76 -0
- package/dist/types/services/config/constants.d.ts +35 -1
- package/dist/types/services/config/index.d.ts +6 -9
- package/dist/types/services/config/types.d.ts +79 -58
- package/dist/types/services/core/GlobalTypes.d.ts +25 -0
- package/dist/types/services/core/Utils.d.ts +40 -1
- package/dist/types/services/task/TaskUtils.d.ts +28 -0
- package/dist/types/services/task/constants.d.ts +23 -0
- package/dist/types/services/task/contact.d.ts +10 -0
- package/dist/types/services/task/index.d.ts +85 -4
- package/dist/types/services/task/types.d.ts +233 -21
- package/dist/types/types.d.ts +162 -0
- package/dist/types/utils/PageCache.d.ts +173 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/PageCache.js +192 -0
- package/dist/utils/PageCache.js.map +1 -0
- package/dist/webex.js +1 -1
- package/package.json +10 -9
- package/src/cc.ts +221 -52
- package/src/constants.ts +1 -0
- package/src/index.ts +16 -2
- package/src/logger-proxy.ts +24 -1
- package/src/metrics/MetricsManager.ts +1 -1
- package/src/metrics/behavioral-events.ts +94 -0
- package/src/metrics/constants.ts +37 -1
- package/src/services/AddressBook.ts +291 -0
- package/src/services/EntryPoint.ts +241 -0
- package/src/services/Queue.ts +277 -0
- package/src/services/config/constants.ts +42 -2
- package/src/services/config/index.ts +30 -30
- package/src/services/config/types.ts +59 -58
- package/src/services/core/GlobalTypes.ts +27 -0
- package/src/services/core/Utils.ts +199 -1
- package/src/services/core/aqm-reqs.ts +0 -5
- package/src/services/core/websocket/WebSocketManager.ts +0 -4
- package/src/services/task/TaskManager.ts +123 -5
- package/src/services/task/TaskUtils.ts +81 -0
- package/src/services/task/constants.ts +25 -0
- package/src/services/task/contact.ts +80 -0
- package/src/services/task/index.ts +510 -71
- package/src/services/task/types.ts +251 -20
- package/src/types.ts +180 -0
- package/src/utils/PageCache.ts +252 -0
- package/test/unit/spec/cc.ts +282 -85
- package/test/unit/spec/metrics/MetricsManager.ts +0 -1
- package/test/unit/spec/metrics/behavioral-events.ts +42 -0
- package/test/unit/spec/services/AddressBook.ts +332 -0
- package/test/unit/spec/services/EntryPoint.ts +259 -0
- package/test/unit/spec/services/Queue.ts +323 -0
- package/test/unit/spec/services/config/index.ts +279 -65
- package/test/unit/spec/services/core/Utils.ts +50 -0
- package/test/unit/spec/services/core/aqm-reqs.ts +1 -3
- package/test/unit/spec/services/core/websocket/WebSocketManager.ts +0 -4
- package/test/unit/spec/services/task/TaskManager.ts +390 -1
- package/test/unit/spec/services/task/TaskUtils.ts +131 -0
- package/test/unit/spec/services/task/contact.ts +31 -1
- package/test/unit/spec/services/task/index.ts +585 -130
- package/umd/contact-center.min.js +2 -2
- package/umd/contact-center.min.js.map +1 -1
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import LoggerProxy from '../logger-proxy';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Common pagination metadata interface used across all APIs.
|
|
5
|
+
* @public
|
|
6
|
+
* @template T - Additional metadata properties specific to the API
|
|
7
|
+
*/
|
|
8
|
+
export interface PaginationMeta {
|
|
9
|
+
/** Organization ID */
|
|
10
|
+
orgid?: string;
|
|
11
|
+
/** Current page number */
|
|
12
|
+
page?: number;
|
|
13
|
+
/** Page size for current data set */
|
|
14
|
+
pageSize?: number;
|
|
15
|
+
/** Number of pages */
|
|
16
|
+
totalPages?: number;
|
|
17
|
+
/** Total number of items */
|
|
18
|
+
totalRecords?: number;
|
|
19
|
+
/** Total number of items (alias for compatibility) */
|
|
20
|
+
totalItems?: number;
|
|
21
|
+
/** Current page number (alias for compatibility) */
|
|
22
|
+
currentPage?: number;
|
|
23
|
+
/** Map of pagination links */
|
|
24
|
+
links?: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Common paginated response interface used across all APIs.
|
|
29
|
+
* @public
|
|
30
|
+
* @template T - The type of data items in the response
|
|
31
|
+
*/
|
|
32
|
+
export interface PaginatedResponse<T> {
|
|
33
|
+
/** Array of data items */
|
|
34
|
+
data: T[];
|
|
35
|
+
/** Pagination metadata */
|
|
36
|
+
meta: PaginationMeta;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Common search and pagination parameters interface.
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
export interface BaseSearchParams {
|
|
44
|
+
/** Search keyword */
|
|
45
|
+
search?: string;
|
|
46
|
+
/** Filter criteria using RSQL syntax */
|
|
47
|
+
filter?: string;
|
|
48
|
+
/** Attributes to be returned */
|
|
49
|
+
attributes?: string;
|
|
50
|
+
/** Page number (starts from 0) */
|
|
51
|
+
page?: number;
|
|
52
|
+
/** Number of items per page */
|
|
53
|
+
pageSize?: number;
|
|
54
|
+
/** Sort field */
|
|
55
|
+
sortBy?: string;
|
|
56
|
+
/** Sort direction */
|
|
57
|
+
sortOrder?: 'asc' | 'desc';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Default pagination constants used across all APIs.
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export const PAGINATION_DEFAULTS = {
|
|
65
|
+
/** Default page number */
|
|
66
|
+
PAGE: 0,
|
|
67
|
+
/** Default page size */
|
|
68
|
+
PAGE_SIZE: 100,
|
|
69
|
+
} as const;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Interface for cached page entry with metadata
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
export interface PageCacheEntry<T> {
|
|
76
|
+
/** Cached data items for this page */
|
|
77
|
+
data: T[];
|
|
78
|
+
/** Timestamp when this page was cached */
|
|
79
|
+
timestamp: number;
|
|
80
|
+
/** Total metadata if available */
|
|
81
|
+
totalMeta?: {
|
|
82
|
+
totalPages?: number;
|
|
83
|
+
totalRecords?: number;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Interface for cache validation parameters
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
export interface CacheValidationParams {
|
|
92
|
+
/** Search query parameter */
|
|
93
|
+
search?: string;
|
|
94
|
+
/** Filter parameter */
|
|
95
|
+
filter?: string;
|
|
96
|
+
/** Attributes parameter */
|
|
97
|
+
attributes?: string;
|
|
98
|
+
/** Sort by parameter */
|
|
99
|
+
sortBy?: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Default cache TTL in minutes
|
|
104
|
+
*/
|
|
105
|
+
const DEFAULT_CACHE_TTL_MINUTES = 5;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Page cache utility class for managing paginated API response caching.
|
|
109
|
+
* Provides consistent caching behavior across all Contact Center APIs.
|
|
110
|
+
*
|
|
111
|
+
* @class PageCache
|
|
112
|
+
* @public
|
|
113
|
+
* @template T - The type of data items being cached
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* // Create a cache instance for a specific data type
|
|
117
|
+
* const cache = new PageCache<AddressBookEntry>('AddressBook');
|
|
118
|
+
*
|
|
119
|
+
* // Check if we can use cache (no search/filter parameters)
|
|
120
|
+
* if (cache.canUseCache({ search, filter })) {
|
|
121
|
+
* const cacheKey = cache.buildCacheKey(orgId, page, pageSize);
|
|
122
|
+
* const cachedPage = cache.getCachedPage(cacheKey);
|
|
123
|
+
*
|
|
124
|
+
* if (cachedPage) {
|
|
125
|
+
* return cachedPage.data;
|
|
126
|
+
* }
|
|
127
|
+
* }
|
|
128
|
+
*
|
|
129
|
+
* // Cache API response
|
|
130
|
+
* cache.cachePage(cacheKey, responseData, responseMeta);
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export class PageCache<T> {
|
|
134
|
+
private cache: Map<string, PageCacheEntry<T>> = new Map();
|
|
135
|
+
private apiName: string;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Creates an instance of PageCache
|
|
139
|
+
* @param {string} apiName - Name of the API using this cache (for logging)
|
|
140
|
+
* @public
|
|
141
|
+
*/
|
|
142
|
+
constructor(apiName: string) {
|
|
143
|
+
this.apiName = apiName;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Checks if cache can be used for the given parameters.
|
|
148
|
+
* Cache is only used for simple pagination without search/filter/attributes/sort.
|
|
149
|
+
* @param {CacheValidationParams} params - Parameters to validate
|
|
150
|
+
* @returns {boolean} True if cache can be used
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
|
+
public canUseCache(params: CacheValidationParams): boolean {
|
|
154
|
+
const {search, filter, attributes, sortBy} = params;
|
|
155
|
+
|
|
156
|
+
return !search && !filter && !attributes && !sortBy;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Builds a cache key for the given parameters
|
|
161
|
+
* @param {string} orgId - Organization ID
|
|
162
|
+
* @param {number} page - Page number
|
|
163
|
+
* @param {number} pageSize - Page size
|
|
164
|
+
* @returns {string} Cache key
|
|
165
|
+
* @public
|
|
166
|
+
*/
|
|
167
|
+
public buildCacheKey(orgId: string, page: number, pageSize: number): string {
|
|
168
|
+
return `${orgId}:${page}:${pageSize}`;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Gets a cached page if it exists and is valid
|
|
173
|
+
* @param {string} cacheKey - Cache key to look up
|
|
174
|
+
* @returns {PageCacheEntry<T> | null} Cached page entry or null if not found/expired
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
public getCachedPage(cacheKey: string): PageCacheEntry<T> | null {
|
|
178
|
+
const cachedEntry = this.cache.get(cacheKey);
|
|
179
|
+
|
|
180
|
+
if (!cachedEntry) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Check if cache entry is expired
|
|
185
|
+
const now = Date.now();
|
|
186
|
+
const cacheAge = (now - cachedEntry.timestamp) / (1000 * 60); // in minutes
|
|
187
|
+
|
|
188
|
+
if (cacheAge >= DEFAULT_CACHE_TTL_MINUTES) {
|
|
189
|
+
LoggerProxy.log(`Cache entry expired for key: ${cacheKey}`, {
|
|
190
|
+
module: this.apiName,
|
|
191
|
+
method: 'getCachedPage',
|
|
192
|
+
});
|
|
193
|
+
this.cache.delete(cacheKey);
|
|
194
|
+
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return cachedEntry;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Caches a page of data with metadata
|
|
203
|
+
* @param {string} cacheKey - Cache key
|
|
204
|
+
* @param {T[]} data - Data items to cache
|
|
205
|
+
* @param {any} meta - Metadata from API response
|
|
206
|
+
* @public
|
|
207
|
+
*/
|
|
208
|
+
public cachePage(cacheKey: string, data: T[], meta?: any): void {
|
|
209
|
+
const cacheEntry: PageCacheEntry<T> = {
|
|
210
|
+
data,
|
|
211
|
+
timestamp: Date.now(),
|
|
212
|
+
totalMeta: meta
|
|
213
|
+
? {
|
|
214
|
+
totalPages: meta.totalPages,
|
|
215
|
+
totalRecords: meta.totalRecords || meta.totalItems,
|
|
216
|
+
}
|
|
217
|
+
: undefined,
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
this.cache.set(cacheKey, cacheEntry);
|
|
221
|
+
|
|
222
|
+
LoggerProxy.log(`Cached page with ${data.length} items for key: ${cacheKey}`, {
|
|
223
|
+
module: this.apiName,
|
|
224
|
+
method: 'cachePage',
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Clears all cached entries
|
|
230
|
+
* @public
|
|
231
|
+
*/
|
|
232
|
+
public clearCache(): void {
|
|
233
|
+
const cacheSize = this.cache.size;
|
|
234
|
+
this.cache.clear();
|
|
235
|
+
|
|
236
|
+
LoggerProxy.log(`Cleared ${cacheSize} cache entries`, {
|
|
237
|
+
module: this.apiName,
|
|
238
|
+
method: 'clearCache',
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Gets the current number of cached entries
|
|
244
|
+
* @returns {number} Number of cached entries
|
|
245
|
+
* @public
|
|
246
|
+
*/
|
|
247
|
+
public getCacheSize(): number {
|
|
248
|
+
return this.cache.size;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export default PageCache;
|
package/test/unit/spec/cc.ts
CHANGED
|
@@ -7,6 +7,11 @@ import {
|
|
|
7
7
|
WebexSDK,
|
|
8
8
|
} from '../../../src/types';
|
|
9
9
|
import ContactCenter from '../../../src/cc';
|
|
10
|
+
import EntryPoint from '../../../src/services/EntryPoint';
|
|
11
|
+
import type {EntryPointListResponse} from '../../../src/types';
|
|
12
|
+
import AddressBook from '../../../src/services/AddressBook';
|
|
13
|
+
import Queue from '../../../src/services/Queue';
|
|
14
|
+
import type {ContactServiceQueuesResponse} from '../../../src/types';
|
|
10
15
|
import MockWebex from '@webex/test-helper-mock-webex';
|
|
11
16
|
import {StationLoginSuccess, AGENT_EVENTS} from '../../../src/services/agent/types';
|
|
12
17
|
import {SetStateResponse} from '../../../src/types';
|
|
@@ -113,6 +118,7 @@ describe('webex.cc', () => {
|
|
|
113
118
|
},
|
|
114
119
|
config: {
|
|
115
120
|
getAgentConfig: jest.fn(),
|
|
121
|
+
getOutdialAniEntries: jest.fn(),
|
|
116
122
|
},
|
|
117
123
|
webSocketManager: mockWebSocketManager,
|
|
118
124
|
connectionService: {
|
|
@@ -134,6 +140,7 @@ describe('webex.cc', () => {
|
|
|
134
140
|
webSocketManager: mockWebSocketManager,
|
|
135
141
|
task: undefined,
|
|
136
142
|
setWrapupData: jest.fn(),
|
|
143
|
+
setAgentId: jest.fn(),
|
|
137
144
|
registerIncomingCallEvent: jest.fn(),
|
|
138
145
|
registerTaskListeners: jest.fn(),
|
|
139
146
|
getTask: jest.fn(),
|
|
@@ -155,7 +162,7 @@ describe('webex.cc', () => {
|
|
|
155
162
|
};
|
|
156
163
|
|
|
157
164
|
jest.spyOn(MetricsManager, 'getInstance').mockReturnValue(mockMetricsManager);
|
|
158
|
-
jest.spyOn(Services, 'getInstance').mockReturnValue(mockServicesInstance);
|
|
165
|
+
jest.spyOn(Services, 'getInstance').mockReturnValue(mockServicesInstance as any);
|
|
159
166
|
jest.spyOn(TaskManager, 'getTaskManager').mockReturnValue(mockTaskManager);
|
|
160
167
|
jest.spyOn(WebexRequest, 'getInstance').mockReturnValue(mockWebexRequest);
|
|
161
168
|
// Instantiate ContactCenter to ensure it's fully initialized
|
|
@@ -1310,7 +1317,7 @@ describe('webex.cc', () => {
|
|
|
1310
1317
|
});
|
|
1311
1318
|
|
|
1312
1319
|
describe('startOutdial', () => {
|
|
1313
|
-
it('should make outdial call successfully.', async () => {
|
|
1320
|
+
it('should make outdial call successfully without origin.', async () => {
|
|
1314
1321
|
// Setup outDialEp.
|
|
1315
1322
|
webex.cc.agentConfig = {
|
|
1316
1323
|
outDialEp: 'test-entry-point',
|
|
@@ -1319,9 +1326,10 @@ describe('webex.cc', () => {
|
|
|
1319
1326
|
// destination number required for making outdial call.
|
|
1320
1327
|
const destination = '1234567890';
|
|
1321
1328
|
|
|
1322
|
-
// Construct Payload for startOutdial.
|
|
1329
|
+
// Construct Payload for startOutdial without origin.
|
|
1323
1330
|
const newPayload = {
|
|
1324
1331
|
destination,
|
|
1332
|
+
origin: undefined,
|
|
1325
1333
|
entryPointId: 'test-entry-point',
|
|
1326
1334
|
direction: OUTDIAL_DIRECTION,
|
|
1327
1335
|
attributes: ATTRIBUTES,
|
|
@@ -1351,6 +1359,49 @@ describe('webex.cc', () => {
|
|
|
1351
1359
|
expect(result).toEqual(mockResponse);
|
|
1352
1360
|
});
|
|
1353
1361
|
|
|
1362
|
+
it('should make outdial call successfully with origin.', async () => {
|
|
1363
|
+
// Setup outDialEp.
|
|
1364
|
+
webex.cc.agentConfig = {
|
|
1365
|
+
outDialEp: 'test-entry-point',
|
|
1366
|
+
};
|
|
1367
|
+
|
|
1368
|
+
// destination number and origin for making outdial call.
|
|
1369
|
+
const destination = '1234567890';
|
|
1370
|
+
const origin = '+19403016307';
|
|
1371
|
+
|
|
1372
|
+
// Construct Payload for startOutdial with origin.
|
|
1373
|
+
const newPayload = {
|
|
1374
|
+
destination,
|
|
1375
|
+
origin,
|
|
1376
|
+
entryPointId: 'test-entry-point',
|
|
1377
|
+
direction: OUTDIAL_DIRECTION,
|
|
1378
|
+
attributes: ATTRIBUTES,
|
|
1379
|
+
mediaType: OUTDIAL_MEDIA_TYPE,
|
|
1380
|
+
outboundType: OUTBOUND_TYPE,
|
|
1381
|
+
} as const;
|
|
1382
|
+
|
|
1383
|
+
const mockResponse = {} as AgentContact;
|
|
1384
|
+
|
|
1385
|
+
const startOutdialMock = jest
|
|
1386
|
+
.spyOn(webex.cc.services.dialer, 'startOutdial')
|
|
1387
|
+
.mockResolvedValue(mockResponse);
|
|
1388
|
+
|
|
1389
|
+
const result = await webex.cc.startOutdial(destination, origin);
|
|
1390
|
+
|
|
1391
|
+
// Verify logging calls
|
|
1392
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith('Starting outbound dial', {
|
|
1393
|
+
module: CC_FILE,
|
|
1394
|
+
method: 'startOutdial',
|
|
1395
|
+
});
|
|
1396
|
+
expect(LoggerProxy.log).toHaveBeenCalledWith('Outbound dial completed successfully', {
|
|
1397
|
+
module: CC_FILE,
|
|
1398
|
+
method: 'startOutdial',
|
|
1399
|
+
});
|
|
1400
|
+
|
|
1401
|
+
expect(startOutdialMock).toHaveBeenCalledWith({data: newPayload});
|
|
1402
|
+
expect(result).toEqual(mockResponse);
|
|
1403
|
+
});
|
|
1404
|
+
|
|
1354
1405
|
it('should handle error during startOutdial', async () => {
|
|
1355
1406
|
// Setup outDialEp.
|
|
1356
1407
|
webex.cc.agentConfig = {
|
|
@@ -1387,88 +1438,6 @@ describe('webex.cc', () => {
|
|
|
1387
1438
|
});
|
|
1388
1439
|
});
|
|
1389
1440
|
|
|
1390
|
-
describe('getQueues', () => {
|
|
1391
|
-
it('should return queues response when successful', async () => {
|
|
1392
|
-
const mockQueuesResponse = [
|
|
1393
|
-
{
|
|
1394
|
-
queueId: 'queue1',
|
|
1395
|
-
queueName: 'Queue 1',
|
|
1396
|
-
},
|
|
1397
|
-
{
|
|
1398
|
-
queueId: 'queue2',
|
|
1399
|
-
queueName: 'Queue 2',
|
|
1400
|
-
},
|
|
1401
|
-
];
|
|
1402
|
-
|
|
1403
|
-
webex.cc.services.config.getQueues = jest.fn().mockResolvedValue(mockQueuesResponse);
|
|
1404
|
-
|
|
1405
|
-
const result = await webex.cc.getQueues();
|
|
1406
|
-
|
|
1407
|
-
// Verify logging calls
|
|
1408
|
-
expect(LoggerProxy.info).toHaveBeenCalledWith('Fetching queues', {
|
|
1409
|
-
module: CC_FILE,
|
|
1410
|
-
method: 'getQueues',
|
|
1411
|
-
});
|
|
1412
|
-
expect(LoggerProxy.log).toHaveBeenCalledWith(
|
|
1413
|
-
`Successfully retrieved ${result.length} queues`,
|
|
1414
|
-
{
|
|
1415
|
-
module: CC_FILE,
|
|
1416
|
-
method: 'getQueues',
|
|
1417
|
-
}
|
|
1418
|
-
);
|
|
1419
|
-
|
|
1420
|
-
expect(webex.cc.services.config.getQueues).toHaveBeenCalledWith(
|
|
1421
|
-
'mockOrgId',
|
|
1422
|
-
0,
|
|
1423
|
-
100,
|
|
1424
|
-
undefined,
|
|
1425
|
-
undefined
|
|
1426
|
-
);
|
|
1427
|
-
expect(result).toEqual(mockQueuesResponse);
|
|
1428
|
-
});
|
|
1429
|
-
|
|
1430
|
-
it('should throw an error if orgId is not present', async () => {
|
|
1431
|
-
jest.spyOn(webex.credentials, 'getOrgId').mockResolvedValue(undefined);
|
|
1432
|
-
webex.cc.services.config.getQueues = jest.fn();
|
|
1433
|
-
|
|
1434
|
-
try {
|
|
1435
|
-
await webex.cc.getQueues();
|
|
1436
|
-
} catch (error) {
|
|
1437
|
-
expect(error).toEqual(new Error('Org ID not found.'));
|
|
1438
|
-
expect(LoggerProxy.info).toHaveBeenCalledWith('Fetching queues', {
|
|
1439
|
-
module: CC_FILE,
|
|
1440
|
-
method: 'getQueues',
|
|
1441
|
-
});
|
|
1442
|
-
expect(LoggerProxy.error).toHaveBeenCalledWith('Org ID not found.', {
|
|
1443
|
-
module: CC_FILE,
|
|
1444
|
-
method: 'getQueues',
|
|
1445
|
-
});
|
|
1446
|
-
expect(webex.cc.services.config.getQueues).not.toHaveBeenCalled();
|
|
1447
|
-
}
|
|
1448
|
-
});
|
|
1449
|
-
|
|
1450
|
-
it('should throw an error if config getQueues throws an error', async () => {
|
|
1451
|
-
webex.cc.services.config.getQueues = jest.fn().mockRejectedValue(new Error('Test error.'));
|
|
1452
|
-
|
|
1453
|
-
try {
|
|
1454
|
-
await webex.cc.getQueues();
|
|
1455
|
-
} catch (error) {
|
|
1456
|
-
expect(error).toEqual(new Error('Test error.'));
|
|
1457
|
-
expect(LoggerProxy.info).toHaveBeenCalledWith('Fetching queues', {
|
|
1458
|
-
module: CC_FILE,
|
|
1459
|
-
method: 'getQueues',
|
|
1460
|
-
});
|
|
1461
|
-
expect(webex.cc.services.config.getQueues).toHaveBeenCalledWith(
|
|
1462
|
-
'mockOrgId',
|
|
1463
|
-
0,
|
|
1464
|
-
100,
|
|
1465
|
-
undefined,
|
|
1466
|
-
undefined
|
|
1467
|
-
);
|
|
1468
|
-
}
|
|
1469
|
-
});
|
|
1470
|
-
});
|
|
1471
|
-
|
|
1472
1441
|
describe('uploadLogs', () => {
|
|
1473
1442
|
it('should upload logs successfully', async () => {
|
|
1474
1443
|
const uploadLogsMock = jest.spyOn(webex.cc.webexRequest, 'uploadLogs').mockResolvedValue({
|
|
@@ -1796,6 +1765,31 @@ describe('webex.cc', () => {
|
|
|
1796
1765
|
});
|
|
1797
1766
|
});
|
|
1798
1767
|
|
|
1768
|
+
describe('API property exposure', () => {
|
|
1769
|
+
it('should provide getEntryPoints wrapper that delegates to EntryPoint', async () => {
|
|
1770
|
+
const spy = jest
|
|
1771
|
+
.spyOn(EntryPoint.prototype, 'getEntryPoints')
|
|
1772
|
+
.mockResolvedValue({} as EntryPointListResponse);
|
|
1773
|
+
await webex.cc.getEntryPoints();
|
|
1774
|
+
expect(spy).toHaveBeenCalled();
|
|
1775
|
+
spy.mockRestore();
|
|
1776
|
+
});
|
|
1777
|
+
|
|
1778
|
+
it('should expose addressBook API', () => {
|
|
1779
|
+
expect(webex.cc.addressBook).toBeDefined();
|
|
1780
|
+
expect(webex.cc.addressBook).toBeInstanceOf(AddressBook);
|
|
1781
|
+
});
|
|
1782
|
+
|
|
1783
|
+
it('should provide getQueues wrapper that delegates to Queue', async () => {
|
|
1784
|
+
const spy = jest
|
|
1785
|
+
.spyOn(Queue.prototype, 'getQueues')
|
|
1786
|
+
.mockResolvedValue({} as ContactServiceQueuesResponse);
|
|
1787
|
+
await webex.cc.getQueues();
|
|
1788
|
+
expect(spy).toHaveBeenCalled();
|
|
1789
|
+
spy.mockRestore();
|
|
1790
|
+
});
|
|
1791
|
+
});
|
|
1792
|
+
|
|
1799
1793
|
describe('updateAgentProfile', () => {
|
|
1800
1794
|
beforeEach(() => {
|
|
1801
1795
|
webex.cc.agentConfig = {
|
|
@@ -1982,4 +1976,207 @@ describe('webex.cc', () => {
|
|
|
1982
1976
|
});
|
|
1983
1977
|
});
|
|
1984
1978
|
});
|
|
1979
|
+
|
|
1980
|
+
describe('getOutdialAniEntries', () => {
|
|
1981
|
+
const mockOutdialANI = 'ani-123-456';
|
|
1982
|
+
const mockParams = {
|
|
1983
|
+
outdialANI: mockOutdialANI,
|
|
1984
|
+
page: 0,
|
|
1985
|
+
pageSize: 10,
|
|
1986
|
+
search: 'test',
|
|
1987
|
+
filter: 'active=true',
|
|
1988
|
+
attributes: 'id,name,number',
|
|
1989
|
+
};
|
|
1990
|
+
|
|
1991
|
+
beforeEach(() => {
|
|
1992
|
+
jest.clearAllMocks();
|
|
1993
|
+
// Reset orgId mock to return valid value
|
|
1994
|
+
webex.credentials.getOrgId.mockReturnValue('mockOrgId');
|
|
1995
|
+
});
|
|
1996
|
+
|
|
1997
|
+
it('should successfully fetch outdial ANI entries and track success metrics', async () => {
|
|
1998
|
+
const mockResult = [
|
|
1999
|
+
{
|
|
2000
|
+
id: '142fba3c-8502-4446-bf6e-584fd657553a',
|
|
2001
|
+
name: 'Test Entry',
|
|
2002
|
+
number: '+19403016307',
|
|
2003
|
+
},
|
|
2004
|
+
{
|
|
2005
|
+
id: '6f53000b-e04a-4418-9de9-ba511d2367cb',
|
|
2006
|
+
name: 'Another Entry',
|
|
2007
|
+
number: '+19403016308',
|
|
2008
|
+
},
|
|
2009
|
+
];
|
|
2010
|
+
|
|
2011
|
+
// Mock the service call to return successful result
|
|
2012
|
+
webex.cc.services.config.getOutdialAniEntries.mockResolvedValue(mockResult);
|
|
2013
|
+
|
|
2014
|
+
const result = await webex.cc.getOutdialAniEntries(mockParams);
|
|
2015
|
+
|
|
2016
|
+
// Verify the service was called with correct parameters
|
|
2017
|
+
expect(webex.cc.services.config.getOutdialAniEntries).toHaveBeenCalledWith('mockOrgId', {
|
|
2018
|
+
outdialANI: mockOutdialANI,
|
|
2019
|
+
page: 0,
|
|
2020
|
+
pageSize: 10,
|
|
2021
|
+
search: 'test',
|
|
2022
|
+
filter: 'active=true',
|
|
2023
|
+
attributes: 'id,name,number',
|
|
2024
|
+
});
|
|
2025
|
+
|
|
2026
|
+
// Verify the result is returned correctly
|
|
2027
|
+
expect(result).toEqual(mockResult);
|
|
2028
|
+
|
|
2029
|
+
// Verify success metrics are tracked
|
|
2030
|
+
expect(mockMetricsManager.trackEvent).toHaveBeenCalledWith(
|
|
2031
|
+
METRIC_EVENT_NAMES.OUTDIAL_ANI_EP_FETCH_SUCCESS,
|
|
2032
|
+
{
|
|
2033
|
+
outdialANI: mockOutdialANI,
|
|
2034
|
+
resultCount: 2,
|
|
2035
|
+
},
|
|
2036
|
+
['behavioral', 'business', 'operational']
|
|
2037
|
+
);
|
|
2038
|
+
|
|
2039
|
+
// Verify success logging
|
|
2040
|
+
expect(LoggerProxy.log).toHaveBeenCalledWith(
|
|
2041
|
+
`Successfully retrieved outdial ANI entries for ANI ID ${mockOutdialANI}`,
|
|
2042
|
+
{
|
|
2043
|
+
module: CC_FILE,
|
|
2044
|
+
method: 'getOutdialAniEntries',
|
|
2045
|
+
}
|
|
2046
|
+
);
|
|
2047
|
+
});
|
|
2048
|
+
|
|
2049
|
+
it('should handle empty results and track success metrics with zero count', async () => {
|
|
2050
|
+
const mockResult = [];
|
|
2051
|
+
|
|
2052
|
+
// Mock the service call to return empty result
|
|
2053
|
+
webex.cc.services.config.getOutdialAniEntries.mockResolvedValue(mockResult);
|
|
2054
|
+
|
|
2055
|
+
const result = await webex.cc.getOutdialAniEntries({outdialANI: mockOutdialANI});
|
|
2056
|
+
|
|
2057
|
+
// Verify the result is returned correctly
|
|
2058
|
+
expect(result).toEqual(mockResult);
|
|
2059
|
+
|
|
2060
|
+
// Verify success metrics are tracked with zero count
|
|
2061
|
+
expect(mockMetricsManager.trackEvent).toHaveBeenCalledWith(
|
|
2062
|
+
METRIC_EVENT_NAMES.OUTDIAL_ANI_EP_FETCH_SUCCESS,
|
|
2063
|
+
{
|
|
2064
|
+
outdialANI: mockOutdialANI,
|
|
2065
|
+
resultCount: 0,
|
|
2066
|
+
},
|
|
2067
|
+
['behavioral', 'business', 'operational']
|
|
2068
|
+
);
|
|
2069
|
+
});
|
|
2070
|
+
|
|
2071
|
+
it('should handle undefined results and track success metrics with zero count', async () => {
|
|
2072
|
+
// Mock the service call to return undefined
|
|
2073
|
+
webex.cc.services.config.getOutdialAniEntries.mockResolvedValue(undefined);
|
|
2074
|
+
|
|
2075
|
+
const result = await webex.cc.getOutdialAniEntries({outdialANI: mockOutdialANI});
|
|
2076
|
+
|
|
2077
|
+
// Verify the result is returned correctly
|
|
2078
|
+
expect(result).toBeUndefined();
|
|
2079
|
+
|
|
2080
|
+
// Verify success metrics are tracked with zero count
|
|
2081
|
+
expect(mockMetricsManager.trackEvent).toHaveBeenCalledWith(
|
|
2082
|
+
METRIC_EVENT_NAMES.OUTDIAL_ANI_EP_FETCH_SUCCESS,
|
|
2083
|
+
{
|
|
2084
|
+
outdialANI: mockOutdialANI,
|
|
2085
|
+
resultCount: 0,
|
|
2086
|
+
},
|
|
2087
|
+
['behavioral', 'business', 'operational']
|
|
2088
|
+
);
|
|
2089
|
+
});
|
|
2090
|
+
|
|
2091
|
+
it('should handle service failure and track failure metrics', async () => {
|
|
2092
|
+
const mockError = new Error('Service unavailable') as any;
|
|
2093
|
+
mockError.details = {
|
|
2094
|
+
trackingId: 'test-tracking-id',
|
|
2095
|
+
orgId: 'mockOrgId',
|
|
2096
|
+
error: 'Service error',
|
|
2097
|
+
};
|
|
2098
|
+
|
|
2099
|
+
// Mock the service call to throw an error
|
|
2100
|
+
webex.cc.services.config.getOutdialAniEntries.mockRejectedValue(mockError);
|
|
2101
|
+
|
|
2102
|
+
// Mock getErrorDetails to return a detailed error
|
|
2103
|
+
const detailedError = new Error('Detailed service error');
|
|
2104
|
+
getErrorDetailsSpy.mockReturnValue({error: detailedError});
|
|
2105
|
+
|
|
2106
|
+
await expect(webex.cc.getOutdialAniEntries(mockParams)).rejects.toThrow('Detailed service error');
|
|
2107
|
+
|
|
2108
|
+
// Verify failure metrics are tracked
|
|
2109
|
+
expect(mockMetricsManager.trackEvent).toHaveBeenCalledWith(
|
|
2110
|
+
METRIC_EVENT_NAMES.OUTDIAL_ANI_EP_FETCH_FAILED,
|
|
2111
|
+
{
|
|
2112
|
+
...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(mockError.details),
|
|
2113
|
+
outdialANI: mockOutdialANI,
|
|
2114
|
+
error: mockError,
|
|
2115
|
+
},
|
|
2116
|
+
['behavioral', 'business', 'operational']
|
|
2117
|
+
);
|
|
2118
|
+
|
|
2119
|
+
// Verify error logging
|
|
2120
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
2121
|
+
`Failed to fetch outdial ANI entries for ANI ID ${mockOutdialANI} due to: ${mockError}`,
|
|
2122
|
+
{
|
|
2123
|
+
module: CC_FILE,
|
|
2124
|
+
method: 'getOutdialAniEntries',
|
|
2125
|
+
trackingId: 'test-tracking-id',
|
|
2126
|
+
}
|
|
2127
|
+
);
|
|
2128
|
+
|
|
2129
|
+
// Verify getErrorDetails was called
|
|
2130
|
+
expect(getErrorDetailsSpy).toHaveBeenCalledWith(
|
|
2131
|
+
mockError,
|
|
2132
|
+
'getOutdialAniEntries',
|
|
2133
|
+
CC_FILE
|
|
2134
|
+
);
|
|
2135
|
+
});
|
|
2136
|
+
|
|
2137
|
+
it('should throw error when orgId is not found', async () => {
|
|
2138
|
+
// Mock getOrgId to return null
|
|
2139
|
+
webex.credentials.getOrgId.mockReturnValue(null);
|
|
2140
|
+
|
|
2141
|
+
await expect(webex.cc.getOutdialAniEntries(mockParams)).rejects.toThrow('Org ID not found.');
|
|
2142
|
+
|
|
2143
|
+
// Verify error logging
|
|
2144
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith('Org ID not found.', {
|
|
2145
|
+
module: CC_FILE,
|
|
2146
|
+
method: 'getOutdialAniEntries',
|
|
2147
|
+
});
|
|
2148
|
+
|
|
2149
|
+
// Verify service was not called
|
|
2150
|
+
expect(webex.cc.services.config.getOutdialAniEntries).not.toHaveBeenCalled();
|
|
2151
|
+
|
|
2152
|
+
// Verify no metrics were tracked
|
|
2153
|
+
expect(mockMetricsManager.trackEvent).not.toHaveBeenCalled();
|
|
2154
|
+
});
|
|
2155
|
+
|
|
2156
|
+
it('should handle minimal parameters correctly', async () => {
|
|
2157
|
+
const minimalParams = {outdialANI: mockOutdialANI};
|
|
2158
|
+
const mockResult = [{id: 'test', name: 'Test', number: '+1234567890'}];
|
|
2159
|
+
|
|
2160
|
+
webex.cc.services.config.getOutdialAniEntries.mockResolvedValue(mockResult);
|
|
2161
|
+
|
|
2162
|
+
const result = await webex.cc.getOutdialAniEntries(minimalParams);
|
|
2163
|
+
|
|
2164
|
+
// Verify the service was called with minimal parameters
|
|
2165
|
+
expect(webex.cc.services.config.getOutdialAniEntries).toHaveBeenCalledWith('mockOrgId', {
|
|
2166
|
+
outdialANI: mockOutdialANI,
|
|
2167
|
+
});
|
|
2168
|
+
|
|
2169
|
+
expect(result).toEqual(mockResult);
|
|
2170
|
+
|
|
2171
|
+
// Verify success metrics are tracked
|
|
2172
|
+
expect(mockMetricsManager.trackEvent).toHaveBeenCalledWith(
|
|
2173
|
+
METRIC_EVENT_NAMES.OUTDIAL_ANI_EP_FETCH_SUCCESS,
|
|
2174
|
+
{
|
|
2175
|
+
outdialANI: mockOutdialANI,
|
|
2176
|
+
resultCount: 1,
|
|
2177
|
+
},
|
|
2178
|
+
['behavioral', 'business', 'operational']
|
|
2179
|
+
);
|
|
2180
|
+
});
|
|
2181
|
+
});
|
|
1985
2182
|
});
|
|
@@ -3,7 +3,6 @@ import MetricsManager from '../../../../src/metrics/MetricsManager';
|
|
|
3
3
|
import {METRIC_EVENT_NAMES} from '../../../../src/metrics/constants';
|
|
4
4
|
import {WebexSDK} from '../../../../src/types';
|
|
5
5
|
import {EventPayload} from '@webex/internal-plugin-metrics/src/metrics.types';
|
|
6
|
-
import LoggerProxy from '../../../../src/logger-proxy';
|
|
7
6
|
|
|
8
7
|
describe('MetricsManagerImplementation', () => {
|
|
9
8
|
let webex: WebexSDK;
|