@webex/contact-center 0.0.0-next.1
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 +81 -0
- package/__mocks__/workerMock.js +15 -0
- package/babel.config.js +15 -0
- package/dist/cc.js +1416 -0
- package/dist/cc.js.map +1 -0
- package/dist/config.js +72 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.js +58 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.js +142 -0
- package/dist/index.js.map +1 -0
- package/dist/logger-proxy.js +115 -0
- package/dist/logger-proxy.js.map +1 -0
- package/dist/metrics/MetricsManager.js +474 -0
- package/dist/metrics/MetricsManager.js.map +1 -0
- package/dist/metrics/behavioral-events.js +322 -0
- package/dist/metrics/behavioral-events.js.map +1 -0
- package/dist/metrics/constants.js +134 -0
- package/dist/metrics/constants.js.map +1 -0
- package/dist/services/WebCallingService.js +323 -0
- package/dist/services/WebCallingService.js.map +1 -0
- package/dist/services/agent/index.js +177 -0
- package/dist/services/agent/index.js.map +1 -0
- package/dist/services/agent/types.js +137 -0
- package/dist/services/agent/types.js.map +1 -0
- package/dist/services/config/Util.js +203 -0
- package/dist/services/config/Util.js.map +1 -0
- package/dist/services/config/constants.js +221 -0
- package/dist/services/config/constants.js.map +1 -0
- package/dist/services/config/index.js +607 -0
- package/dist/services/config/index.js.map +1 -0
- package/dist/services/config/types.js +334 -0
- package/dist/services/config/types.js.map +1 -0
- package/dist/services/constants.js +117 -0
- package/dist/services/constants.js.map +1 -0
- package/dist/services/core/Err.js +43 -0
- package/dist/services/core/Err.js.map +1 -0
- package/dist/services/core/GlobalTypes.js +6 -0
- package/dist/services/core/GlobalTypes.js.map +1 -0
- package/dist/services/core/Utils.js +126 -0
- package/dist/services/core/Utils.js.map +1 -0
- package/dist/services/core/WebexRequest.js +96 -0
- package/dist/services/core/WebexRequest.js.map +1 -0
- package/dist/services/core/aqm-reqs.js +246 -0
- package/dist/services/core/aqm-reqs.js.map +1 -0
- package/dist/services/core/constants.js +109 -0
- package/dist/services/core/constants.js.map +1 -0
- package/dist/services/core/types.js +6 -0
- package/dist/services/core/types.js.map +1 -0
- package/dist/services/core/websocket/WebSocketManager.js +187 -0
- package/dist/services/core/websocket/WebSocketManager.js.map +1 -0
- package/dist/services/core/websocket/connection-service.js +111 -0
- package/dist/services/core/websocket/connection-service.js.map +1 -0
- package/dist/services/core/websocket/keepalive.worker.js +94 -0
- package/dist/services/core/websocket/keepalive.worker.js.map +1 -0
- package/dist/services/core/websocket/types.js +6 -0
- package/dist/services/core/websocket/types.js.map +1 -0
- package/dist/services/index.js +78 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/task/AutoWrapup.js +88 -0
- package/dist/services/task/AutoWrapup.js.map +1 -0
- package/dist/services/task/TaskManager.js +369 -0
- package/dist/services/task/TaskManager.js.map +1 -0
- package/dist/services/task/constants.js +58 -0
- package/dist/services/task/constants.js.map +1 -0
- package/dist/services/task/contact.js +464 -0
- package/dist/services/task/contact.js.map +1 -0
- package/dist/services/task/dialer.js +60 -0
- package/dist/services/task/dialer.js.map +1 -0
- package/dist/services/task/index.js +1188 -0
- package/dist/services/task/index.js.map +1 -0
- package/dist/services/task/types.js +214 -0
- package/dist/services/task/types.js.map +1 -0
- package/dist/types/cc.d.ts +676 -0
- package/dist/types/config.d.ts +66 -0
- package/dist/types/constants.d.ts +45 -0
- package/dist/types/index.d.ts +178 -0
- package/dist/types/logger-proxy.d.ts +71 -0
- package/dist/types/metrics/MetricsManager.d.ts +223 -0
- package/dist/types/metrics/behavioral-events.d.ts +29 -0
- package/dist/types/metrics/constants.d.ts +127 -0
- package/dist/types/services/WebCallingService.d.ts +1 -0
- package/dist/types/services/agent/index.d.ts +46 -0
- package/dist/types/services/agent/types.d.ts +413 -0
- package/dist/types/services/config/Util.d.ts +19 -0
- package/dist/types/services/config/constants.d.ts +203 -0
- package/dist/types/services/config/index.d.ts +171 -0
- package/dist/types/services/config/types.d.ts +1113 -0
- package/dist/types/services/constants.d.ts +97 -0
- package/dist/types/services/core/Err.d.ts +119 -0
- package/dist/types/services/core/GlobalTypes.d.ts +33 -0
- package/dist/types/services/core/Utils.d.ts +36 -0
- package/dist/types/services/core/WebexRequest.d.ts +22 -0
- package/dist/types/services/core/aqm-reqs.d.ts +16 -0
- package/dist/types/services/core/constants.d.ts +85 -0
- package/dist/types/services/core/types.d.ts +47 -0
- package/dist/types/services/core/websocket/WebSocketManager.d.ts +34 -0
- package/dist/types/services/core/websocket/connection-service.d.ts +27 -0
- package/dist/types/services/core/websocket/keepalive.worker.d.ts +2 -0
- package/dist/types/services/core/websocket/types.d.ts +37 -0
- package/dist/types/services/index.d.ts +52 -0
- package/dist/types/services/task/AutoWrapup.d.ts +40 -0
- package/dist/types/services/task/TaskManager.d.ts +1 -0
- package/dist/types/services/task/constants.d.ts +46 -0
- package/dist/types/services/task/contact.d.ts +59 -0
- package/dist/types/services/task/dialer.d.ts +28 -0
- package/dist/types/services/task/index.d.ts +569 -0
- package/dist/types/services/task/types.d.ts +1041 -0
- package/dist/types/types.d.ts +452 -0
- package/dist/types/webex-config.d.ts +53 -0
- package/dist/types/webex.d.ts +7 -0
- package/dist/types.js +292 -0
- package/dist/types.js.map +1 -0
- package/dist/webex-config.js +60 -0
- package/dist/webex-config.js.map +1 -0
- package/dist/webex.js +99 -0
- package/dist/webex.js.map +1 -0
- package/jest.config.js +45 -0
- package/package.json +83 -0
- package/src/cc.ts +1618 -0
- package/src/config.ts +65 -0
- package/src/constants.ts +51 -0
- package/src/index.ts +220 -0
- package/src/logger-proxy.ts +110 -0
- package/src/metrics/MetricsManager.ts +512 -0
- package/src/metrics/behavioral-events.ts +332 -0
- package/src/metrics/constants.ts +135 -0
- package/src/services/WebCallingService.ts +351 -0
- package/src/services/agent/index.ts +149 -0
- package/src/services/agent/types.ts +440 -0
- package/src/services/config/Util.ts +261 -0
- package/src/services/config/constants.ts +249 -0
- package/src/services/config/index.ts +743 -0
- package/src/services/config/types.ts +1117 -0
- package/src/services/constants.ts +111 -0
- package/src/services/core/Err.ts +126 -0
- package/src/services/core/GlobalTypes.ts +34 -0
- package/src/services/core/Utils.ts +132 -0
- package/src/services/core/WebexRequest.ts +103 -0
- package/src/services/core/aqm-reqs.ts +272 -0
- package/src/services/core/constants.ts +106 -0
- package/src/services/core/types.ts +48 -0
- package/src/services/core/websocket/WebSocketManager.ts +196 -0
- package/src/services/core/websocket/connection-service.ts +142 -0
- package/src/services/core/websocket/keepalive.worker.js +88 -0
- package/src/services/core/websocket/types.ts +40 -0
- package/src/services/index.ts +71 -0
- package/src/services/task/AutoWrapup.ts +86 -0
- package/src/services/task/TaskManager.ts +420 -0
- package/src/services/task/constants.ts +52 -0
- package/src/services/task/contact.ts +429 -0
- package/src/services/task/dialer.ts +52 -0
- package/src/services/task/index.ts +1375 -0
- package/src/services/task/types.ts +1113 -0
- package/src/types.ts +639 -0
- package/src/webex-config.ts +54 -0
- package/src/webex.js +96 -0
- package/test/unit/spec/cc.ts +1985 -0
- package/test/unit/spec/metrics/MetricsManager.ts +491 -0
- package/test/unit/spec/metrics/behavioral-events.ts +102 -0
- package/test/unit/spec/services/WebCallingService.ts +416 -0
- package/test/unit/spec/services/agent/index.ts +65 -0
- package/test/unit/spec/services/config/index.ts +1035 -0
- package/test/unit/spec/services/core/Utils.ts +279 -0
- package/test/unit/spec/services/core/WebexRequest.ts +144 -0
- package/test/unit/spec/services/core/aqm-reqs.ts +570 -0
- package/test/unit/spec/services/core/websocket/WebSocketManager.ts +378 -0
- package/test/unit/spec/services/core/websocket/connection-service.ts +178 -0
- package/test/unit/spec/services/task/TaskManager.ts +1351 -0
- package/test/unit/spec/services/task/contact.ts +204 -0
- package/test/unit/spec/services/task/dialer.ts +157 -0
- package/test/unit/spec/services/task/index.ts +1474 -0
- package/tsconfig.json +6 -0
- package/typedoc.json +37 -0
- package/typedoc.md +240 -0
- package/umd/contact-center.min.js +3 -0
- package/umd/contact-center.min.js.map +1 -0
|
@@ -0,0 +1,1035 @@
|
|
|
1
|
+
import {WebexSDK} from '../../../../../src/types';
|
|
2
|
+
import AgentConfigService from '../../../../../src/services/config';
|
|
3
|
+
import WebexRequest from '../../../../../src/services/core/WebexRequest';
|
|
4
|
+
import {WCC_API_GATEWAY} from '../../../../../src/services/constants';
|
|
5
|
+
import {CONFIG_FILE_NAME} from '../../../../../src/constants';
|
|
6
|
+
import MockWebex from '@webex/test-helper-mock-webex';
|
|
7
|
+
import LoggerProxy from '../../../../../src/logger-proxy';
|
|
8
|
+
import * as util from '../../../../../src/services/config/Util';
|
|
9
|
+
|
|
10
|
+
jest.mock('../../../../../src/logger-proxy', () => ({
|
|
11
|
+
__esModule: true,
|
|
12
|
+
default: {
|
|
13
|
+
log: jest.fn(),
|
|
14
|
+
error: jest.fn(),
|
|
15
|
+
info: jest.fn(),
|
|
16
|
+
initialize: jest.fn(),
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
describe('AgentConfigService', () => {
|
|
21
|
+
let agentConfigService: AgentConfigService;
|
|
22
|
+
let webex: WebexSDK;
|
|
23
|
+
let mockWebexRequest: WebexRequest;
|
|
24
|
+
const mockAgentId = 'agent123';
|
|
25
|
+
const mockOrgId = 'org123';
|
|
26
|
+
const mockWccAPIURL = WCC_API_GATEWAY;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
webex = new MockWebex({
|
|
30
|
+
logger: {
|
|
31
|
+
log: jest.fn(),
|
|
32
|
+
error: jest.fn(),
|
|
33
|
+
info: jest.fn(),
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
mockWebexRequest = WebexRequest.getInstance({webex});
|
|
38
|
+
mockWebexRequest.request = jest.fn();
|
|
39
|
+
|
|
40
|
+
agentConfigService = new AgentConfigService();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
jest.clearAllMocks();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('getUserUsingCI', () => {
|
|
48
|
+
it('should return AgentResponse on success', async () => {
|
|
49
|
+
const mockResponse = {
|
|
50
|
+
statusCode: 200,
|
|
51
|
+
body: {
|
|
52
|
+
firstName: 'John',
|
|
53
|
+
lastName: 'Doe',
|
|
54
|
+
agentProfileId: 'profile123',
|
|
55
|
+
email: 'john.doe@example.com',
|
|
56
|
+
teamIds: ['123', '456'],
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
(mockWebexRequest.request as jest.Mock).mockResolvedValue(mockResponse);
|
|
60
|
+
|
|
61
|
+
const result = await agentConfigService.getUserUsingCI(mockOrgId, mockAgentId);
|
|
62
|
+
|
|
63
|
+
expect(mockWebexRequest.request).toHaveBeenCalledWith({
|
|
64
|
+
service: mockWccAPIURL,
|
|
65
|
+
resource: `organization/${mockOrgId}/user/by-ci-user-id/${mockAgentId}`,
|
|
66
|
+
method: 'GET',
|
|
67
|
+
});
|
|
68
|
+
expect(result).toEqual(mockResponse.body);
|
|
69
|
+
|
|
70
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith('Fetching user data using CI', {
|
|
71
|
+
module: CONFIG_FILE_NAME,
|
|
72
|
+
method: 'getUserUsingCI',
|
|
73
|
+
});
|
|
74
|
+
expect(LoggerProxy.log).toHaveBeenCalledWith('getUserUsingCI api success.', {
|
|
75
|
+
module: CONFIG_FILE_NAME,
|
|
76
|
+
method: 'getUserUsingCI',
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should throw an error if the API call fails', async () => {
|
|
81
|
+
const mockError = new Error('API call failed');
|
|
82
|
+
(mockWebexRequest.request as jest.Mock).mockRejectedValue(mockError);
|
|
83
|
+
|
|
84
|
+
await expect(agentConfigService.getUserUsingCI(mockOrgId, mockAgentId)).rejects.toThrow(
|
|
85
|
+
'API call failed'
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should throw an error if the getUserUsingCI call fails with other than 200', async () => {
|
|
90
|
+
const mockResponse = {
|
|
91
|
+
statusCode: 400,
|
|
92
|
+
};
|
|
93
|
+
(mockWebexRequest.request as jest.Mock).mockResolvedValue(mockResponse);
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
await agentConfigService.getUserUsingCI(mockOrgId, mockAgentId);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
expect(error).toEqual(new Error(`API call failed with ${mockResponse.statusCode}`));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('getDesktopProfileById', () => {
|
|
104
|
+
const desktopProfileId = 'profile123';
|
|
105
|
+
|
|
106
|
+
it('should return DesktopProfileResponse on success', async () => {
|
|
107
|
+
const mockResponse = {
|
|
108
|
+
statusCode: 200,
|
|
109
|
+
body: {
|
|
110
|
+
loginVoiceOptions: ['option1', 'option2'],
|
|
111
|
+
accessWrapUpCode: 'ALL',
|
|
112
|
+
accessIdleCode: 'SPECIFIC',
|
|
113
|
+
wrapUpCodes: ['code1', 'code2'],
|
|
114
|
+
idleCodes: ['idle1', 'idle2'],
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
(mockWebexRequest.request as jest.Mock).mockResolvedValue(mockResponse);
|
|
118
|
+
|
|
119
|
+
const result = await agentConfigService.getDesktopProfileById(mockOrgId, desktopProfileId);
|
|
120
|
+
|
|
121
|
+
expect(mockWebexRequest.request).toHaveBeenCalledWith({
|
|
122
|
+
service: mockWccAPIURL,
|
|
123
|
+
resource: `organization/${mockOrgId}/agent-profile/${desktopProfileId}`,
|
|
124
|
+
method: 'GET',
|
|
125
|
+
});
|
|
126
|
+
expect(result).toEqual(mockResponse.body);
|
|
127
|
+
|
|
128
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith('Fetching desktop profile', {
|
|
129
|
+
module: CONFIG_FILE_NAME,
|
|
130
|
+
method: 'getDesktopProfileById',
|
|
131
|
+
});
|
|
132
|
+
expect(LoggerProxy.log).toHaveBeenCalledWith('getDesktopProfileById api success.', {
|
|
133
|
+
module: CONFIG_FILE_NAME,
|
|
134
|
+
method: 'getDesktopProfileById',
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should throw an error if the API call fails', async () => {
|
|
139
|
+
const mockError = new Error('API call failed');
|
|
140
|
+
(mockWebexRequest.request as jest.Mock).mockRejectedValue(mockError);
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
await agentConfigService.getDesktopProfileById(mockOrgId, desktopProfileId);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
expect(error).toEqual(mockError);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('should throw an error if the getDesktopProfileById call fails with other than 200', async () => {
|
|
150
|
+
const mockResponse = {
|
|
151
|
+
statusCode: 400,
|
|
152
|
+
};
|
|
153
|
+
(mockWebexRequest.request as jest.Mock).mockResolvedValue(mockResponse);
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
await agentConfigService.getDesktopProfileById(mockOrgId, desktopProfileId);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
expect(error).toEqual(new Error(`API call failed with ${mockResponse.statusCode}`));
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('getListOfTeams', () => {
|
|
164
|
+
const page = 0;
|
|
165
|
+
const pageSize = 10;
|
|
166
|
+
const filter: string[] = ['123'];
|
|
167
|
+
|
|
168
|
+
it('should return team on success', async () => {
|
|
169
|
+
const mockResponse = {
|
|
170
|
+
statusCode: 200,
|
|
171
|
+
body: [
|
|
172
|
+
{id: '123', name: 'Team 1'},
|
|
173
|
+
{id: '12345', name: 'Team 2'},
|
|
174
|
+
],
|
|
175
|
+
};
|
|
176
|
+
(mockWebexRequest.request as jest.Mock).mockResolvedValue(mockResponse);
|
|
177
|
+
|
|
178
|
+
const result = await agentConfigService.getListOfTeams(
|
|
179
|
+
mockOrgId,
|
|
180
|
+
page,
|
|
181
|
+
pageSize,
|
|
182
|
+
filter
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
expect(mockWebexRequest.request).toHaveBeenCalledWith({
|
|
186
|
+
service: mockWccAPIURL,
|
|
187
|
+
resource: `organization/${mockOrgId}/v2/team?page=${page}&pageSize=${pageSize}&filter=id=in=(${filter})`,
|
|
188
|
+
method: 'GET',
|
|
189
|
+
});
|
|
190
|
+
expect(result).toEqual(mockResponse.body);
|
|
191
|
+
|
|
192
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith('Fetching list of teams', {
|
|
193
|
+
module: CONFIG_FILE_NAME,
|
|
194
|
+
method: 'getListOfTeams',
|
|
195
|
+
});
|
|
196
|
+
expect(LoggerProxy.log).toHaveBeenCalledWith('getListOfTeams api success.', {
|
|
197
|
+
module: CONFIG_FILE_NAME,
|
|
198
|
+
method: 'getListOfTeams',
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('should throw an error if the API call fails', async () => {
|
|
203
|
+
const mockError = new Error('API call failed');
|
|
204
|
+
(mockWebexRequest.request as jest.Mock).mockRejectedValue(mockError);
|
|
205
|
+
|
|
206
|
+
try {
|
|
207
|
+
await agentConfigService.getListOfTeams(mockOrgId, page, pageSize, filter);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
expect(error).toEqual(mockError);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('should throw an error if the getListOfTeams call fails with other than 200', async () => {
|
|
214
|
+
const mockResponse = {
|
|
215
|
+
statusCode: 400,
|
|
216
|
+
};
|
|
217
|
+
(mockWebexRequest.request as jest.Mock).mockResolvedValue(mockResponse);
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
await agentConfigService.getListOfTeams(mockOrgId, page, pageSize, filter);
|
|
221
|
+
} catch (error) {
|
|
222
|
+
expect(error).toEqual(new Error(`API call failed with ${mockResponse.statusCode}`));
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe('getListOfAuxCodes', () => {
|
|
228
|
+
const page = 0;
|
|
229
|
+
const pageSize = 10;
|
|
230
|
+
const filter: string[] = ['123'];
|
|
231
|
+
const attributes: string[] = ['id'];
|
|
232
|
+
|
|
233
|
+
it('should return ListAuxCodesResponse on success', async () => {
|
|
234
|
+
const mockResponse = {
|
|
235
|
+
statusCode: 200,
|
|
236
|
+
body: {
|
|
237
|
+
data: [
|
|
238
|
+
{
|
|
239
|
+
id: 'aux1',
|
|
240
|
+
active: true,
|
|
241
|
+
defaultCode: false,
|
|
242
|
+
isSystemCode: false,
|
|
243
|
+
description: 'Aux 1',
|
|
244
|
+
name: 'Aux 1',
|
|
245
|
+
workTypeCode: 'work1',
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
id: 'aux2',
|
|
249
|
+
active: true,
|
|
250
|
+
defaultCode: false,
|
|
251
|
+
isSystemCode: false,
|
|
252
|
+
description: 'Aux 2',
|
|
253
|
+
name: 'Aux 2',
|
|
254
|
+
workTypeCode: 'work2',
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
(mockWebexRequest.request as jest.Mock).mockResolvedValue(mockResponse);
|
|
260
|
+
|
|
261
|
+
const result = await agentConfigService.getListOfAuxCodes(
|
|
262
|
+
mockOrgId,
|
|
263
|
+
page,
|
|
264
|
+
pageSize,
|
|
265
|
+
filter,
|
|
266
|
+
attributes
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
expect(mockWebexRequest.request).toHaveBeenCalledWith({
|
|
270
|
+
service: mockWccAPIURL,
|
|
271
|
+
resource: `organization/${mockOrgId}/v2/auxiliary-code?page=${page}&pageSize=${pageSize}&filter=id=in=(${filter})&attributes=${attributes}`,
|
|
272
|
+
method: 'GET',
|
|
273
|
+
});
|
|
274
|
+
expect(result).toEqual(mockResponse.body);
|
|
275
|
+
|
|
276
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith('Fetching list of aux codes', {
|
|
277
|
+
module: CONFIG_FILE_NAME,
|
|
278
|
+
method: 'getListOfAuxCodes',
|
|
279
|
+
});
|
|
280
|
+
expect(LoggerProxy.log).toHaveBeenCalledWith('getListOfAuxCodes api success.', {
|
|
281
|
+
module: CONFIG_FILE_NAME,
|
|
282
|
+
method: 'getListOfAuxCodes',
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('should throw an error if the API call fails', async () => {
|
|
287
|
+
const mockError = new Error('API call failed');
|
|
288
|
+
(mockWebexRequest.request as jest.Mock).mockRejectedValue(mockError);
|
|
289
|
+
try {
|
|
290
|
+
await agentConfigService.getListOfAuxCodes(mockOrgId, page, pageSize, filter, attributes);
|
|
291
|
+
} catch (error) {
|
|
292
|
+
expect(error).toEqual(mockError);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('should throw an error if the getListOfAuxCodes call fails with other than 200', async () => {
|
|
297
|
+
const mockResponse = {
|
|
298
|
+
statusCode: 400,
|
|
299
|
+
};
|
|
300
|
+
(mockWebexRequest.request as jest.Mock).mockResolvedValue(mockResponse);
|
|
301
|
+
|
|
302
|
+
try {
|
|
303
|
+
await agentConfigService.getListOfAuxCodes(mockOrgId, page, pageSize, filter, attributes);
|
|
304
|
+
} catch (error) {
|
|
305
|
+
expect(error).toEqual(new Error(`API call failed with ${mockResponse.statusCode}`));
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
describe('getOrgInfo', () => {
|
|
311
|
+
it('should return organization info successfully', async () => {
|
|
312
|
+
const mockResponse = {
|
|
313
|
+
statusCode: 200,
|
|
314
|
+
body: {
|
|
315
|
+
id: 'org123',
|
|
316
|
+
name: 'Organization 123',
|
|
317
|
+
description: 'Description',
|
|
318
|
+
type: 'type',
|
|
319
|
+
status: 'status',
|
|
320
|
+
created: '2021-01-01',
|
|
321
|
+
},
|
|
322
|
+
};
|
|
323
|
+
mockWebexRequest.request.mockResolvedValue(mockResponse);
|
|
324
|
+
|
|
325
|
+
const result = await agentConfigService.getOrgInfo(mockOrgId);
|
|
326
|
+
expect(result).toEqual(mockResponse.body);
|
|
327
|
+
expect(LoggerProxy.log).toHaveBeenCalledWith('getOrgInfo api success.', {
|
|
328
|
+
module: CONFIG_FILE_NAME,
|
|
329
|
+
method: 'getOrgInfo',
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('should throw an error if API call returns non-200 status code', async () => {
|
|
334
|
+
const mockError = {statusCode: 500};
|
|
335
|
+
mockWebexRequest.request.mockResolvedValue(mockError);
|
|
336
|
+
|
|
337
|
+
await expect(agentConfigService.getOrgInfo(mockOrgId)).rejects.toThrow(
|
|
338
|
+
'API call failed with 500'
|
|
339
|
+
);
|
|
340
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
341
|
+
'getOrgInfo API call failed with Error: API call failed with 500',
|
|
342
|
+
{module: CONFIG_FILE_NAME, method: 'getOrgInfo'}
|
|
343
|
+
);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it('should handle network errors gracefully', async () => {
|
|
347
|
+
const networkError = new Error('Network Error');
|
|
348
|
+
mockWebexRequest.request.mockRejectedValue(networkError);
|
|
349
|
+
|
|
350
|
+
await expect(agentConfigService.getOrgInfo(mockOrgId)).rejects.toThrow('Network Error');
|
|
351
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
352
|
+
'getOrgInfo API call failed with Error: Network Error',
|
|
353
|
+
{module: CONFIG_FILE_NAME, method: 'getOrgInfo'}
|
|
354
|
+
);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it('should handle timeout errors gracefully', async () => {
|
|
358
|
+
const timeoutError = new Error('Timeout Error');
|
|
359
|
+
mockWebexRequest.request.mockRejectedValue(timeoutError);
|
|
360
|
+
|
|
361
|
+
await expect(agentConfigService.getOrgInfo(mockOrgId)).rejects.toThrow('Timeout Error');
|
|
362
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
363
|
+
'getOrgInfo API call failed with Error: Timeout Error',
|
|
364
|
+
{module: CONFIG_FILE_NAME, method: 'getOrgInfo'}
|
|
365
|
+
);
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
describe('getOrganizationSetting', () => {
|
|
370
|
+
it('should return organization settings successfully', async () => {
|
|
371
|
+
const mockResponse = {statusCode: 200, body: {data: [{}]}}; // Adjust data accordingly
|
|
372
|
+
mockWebexRequest.request.mockResolvedValue(mockResponse);
|
|
373
|
+
|
|
374
|
+
const result = await agentConfigService.getOrganizationSetting();
|
|
375
|
+
expect(result).toEqual(mockResponse.body.data[0]);
|
|
376
|
+
expect(LoggerProxy.log).toHaveBeenCalledWith('getOrganizationSetting api success.', {
|
|
377
|
+
module: CONFIG_FILE_NAME,
|
|
378
|
+
method: 'getOrganizationSetting',
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('should throw an error if API call returns non-200 status code', async () => {
|
|
383
|
+
const mockError = {statusCode: 500};
|
|
384
|
+
mockWebexRequest.request.mockResolvedValue(mockError);
|
|
385
|
+
|
|
386
|
+
await expect(agentConfigService.getOrganizationSetting(mockOrgId)).rejects.toThrow(
|
|
387
|
+
'API call failed with 500'
|
|
388
|
+
);
|
|
389
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
390
|
+
'getOrganizationSetting API call failed with Error: API call failed with 500',
|
|
391
|
+
{module: CONFIG_FILE_NAME, method: 'getOrganizationSetting'}
|
|
392
|
+
);
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it('should handle network errors gracefully', async () => {
|
|
396
|
+
const networkError = new Error('Network Error');
|
|
397
|
+
mockWebexRequest.request.mockRejectedValue(networkError);
|
|
398
|
+
|
|
399
|
+
await expect(agentConfigService.getOrganizationSetting(mockOrgId)).rejects.toThrow(
|
|
400
|
+
'Network Error'
|
|
401
|
+
);
|
|
402
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
403
|
+
'getOrganizationSetting API call failed with Error: Network Error',
|
|
404
|
+
{module: CONFIG_FILE_NAME, method: 'getOrganizationSetting'}
|
|
405
|
+
);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
it('should handle timeout errors gracefully', async () => {
|
|
409
|
+
const timeoutError = new Error('Timeout Error');
|
|
410
|
+
mockWebexRequest.request.mockRejectedValue(timeoutError);
|
|
411
|
+
|
|
412
|
+
await expect(agentConfigService.getOrganizationSetting(mockOrgId)).rejects.toThrow(
|
|
413
|
+
'Timeout Error'
|
|
414
|
+
);
|
|
415
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
416
|
+
'getOrganizationSetting API call failed with Error: Timeout Error',
|
|
417
|
+
{module: CONFIG_FILE_NAME, method: 'getOrganizationSetting'}
|
|
418
|
+
);
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
describe('getTenantData', () => {
|
|
423
|
+
it('should return tenant successfully', async () => {
|
|
424
|
+
const mockResponse = {statusCode: 200, body: {data: [{}]}}; // Adjust data accordingly
|
|
425
|
+
mockWebexRequest.request.mockResolvedValue(mockResponse);
|
|
426
|
+
|
|
427
|
+
const result = await agentConfigService.getTenantData(mockOrgId);
|
|
428
|
+
expect(result).toEqual(mockResponse.body.data[0]);
|
|
429
|
+
expect(LoggerProxy.log).toHaveBeenCalledWith('getTenantData api success.', {
|
|
430
|
+
module: CONFIG_FILE_NAME,
|
|
431
|
+
method: 'getTenantData',
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it('should throw an error if API call returns non-200 status code', async () => {
|
|
436
|
+
const mockError = {statusCode: 500};
|
|
437
|
+
mockWebexRequest.request.mockResolvedValue(mockError);
|
|
438
|
+
|
|
439
|
+
await expect(agentConfigService.getTenantData(mockOrgId)).rejects.toThrow(
|
|
440
|
+
'API call failed with 500'
|
|
441
|
+
);
|
|
442
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
443
|
+
'getTenantData API call failed with Error: API call failed with 500',
|
|
444
|
+
{module: CONFIG_FILE_NAME, method: 'getTenantData'}
|
|
445
|
+
);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it('should handle network errors gracefully', async () => {
|
|
449
|
+
const networkError = new Error('Network Error');
|
|
450
|
+
mockWebexRequest.request.mockRejectedValue(networkError);
|
|
451
|
+
|
|
452
|
+
await expect(agentConfigService.getTenantData(mockOrgId)).rejects.toThrow('Network Error');
|
|
453
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
454
|
+
'getTenantData API call failed with Error: Network Error',
|
|
455
|
+
{module: CONFIG_FILE_NAME, method: 'getTenantData'}
|
|
456
|
+
);
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
describe(`getURLMapping`, () => {
|
|
461
|
+
it('should return URL mapping successfully', async () => {
|
|
462
|
+
const mockResponse = {statusCode: 200, body: {data: {}}}; // Adjust data accordingly
|
|
463
|
+
mockWebexRequest.request.mockResolvedValue(mockResponse);
|
|
464
|
+
|
|
465
|
+
const result = await agentConfigService.getURLMapping(mockOrgId);
|
|
466
|
+
expect(result).toEqual(mockResponse.body.data);
|
|
467
|
+
expect(LoggerProxy.log).toHaveBeenCalledWith('getURLMapping api success.', {
|
|
468
|
+
module: CONFIG_FILE_NAME,
|
|
469
|
+
method: 'getURLMapping',
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
it('should throw an error if API call returns non-200 status code', async () => {
|
|
474
|
+
const mockError = {statusCode: 500};
|
|
475
|
+
mockWebexRequest.request.mockResolvedValue(mockError);
|
|
476
|
+
|
|
477
|
+
await expect(agentConfigService.getURLMapping(mockOrgId)).rejects.toThrow(
|
|
478
|
+
'API call failed with 500'
|
|
479
|
+
);
|
|
480
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
481
|
+
'getURLMapping API call failed with Error: API call failed with 500',
|
|
482
|
+
{module: CONFIG_FILE_NAME, method: 'getURLMapping'}
|
|
483
|
+
);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
it('should handle network errors gracefully', async () => {
|
|
487
|
+
const networkError = new Error('Network Error');
|
|
488
|
+
mockWebexRequest.request.mockRejectedValue(networkError);
|
|
489
|
+
|
|
490
|
+
await expect(agentConfigService.getURLMapping(mockOrgId)).rejects.toThrow('Network Error');
|
|
491
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
492
|
+
'getURLMapping API call failed with Error: Network Error',
|
|
493
|
+
{module: CONFIG_FILE_NAME, method: 'getURLMapping'}
|
|
494
|
+
);
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
describe(`getDialPlanData`, () => {
|
|
499
|
+
it('should return dial plan data successfully', async () => {
|
|
500
|
+
const mockResponse = {statusCode: 200, body: {data: {}}}; // Adjust data accordingly
|
|
501
|
+
mockWebexRequest.request.mockResolvedValue(mockResponse);
|
|
502
|
+
|
|
503
|
+
const result = await agentConfigService.getDialPlanData(mockOrgId);
|
|
504
|
+
expect(result).toEqual(mockResponse.body);
|
|
505
|
+
expect(LoggerProxy.log).toHaveBeenCalledWith('getDialPlanData api success.', {
|
|
506
|
+
module: CONFIG_FILE_NAME,
|
|
507
|
+
method: 'getDialPlanData',
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
it('should throw an error if API call returns non-200 status code', async () => {
|
|
512
|
+
const mockError = {statusCode: 500};
|
|
513
|
+
mockWebexRequest.request.mockResolvedValue(mockError);
|
|
514
|
+
|
|
515
|
+
await expect(agentConfigService.getDialPlanData(mockOrgId)).rejects.toThrow(
|
|
516
|
+
'API call failed with 500'
|
|
517
|
+
);
|
|
518
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
519
|
+
'getDialPlanData API call failed with Error: API call failed with 500',
|
|
520
|
+
{module: CONFIG_FILE_NAME, method: 'getDialPlanData'}
|
|
521
|
+
);
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
it('should handle network errors gracefully', async () => {
|
|
525
|
+
const networkError = new Error('Network Error');
|
|
526
|
+
mockWebexRequest.request.mockRejectedValue(networkError);
|
|
527
|
+
|
|
528
|
+
await expect(agentConfigService.getDialPlanData(mockOrgId)).rejects.toThrow('Network Error');
|
|
529
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
530
|
+
'getDialPlanData API call failed with Error: Network Error',
|
|
531
|
+
{module: CONFIG_FILE_NAME, method: 'getDialPlanData'}
|
|
532
|
+
);
|
|
533
|
+
});
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
describe(`getAllTeams`, () => {
|
|
537
|
+
it('should return all teams successfully', async () => {
|
|
538
|
+
const pageSize = 10;
|
|
539
|
+
const filter = ['filter1'];
|
|
540
|
+
const attributes = ['attribute1'];
|
|
541
|
+
|
|
542
|
+
const mockResponseFirst = {
|
|
543
|
+
body: {
|
|
544
|
+
data: [{id: 'team1'}],
|
|
545
|
+
meta: {totalPages: 3},
|
|
546
|
+
},
|
|
547
|
+
statusCode: 200,
|
|
548
|
+
};
|
|
549
|
+
const mockResponseOther = {
|
|
550
|
+
body: {
|
|
551
|
+
data: [{id: 'team2'}],
|
|
552
|
+
},
|
|
553
|
+
statusCode: 200,
|
|
554
|
+
};
|
|
555
|
+
(mockWebexRequest.request as jest.Mock)
|
|
556
|
+
.mockResolvedValueOnce(mockResponseFirst)
|
|
557
|
+
.mockResolvedValue(mockResponseOther);
|
|
558
|
+
|
|
559
|
+
const result = await agentConfigService.getAllTeams(mockOrgId, pageSize, filter, attributes);
|
|
560
|
+
expect(result).toEqual([
|
|
561
|
+
...mockResponseFirst.body.data,
|
|
562
|
+
...mockResponseOther.body.data,
|
|
563
|
+
...mockResponseOther.body.data,
|
|
564
|
+
]);
|
|
565
|
+
|
|
566
|
+
expect(LoggerProxy.log).toHaveBeenCalledTimes(3);
|
|
567
|
+
|
|
568
|
+
// Verify that each call was made with the expected message
|
|
569
|
+
expect(LoggerProxy.log).toHaveBeenNthCalledWith(1, 'getListOfTeams api success.', {
|
|
570
|
+
module: CONFIG_FILE_NAME,
|
|
571
|
+
method: 'getListOfTeams',
|
|
572
|
+
});
|
|
573
|
+
expect(LoggerProxy.log).toHaveBeenNthCalledWith(2, 'getListOfTeams api success.', {
|
|
574
|
+
module: CONFIG_FILE_NAME,
|
|
575
|
+
method: 'getListOfTeams',
|
|
576
|
+
});
|
|
577
|
+
expect(LoggerProxy.log).toHaveBeenNthCalledWith(3, 'getListOfTeams api success.', {
|
|
578
|
+
module: CONFIG_FILE_NAME,
|
|
579
|
+
method: 'getListOfTeams',
|
|
580
|
+
});
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
it('should throw an error if API call returns non-200 status code', async () => {
|
|
584
|
+
const pageSize = 10;
|
|
585
|
+
const filter = ['filter1'];
|
|
586
|
+
const attributes = ['attribute1'];
|
|
587
|
+
|
|
588
|
+
const mockError = {statusCode: 500};
|
|
589
|
+
(mockWebexRequest.request as jest.Mock).mockResolvedValue(mockError);
|
|
590
|
+
|
|
591
|
+
await expect(
|
|
592
|
+
agentConfigService.getAllTeams(mockOrgId, pageSize, filter, attributes)
|
|
593
|
+
).rejects.toThrow('API call failed with 500');
|
|
594
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
595
|
+
'getListOfTeams API call failed with Error: API call failed with 500',
|
|
596
|
+
{module: CONFIG_FILE_NAME, method: 'getListOfTeams'}
|
|
597
|
+
);
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
describe(`getAllAuxCodes`, () => {
|
|
602
|
+
it('should return all aux codes successfully', async () => {
|
|
603
|
+
const pageSize = 10;
|
|
604
|
+
const filter = ['filter1'];
|
|
605
|
+
const attributes = ['attribute1'];
|
|
606
|
+
|
|
607
|
+
const mockResponseFirst = {
|
|
608
|
+
body: {
|
|
609
|
+
data: [{id: 'aux1'}],
|
|
610
|
+
meta: {totalPages: 3},
|
|
611
|
+
},
|
|
612
|
+
statusCode: 200,
|
|
613
|
+
};
|
|
614
|
+
const mockResponseOther = {
|
|
615
|
+
body: {
|
|
616
|
+
data: [{id: 'aux2'}],
|
|
617
|
+
},
|
|
618
|
+
statusCode: 200,
|
|
619
|
+
};
|
|
620
|
+
(mockWebexRequest.request as jest.Mock)
|
|
621
|
+
.mockResolvedValueOnce(mockResponseFirst)
|
|
622
|
+
.mockResolvedValue(mockResponseOther);
|
|
623
|
+
|
|
624
|
+
const result = await agentConfigService.getAllAuxCodes(
|
|
625
|
+
mockOrgId,
|
|
626
|
+
pageSize,
|
|
627
|
+
filter,
|
|
628
|
+
attributes
|
|
629
|
+
);
|
|
630
|
+
expect(result).toEqual([
|
|
631
|
+
...mockResponseFirst.body.data,
|
|
632
|
+
...mockResponseOther.body.data,
|
|
633
|
+
...mockResponseOther.body.data,
|
|
634
|
+
]);
|
|
635
|
+
|
|
636
|
+
expect(LoggerProxy.log).toHaveBeenCalledTimes(3);
|
|
637
|
+
|
|
638
|
+
// Verify that each call was made with the expected message
|
|
639
|
+
expect(LoggerProxy.log).toHaveBeenNthCalledWith(1, 'getListOfAuxCodes api success.', {
|
|
640
|
+
module: CONFIG_FILE_NAME,
|
|
641
|
+
method: 'getListOfAuxCodes',
|
|
642
|
+
});
|
|
643
|
+
expect(LoggerProxy.log).toHaveBeenNthCalledWith(2, 'getListOfAuxCodes api success.', {
|
|
644
|
+
module: CONFIG_FILE_NAME,
|
|
645
|
+
method: 'getListOfAuxCodes',
|
|
646
|
+
});
|
|
647
|
+
expect(LoggerProxy.log).toHaveBeenNthCalledWith(3, 'getListOfAuxCodes api success.', {
|
|
648
|
+
module: CONFIG_FILE_NAME,
|
|
649
|
+
method: 'getListOfAuxCodes',
|
|
650
|
+
});
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
it('should throw an error if API call returns non-200 status code', async () => {
|
|
654
|
+
const pageSize = 10;
|
|
655
|
+
const filter = ['filter1'];
|
|
656
|
+
const attributes = ['attribute1'];
|
|
657
|
+
|
|
658
|
+
const mockError = {statusCode: 500};
|
|
659
|
+
(mockWebexRequest.request as jest.Mock).mockResolvedValue(mockError);
|
|
660
|
+
|
|
661
|
+
await expect(
|
|
662
|
+
agentConfigService.getAllAuxCodes(mockOrgId, pageSize, filter, attributes)
|
|
663
|
+
).rejects.toThrow('API call failed with 500');
|
|
664
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
665
|
+
'getListOfAuxCodes API call failed with Error: API call failed with 500',
|
|
666
|
+
{
|
|
667
|
+
module: CONFIG_FILE_NAME,
|
|
668
|
+
method: 'getListOfAuxCodes',
|
|
669
|
+
}
|
|
670
|
+
);
|
|
671
|
+
});
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
describe('getAgentConfig', () => {
|
|
675
|
+
beforeEach(() => {
|
|
676
|
+
jest.clearAllMocks();
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
it('should fetch and parse agent configuration successfully', async () => {
|
|
680
|
+
const mockAgentId = 'agent001';
|
|
681
|
+
const mockUserConfig = {
|
|
682
|
+
ciUserId: 'agent001',
|
|
683
|
+
firstName: 'John',
|
|
684
|
+
lastName: 'Doe',
|
|
685
|
+
email: 'john.doe@example.com',
|
|
686
|
+
agentProfileId: 'profile123',
|
|
687
|
+
siteId: 'site789',
|
|
688
|
+
dbId: 'db123',
|
|
689
|
+
defaultDialledNumber: '1234567890',
|
|
690
|
+
id: 'user001',
|
|
691
|
+
teamIds: ['team1', 'team2'],
|
|
692
|
+
};
|
|
693
|
+
|
|
694
|
+
const mockAgentProfile = {
|
|
695
|
+
timeoutDesktopInactivityCustomEnabled: true,
|
|
696
|
+
timeoutDesktopInactivityMins: 10,
|
|
697
|
+
accessWrapUpCode: 'SPECIFIC',
|
|
698
|
+
wrapUpCodes: ['aux1'],
|
|
699
|
+
accessIdleCode: 'SPECIFIC',
|
|
700
|
+
idleCodes: ['aux2'],
|
|
701
|
+
autoWrapUp: true,
|
|
702
|
+
autoWrapAfterSeconds: 30,
|
|
703
|
+
lastAgentRouting: true,
|
|
704
|
+
allowAutoWrapUpExtension: false,
|
|
705
|
+
outdialEnabled: true,
|
|
706
|
+
dialPlanEnabled: false,
|
|
707
|
+
agentAvailableAfterOutdial: true,
|
|
708
|
+
outdialEntryPointId: 'entryPoint123',
|
|
709
|
+
consultToQueue: true,
|
|
710
|
+
addressBookId: 'addressBook123',
|
|
711
|
+
outdialANIId: 'ani123',
|
|
712
|
+
dialPlans: ['plan1', 'plan2'],
|
|
713
|
+
agentDNValidation: 'validation123',
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
const mockDialPlanData = [];
|
|
717
|
+
|
|
718
|
+
const mockTeamData = [
|
|
719
|
+
{id: 'team1', name: 'Support Team'},
|
|
720
|
+
{id: 'team2', name: 'Sales Team'},
|
|
721
|
+
];
|
|
722
|
+
|
|
723
|
+
const mockOrgInfo = {
|
|
724
|
+
tenantId: 'tenant123',
|
|
725
|
+
timezone: 'GMT',
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
const mockOrgSettings = {
|
|
729
|
+
campaignManagerEnabled: true,
|
|
730
|
+
webRtcEnabled: true,
|
|
731
|
+
maskSensitiveData: false,
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
const mockSiteInfo = {
|
|
735
|
+
id: "c6a5451f-5ba7-49a1-aee8-fbef70c19ece",
|
|
736
|
+
name: "Site-1",
|
|
737
|
+
multimediaProfileId: "c5888e6f-5661-4871-9936-cbcec7658d41",
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
const mockTenantData = {
|
|
741
|
+
timeoutDesktopInactivityEnabled: false,
|
|
742
|
+
timeoutDesktopInactivityMins: 15,
|
|
743
|
+
forceDefaultDn: true,
|
|
744
|
+
dnDefaultRegex: 'regexUS',
|
|
745
|
+
dnOtherRegex: 'regexOther',
|
|
746
|
+
privacyShieldVisible: true,
|
|
747
|
+
outdialEnabled: true,
|
|
748
|
+
endCallEnabled: true,
|
|
749
|
+
endConsultEnabled: true,
|
|
750
|
+
callVariablesSuppressed: false,
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
const mockURLMapping = [
|
|
754
|
+
{key: 'ACQUEON_API_URL', url: 'https://api.example.com'},
|
|
755
|
+
{key: 'ACQUEON_CONSOLE_URL', url: 'https://console.example.com'},
|
|
756
|
+
];
|
|
757
|
+
|
|
758
|
+
const mockAuxCodes = [
|
|
759
|
+
{id: 'aux1', type: 'WRAP_UP_CODE', name: 'Wrap Up Code 1', isDefault: true},
|
|
760
|
+
{id: 'aux2', type: 'IDLE_CODE', name: 'Idle Code 1', isDefault: true},
|
|
761
|
+
];
|
|
762
|
+
|
|
763
|
+
const parseAgentConfigsSpy = jest.spyOn(util, 'parseAgentConfigs');
|
|
764
|
+
agentConfigService.getUserUsingCI = jest.fn().mockResolvedValue(mockUserConfig);
|
|
765
|
+
agentConfigService.getOrgInfo = jest.fn().mockResolvedValue(mockOrgInfo);
|
|
766
|
+
agentConfigService.getOrganizationSetting = jest.fn().mockResolvedValue(mockOrgSettings);
|
|
767
|
+
agentConfigService.getSiteInfo = jest.fn().mockResolvedValue(mockSiteInfo);
|
|
768
|
+
agentConfigService.getTenantData = jest.fn().mockResolvedValue(mockTenantData);
|
|
769
|
+
agentConfigService.getURLMapping = jest.fn().mockResolvedValue(mockURLMapping);
|
|
770
|
+
agentConfigService.getAllAuxCodes = jest.fn().mockResolvedValue(mockAuxCodes);
|
|
771
|
+
agentConfigService.getDesktopProfileById = jest.fn().mockResolvedValue(mockAgentProfile);
|
|
772
|
+
agentConfigService.getDialPlanData = jest.fn().mockResolvedValue(mockDialPlanData);
|
|
773
|
+
agentConfigService.getAllTeams = jest.fn().mockResolvedValue(mockTeamData);
|
|
774
|
+
|
|
775
|
+
const result = await agentConfigService.getAgentConfig(mockOrgId, mockAgentId);
|
|
776
|
+
|
|
777
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith(`Fetched user data, userId: ${mockUserConfig.ciUserId}`, {
|
|
778
|
+
module: CONFIG_FILE_NAME,
|
|
779
|
+
method: 'getAgentConfig',
|
|
780
|
+
});
|
|
781
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith('Fetched all required data', {
|
|
782
|
+
module: CONFIG_FILE_NAME,
|
|
783
|
+
method: 'getAgentConfig',
|
|
784
|
+
});
|
|
785
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith('Parsing completed for agent-config', {
|
|
786
|
+
module: CONFIG_FILE_NAME,
|
|
787
|
+
method: 'getAgentConfig',
|
|
788
|
+
});
|
|
789
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith('Fetched configuration data successfully', {
|
|
790
|
+
module: CONFIG_FILE_NAME,
|
|
791
|
+
method: 'getAgentConfig',
|
|
792
|
+
});
|
|
793
|
+
expect(parseAgentConfigsSpy).toHaveBeenCalledTimes(1);
|
|
794
|
+
|
|
795
|
+
expect(parseAgentConfigsSpy).toHaveBeenCalledWith({
|
|
796
|
+
userData: mockUserConfig,
|
|
797
|
+
teamData: mockTeamData,
|
|
798
|
+
tenantData: mockTenantData,
|
|
799
|
+
orgInfoData: mockOrgInfo,
|
|
800
|
+
auxCodes: mockAuxCodes,
|
|
801
|
+
orgSettingsData: mockOrgSettings,
|
|
802
|
+
agentProfileData: mockAgentProfile,
|
|
803
|
+
dialPlanData: mockDialPlanData,
|
|
804
|
+
urlMapping: mockURLMapping,
|
|
805
|
+
multimediaProfileId: mockSiteInfo.multimediaProfileId
|
|
806
|
+
});
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
it('should fetch and parse agent configuration with different values and conditions successfully', async () => {
|
|
810
|
+
const mockAgentId = 'agent001';
|
|
811
|
+
const mockUserConfig = {
|
|
812
|
+
ciUserId: 'agent001',
|
|
813
|
+
firstName: 'John',
|
|
814
|
+
lastName: 'Doe',
|
|
815
|
+
email: 'john.doe@example.com',
|
|
816
|
+
agentProfileId: 'profile123',
|
|
817
|
+
skillProfileId: 'skillProfile456',
|
|
818
|
+
siteId: 'site789',
|
|
819
|
+
dbId: 'db123',
|
|
820
|
+
defaultDialledNumber: '1234567890',
|
|
821
|
+
id: 'user001',
|
|
822
|
+
teamIds: ['team1', 'team2'],
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
const mockAgentProfile = {
|
|
826
|
+
timeoutDesktopInactivityCustomEnabled: false,
|
|
827
|
+
timeoutDesktopInactivityMins: 10,
|
|
828
|
+
accessWrapUpCode: 'ALL',
|
|
829
|
+
wrapUpCodes: [],
|
|
830
|
+
accessIdleCode: 'ALL',
|
|
831
|
+
idleCodes: [],
|
|
832
|
+
autoWrapUp: true,
|
|
833
|
+
autoWrapAfterSeconds: 30,
|
|
834
|
+
lastAgentRouting: true,
|
|
835
|
+
allowAutoWrapUpExtension: false,
|
|
836
|
+
outdialEnabled: true,
|
|
837
|
+
dialPlanEnabled: true,
|
|
838
|
+
agentAvailableAfterOutdial: true,
|
|
839
|
+
outdialEntryPointId: 'entryPoint123',
|
|
840
|
+
consultToQueue: true,
|
|
841
|
+
viewableStatistics: {agentStats: true},
|
|
842
|
+
addressBookId: 'addressBook123',
|
|
843
|
+
outdialANIId: 'ani123',
|
|
844
|
+
loginVoiceOptions: ['option1', 'option2'],
|
|
845
|
+
dialPlans: ['dialPlan1', 'dialPlan2'],
|
|
846
|
+
agentDNValidation: 'validation123',
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
const mockDialPlanData = [
|
|
850
|
+
{id: 'dialPlan1', name: 'Plan 1'},
|
|
851
|
+
{id: 'dialPlan2', name: 'Plan 2'},
|
|
852
|
+
];
|
|
853
|
+
|
|
854
|
+
const mockTeamData = [
|
|
855
|
+
{id: 'team1', name: 'Support Team'},
|
|
856
|
+
{id: 'team2', name: 'Sales Team'},
|
|
857
|
+
];
|
|
858
|
+
|
|
859
|
+
const mockOrgInfo = {
|
|
860
|
+
tenantId: 'tenant123',
|
|
861
|
+
timezone: 'GMT',
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
const mockOrgSettings = {
|
|
865
|
+
campaignManagerEnabled: true,
|
|
866
|
+
webRtcEnabled: true,
|
|
867
|
+
maskSensitiveData: true,
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
const mockSiteInfo = {
|
|
871
|
+
id: "c6a5451f-5ba7-49a1-aee8-fbef70c19ece",
|
|
872
|
+
name: "Site-1",
|
|
873
|
+
multimediaProfileId: "c5888e6f-5661-4871-9936-cbcec7658d41",
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
const mockTenantData = {
|
|
877
|
+
timeoutDesktopInactivityEnabled: true,
|
|
878
|
+
timeoutDesktopInactivityMins: 15,
|
|
879
|
+
forceDefaultDn: true,
|
|
880
|
+
dnDefaultRegex: 'regexUS',
|
|
881
|
+
dnOtherRegex: 'regexOther',
|
|
882
|
+
privacyShieldVisible: true,
|
|
883
|
+
outdialEnabled: true,
|
|
884
|
+
endCallEnabled: true,
|
|
885
|
+
endConsultEnabled: true,
|
|
886
|
+
callVariablesSuppressed: false,
|
|
887
|
+
lostConnectionRecoveryTimeout: 30,
|
|
888
|
+
};
|
|
889
|
+
|
|
890
|
+
const mockURLMapping = [
|
|
891
|
+
{key: 'ACQUEON_API_URL', url: 'https://api.example.com'},
|
|
892
|
+
{key: 'ACQUEON_CONSOLE_URL', url: 'https://console.example.com'},
|
|
893
|
+
];
|
|
894
|
+
|
|
895
|
+
const mockAuxCodes = [
|
|
896
|
+
{id: 'aux1', type: 'WRAP_UP_CODE', name: 'Wrap Up Code 1'},
|
|
897
|
+
{id: 'aux2', type: 'IDLE_CODE', name: 'Idle Code 1'},
|
|
898
|
+
];
|
|
899
|
+
|
|
900
|
+
const parseAgentConfigsSpy = jest.spyOn(util, 'parseAgentConfigs');
|
|
901
|
+
agentConfigService.getUserUsingCI = jest.fn().mockResolvedValue(mockUserConfig);
|
|
902
|
+
agentConfigService.getOrgInfo = jest.fn().mockResolvedValue(mockOrgInfo);
|
|
903
|
+
agentConfigService.getOrganizationSetting = jest.fn().mockResolvedValue(mockOrgSettings);
|
|
904
|
+
agentConfigService.getSiteInfo = jest.fn().mockResolvedValue(mockSiteInfo);
|
|
905
|
+
agentConfigService.getTenantData = jest.fn().mockResolvedValue(mockTenantData);
|
|
906
|
+
agentConfigService.getURLMapping = jest.fn().mockResolvedValue(mockURLMapping);
|
|
907
|
+
agentConfigService.getAllAuxCodes = jest.fn().mockResolvedValue(mockAuxCodes);
|
|
908
|
+
agentConfigService.getDesktopProfileById = jest.fn().mockResolvedValue(mockAgentProfile);
|
|
909
|
+
agentConfigService.getDialPlanData = jest.fn().mockResolvedValue(mockDialPlanData);
|
|
910
|
+
agentConfigService.getAllTeams = jest.fn().mockResolvedValue(mockTeamData);
|
|
911
|
+
|
|
912
|
+
const result = await agentConfigService.getAgentConfig(mockOrgId, mockAgentId);
|
|
913
|
+
|
|
914
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith(`Fetched user data, userId: ${mockUserConfig.ciUserId}`, {
|
|
915
|
+
module: CONFIG_FILE_NAME,
|
|
916
|
+
method: 'getAgentConfig',
|
|
917
|
+
});
|
|
918
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith('Fetched all required data', {
|
|
919
|
+
module: CONFIG_FILE_NAME,
|
|
920
|
+
method: 'getAgentConfig',
|
|
921
|
+
});
|
|
922
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith('Parsing completed for agent-config', {
|
|
923
|
+
module: CONFIG_FILE_NAME,
|
|
924
|
+
method: 'getAgentConfig',
|
|
925
|
+
});
|
|
926
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith('Fetched configuration data successfully', {
|
|
927
|
+
module: CONFIG_FILE_NAME,
|
|
928
|
+
method: 'getAgentConfig',
|
|
929
|
+
});
|
|
930
|
+
expect(parseAgentConfigsSpy).toHaveBeenCalledTimes(1);
|
|
931
|
+
|
|
932
|
+
expect(parseAgentConfigsSpy).toHaveBeenCalledWith({
|
|
933
|
+
userData: mockUserConfig,
|
|
934
|
+
teamData: mockTeamData,
|
|
935
|
+
tenantData: mockTenantData,
|
|
936
|
+
orgInfoData: mockOrgInfo,
|
|
937
|
+
auxCodes: mockAuxCodes,
|
|
938
|
+
orgSettingsData: mockOrgSettings,
|
|
939
|
+
agentProfileData: mockAgentProfile,
|
|
940
|
+
dialPlanData: mockDialPlanData,
|
|
941
|
+
urlMapping: mockURLMapping,
|
|
942
|
+
multimediaProfileId: mockSiteInfo.multimediaProfileId
|
|
943
|
+
});
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
it('should throw an error if any of the API calls fail', async () => {
|
|
947
|
+
const mockAgentId = 'agent001';
|
|
948
|
+
const mockError = new Error('API call failed');
|
|
949
|
+
agentConfigService.getUserUsingCI = jest.fn().mockRejectedValue(mockError);
|
|
950
|
+
agentConfigService.getOrgInfo = jest.fn().mockResolvedValue({});
|
|
951
|
+
agentConfigService.getOrganizationSetting = jest.fn().mockResolvedValue({});
|
|
952
|
+
agentConfigService.getTenantData = jest.fn().mockResolvedValue({});
|
|
953
|
+
agentConfigService.getURLMapping = jest.fn().mockResolvedValue({});
|
|
954
|
+
agentConfigService.getAllAuxCodes = jest.fn().mockResolvedValue({});
|
|
955
|
+
agentConfigService.getDesktopProfileById = jest.fn().mockResolvedValue({});
|
|
956
|
+
agentConfigService.getDialPlanData = jest.fn().mockResolvedValue({});
|
|
957
|
+
agentConfigService.getAllTeams = jest.fn().mockResolvedValue({});
|
|
958
|
+
|
|
959
|
+
await expect(agentConfigService.getAgentConfig(mockOrgId, mockAgentId)).rejects.toThrow(
|
|
960
|
+
'API call failed'
|
|
961
|
+
);
|
|
962
|
+
});
|
|
963
|
+
});
|
|
964
|
+
|
|
965
|
+
describe('getQueues', () => {
|
|
966
|
+
const mockQueues = [
|
|
967
|
+
{id: 'queue1', name: 'Queue 1'},
|
|
968
|
+
{id: 'queue2', name: 'Queue 2'},
|
|
969
|
+
];
|
|
970
|
+
|
|
971
|
+
const mockError = new Error('API call failed');
|
|
972
|
+
|
|
973
|
+
beforeEach(() => {
|
|
974
|
+
jest.clearAllMocks();
|
|
975
|
+
});
|
|
976
|
+
|
|
977
|
+
it('should return a list of queues successfully', async () => {
|
|
978
|
+
const mockResponse = {statusCode: 200, body: {data: mockQueues}};
|
|
979
|
+
mockWebexRequest.request.mockResolvedValue(mockResponse);
|
|
980
|
+
|
|
981
|
+
const result = await agentConfigService.getQueues(mockOrgId, 0, 100, 'queue', 'id==someid');
|
|
982
|
+
|
|
983
|
+
expect(mockWebexRequest.request).toHaveBeenCalledWith({
|
|
984
|
+
service: mockWccAPIURL,
|
|
985
|
+
resource: `organization/${mockOrgId}/v2/contact-service-queue?page=0&pageSize=100&desktopProfileFilter=true&search=queue&filter=id==someid`,
|
|
986
|
+
method: 'GET',
|
|
987
|
+
});
|
|
988
|
+
expect(result).toEqual(mockQueues);
|
|
989
|
+
|
|
990
|
+
expect(LoggerProxy.info).toHaveBeenCalledWith('Fetching queue list', {
|
|
991
|
+
module: CONFIG_FILE_NAME,
|
|
992
|
+
method: 'getQueues',
|
|
993
|
+
});
|
|
994
|
+
expect(LoggerProxy.log).toHaveBeenCalledWith('getQueues API success.', {
|
|
995
|
+
module: CONFIG_FILE_NAME,
|
|
996
|
+
method: 'getQueues',
|
|
997
|
+
});
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
it('should throw an error if the API call fails', async () => {
|
|
1001
|
+
mockWebexRequest.request.mockRejectedValue(mockError);
|
|
1002
|
+
|
|
1003
|
+
await expect(agentConfigService.getQueues(mockOrgId, 0, 100)).rejects.toThrow(
|
|
1004
|
+
'API call failed'
|
|
1005
|
+
);
|
|
1006
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
1007
|
+
'getQueues API call failed with Error: API call failed',
|
|
1008
|
+
{module: CONFIG_FILE_NAME, method: 'getQueues'}
|
|
1009
|
+
);
|
|
1010
|
+
expect(mockWebexRequest.request).toHaveBeenCalledWith({
|
|
1011
|
+
service: mockWccAPIURL,
|
|
1012
|
+
resource: `organization/${mockOrgId}/v2/contact-service-queue?page=0&pageSize=100&desktopProfileFilter=true`,
|
|
1013
|
+
method: 'GET',
|
|
1014
|
+
});
|
|
1015
|
+
});
|
|
1016
|
+
|
|
1017
|
+
it('should throw an error if the API call returns a non-200 status code', async () => {
|
|
1018
|
+
const mockResponse = {statusCode: 500};
|
|
1019
|
+
mockWebexRequest.request.mockResolvedValue(mockResponse);
|
|
1020
|
+
|
|
1021
|
+
await expect(agentConfigService.getQueues(mockOrgId, 0, 100)).rejects.toThrow(
|
|
1022
|
+
'API call failed with 500'
|
|
1023
|
+
);
|
|
1024
|
+
expect(LoggerProxy.error).toHaveBeenCalledWith(
|
|
1025
|
+
'getQueues API call failed with Error: API call failed with 500',
|
|
1026
|
+
{module: CONFIG_FILE_NAME, method: 'getQueues'}
|
|
1027
|
+
);
|
|
1028
|
+
expect(mockWebexRequest.request).toHaveBeenCalledWith({
|
|
1029
|
+
service: mockWccAPIURL,
|
|
1030
|
+
resource: `organization/${mockOrgId}/v2/contact-service-queue?page=0&pageSize=100&desktopProfileFilter=true`,
|
|
1031
|
+
method: 'GET',
|
|
1032
|
+
});
|
|
1033
|
+
});
|
|
1034
|
+
});
|
|
1035
|
+
});
|