@webex/calling 3.12.0-next.5 → 3.12.0-next.50

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.
Files changed (212) hide show
  1. package/dist/CallingClient/CallingClient.js +506 -223
  2. package/dist/CallingClient/CallingClient.js.map +1 -1
  3. package/dist/CallingClient/CallingClient.test.js +236 -77
  4. package/dist/CallingClient/CallingClient.test.js.map +1 -1
  5. package/dist/CallingClient/calling/call.js +589 -445
  6. package/dist/CallingClient/calling/call.js.map +1 -1
  7. package/dist/CallingClient/calling/call.test.js +695 -445
  8. package/dist/CallingClient/calling/call.test.js.map +1 -1
  9. package/dist/CallingClient/calling/callManager.js +53 -30
  10. package/dist/CallingClient/calling/callManager.js.map +1 -1
  11. package/dist/CallingClient/calling/callManager.test.js +35 -0
  12. package/dist/CallingClient/calling/callManager.test.js.map +1 -1
  13. package/dist/CallingClient/calling/types.js +2 -0
  14. package/dist/CallingClient/calling/types.js.map +1 -1
  15. package/dist/CallingClient/constants.js +27 -3
  16. package/dist/CallingClient/constants.js.map +1 -1
  17. package/dist/CallingClient/line/index.js +4 -1
  18. package/dist/CallingClient/line/index.js.map +1 -1
  19. package/dist/CallingClient/line/line.test.js +16 -1
  20. package/dist/CallingClient/line/line.test.js.map +1 -1
  21. package/dist/CallingClient/registration/register.js +714 -407
  22. package/dist/CallingClient/registration/register.js.map +1 -1
  23. package/dist/CallingClient/registration/register.test.js +311 -58
  24. package/dist/CallingClient/registration/register.test.js.map +1 -1
  25. package/dist/CallingClient/registration/types.js.map +1 -1
  26. package/dist/CallingClient/registration/webWorker.js +41 -104
  27. package/dist/CallingClient/registration/webWorker.js.map +1 -1
  28. package/dist/CallingClient/registration/webWorker.test.js +39 -153
  29. package/dist/CallingClient/registration/webWorker.test.js.map +1 -1
  30. package/dist/CallingClient/registration/webWorkerStr.js +1 -1
  31. package/dist/CallingClient/registration/webWorkerStr.js.map +1 -1
  32. package/dist/CallingClient/types.js.map +1 -1
  33. package/dist/CallingClient/utils/constants.js +58 -0
  34. package/dist/CallingClient/utils/constants.js.map +1 -0
  35. package/dist/CallingClient/utils/index.js +63 -0
  36. package/dist/CallingClient/utils/index.js.map +1 -0
  37. package/dist/CallingClient/utils/mobiusSocketMapper.js +122 -0
  38. package/dist/CallingClient/utils/mobiusSocketMapper.js.map +1 -0
  39. package/dist/CallingClient/utils/mobiusSocketMapper.test.js +221 -0
  40. package/dist/CallingClient/utils/mobiusSocketMapper.test.js.map +1 -0
  41. package/dist/CallingClient/utils/request.js +415 -0
  42. package/dist/CallingClient/utils/request.js.map +1 -0
  43. package/dist/CallingClient/utils/request.test.js +968 -0
  44. package/dist/CallingClient/utils/request.test.js.map +1 -0
  45. package/dist/CallingClient/utils/types.js +7 -0
  46. package/dist/CallingClient/utils/types.js.map +1 -0
  47. package/dist/CallingClient/utils/wsFeatureFlag.js +70 -0
  48. package/dist/CallingClient/utils/wsFeatureFlag.js.map +1 -0
  49. package/dist/CallingClient/utils/wsFeatureFlag.test.js +139 -0
  50. package/dist/CallingClient/utils/wsFeatureFlag.test.js.map +1 -0
  51. package/dist/Contacts/ContactsClient.js +13 -11
  52. package/dist/Contacts/ContactsClient.js.map +1 -1
  53. package/dist/Contacts/ContactsClient.test.js +3 -8
  54. package/dist/Contacts/ContactsClient.test.js.map +1 -1
  55. package/dist/Events/types.js +11 -11
  56. package/dist/Events/types.js.map +1 -1
  57. package/dist/Metrics/index.js +63 -2
  58. package/dist/Metrics/index.js.map +1 -1
  59. package/dist/Metrics/index.test.js +357 -1
  60. package/dist/Metrics/index.test.js.map +1 -1
  61. package/dist/Metrics/types.js +19 -1
  62. package/dist/Metrics/types.js.map +1 -1
  63. package/dist/SDKConnector/types.js.map +1 -1
  64. package/dist/common/Utils.js +138 -44
  65. package/dist/common/Utils.js.map +1 -1
  66. package/dist/common/testUtil.js +8 -4
  67. package/dist/common/testUtil.js.map +1 -1
  68. package/dist/common/types.js +2 -0
  69. package/dist/common/types.js.map +1 -1
  70. package/dist/index.js +12 -0
  71. package/dist/index.js.map +1 -1
  72. package/dist/mobius-socket/config.js +24 -0
  73. package/dist/mobius-socket/config.js.map +1 -0
  74. package/dist/mobius-socket/errors.js +143 -0
  75. package/dist/mobius-socket/errors.js.map +1 -0
  76. package/dist/mobius-socket/errors.test.js +20 -0
  77. package/dist/mobius-socket/errors.test.js.map +1 -0
  78. package/dist/mobius-socket/index.js +57 -0
  79. package/dist/mobius-socket/index.js.map +1 -0
  80. package/dist/mobius-socket/mobius-socket-events.test.js +492 -0
  81. package/dist/mobius-socket/mobius-socket-events.test.js.map +1 -0
  82. package/dist/mobius-socket/mobius-socket.js +849 -0
  83. package/dist/mobius-socket/mobius-socket.js.map +1 -0
  84. package/dist/mobius-socket/mobius-socket.test.js +1898 -0
  85. package/dist/mobius-socket/mobius-socket.test.js.map +1 -0
  86. package/dist/mobius-socket/socket/constants.js +55 -0
  87. package/dist/mobius-socket/socket/constants.js.map +1 -0
  88. package/dist/mobius-socket/socket/index.js +15 -0
  89. package/dist/mobius-socket/socket/index.js.map +1 -0
  90. package/dist/mobius-socket/socket/socket-base.js +604 -0
  91. package/dist/mobius-socket/socket/socket-base.js.map +1 -0
  92. package/dist/mobius-socket/socket/socket.js +19 -0
  93. package/dist/mobius-socket/socket/socket.js.map +1 -0
  94. package/dist/mobius-socket/socket/socket.shim.js +26 -0
  95. package/dist/mobius-socket/socket/socket.shim.js.map +1 -0
  96. package/dist/mobius-socket/socket/types.js +7 -0
  97. package/dist/mobius-socket/socket/types.js.map +1 -0
  98. package/dist/mobius-socket/socket.test.js +727 -0
  99. package/dist/mobius-socket/socket.test.js.map +1 -0
  100. package/dist/mobius-socket/test/mocha-helpers.js +23 -0
  101. package/dist/mobius-socket/test/mocha-helpers.js.map +1 -0
  102. package/dist/mobius-socket/test/promise-tick.js +28 -0
  103. package/dist/mobius-socket/test/promise-tick.js.map +1 -0
  104. package/dist/mobius-socket/types.js +7 -0
  105. package/dist/mobius-socket/types.js.map +1 -0
  106. package/dist/module/CallingClient/CallingClient.js +148 -10
  107. package/dist/module/CallingClient/calling/call.js +177 -61
  108. package/dist/module/CallingClient/calling/callManager.js +27 -7
  109. package/dist/module/CallingClient/calling/types.js +2 -0
  110. package/dist/module/CallingClient/constants.js +23 -0
  111. package/dist/module/CallingClient/line/index.js +2 -2
  112. package/dist/module/CallingClient/registration/register.js +236 -63
  113. package/dist/module/CallingClient/registration/webWorker.js +42 -61
  114. package/dist/module/CallingClient/registration/webWorkerStr.js +47 -82
  115. package/dist/module/CallingClient/utils/constants.js +36 -0
  116. package/dist/module/CallingClient/utils/index.js +5 -0
  117. package/dist/module/CallingClient/utils/mobiusSocketMapper.js +72 -0
  118. package/dist/module/CallingClient/utils/request.js +204 -0
  119. package/dist/module/CallingClient/utils/types.js +1 -0
  120. package/dist/module/CallingClient/utils/wsFeatureFlag.js +41 -0
  121. package/dist/module/Contacts/ContactsClient.js +1 -1
  122. package/dist/module/Events/types.js +4 -10
  123. package/dist/module/Metrics/index.js +48 -1
  124. package/dist/module/Metrics/types.js +18 -0
  125. package/dist/module/common/Utils.js +52 -12
  126. package/dist/module/common/testUtil.js +5 -1
  127. package/dist/module/common/types.js +2 -0
  128. package/dist/module/index.js +1 -1
  129. package/dist/module/mobius-socket/config.js +15 -0
  130. package/dist/module/mobius-socket/errors.js +58 -0
  131. package/dist/module/mobius-socket/index.js +24 -0
  132. package/dist/module/mobius-socket/mobius-socket.js +593 -0
  133. package/dist/module/mobius-socket/socket/constants.js +26 -0
  134. package/dist/module/mobius-socket/socket/index.js +4 -0
  135. package/dist/module/mobius-socket/socket/socket-base.js +368 -0
  136. package/dist/module/mobius-socket/socket/socket.js +9 -0
  137. package/dist/module/mobius-socket/socket/socket.shim.js +12 -0
  138. package/dist/module/mobius-socket/socket/types.js +1 -0
  139. package/dist/module/mobius-socket/types.js +1 -0
  140. package/dist/types/CallingClient/CallingClient.d.ts +8 -0
  141. package/dist/types/CallingClient/CallingClient.d.ts.map +1 -1
  142. package/dist/types/CallingClient/calling/call.d.ts +12 -0
  143. package/dist/types/CallingClient/calling/call.d.ts.map +1 -1
  144. package/dist/types/CallingClient/calling/callManager.d.ts +3 -2
  145. package/dist/types/CallingClient/calling/callManager.d.ts.map +1 -1
  146. package/dist/types/CallingClient/calling/types.d.ts +34 -9
  147. package/dist/types/CallingClient/calling/types.d.ts.map +1 -1
  148. package/dist/types/CallingClient/constants.d.ts +23 -0
  149. package/dist/types/CallingClient/constants.d.ts.map +1 -1
  150. package/dist/types/CallingClient/line/index.d.ts +1 -1
  151. package/dist/types/CallingClient/line/index.d.ts.map +1 -1
  152. package/dist/types/CallingClient/registration/register.d.ts +7 -1
  153. package/dist/types/CallingClient/registration/register.d.ts.map +1 -1
  154. package/dist/types/CallingClient/registration/types.d.ts +4 -2
  155. package/dist/types/CallingClient/registration/types.d.ts.map +1 -1
  156. package/dist/types/CallingClient/registration/webWorker.d.ts.map +1 -1
  157. package/dist/types/CallingClient/registration/webWorkerStr.d.ts +1 -1
  158. package/dist/types/CallingClient/registration/webWorkerStr.d.ts.map +1 -1
  159. package/dist/types/CallingClient/types.d.ts +1 -0
  160. package/dist/types/CallingClient/types.d.ts.map +1 -1
  161. package/dist/types/CallingClient/utils/constants.d.ts +35 -0
  162. package/dist/types/CallingClient/utils/constants.d.ts.map +1 -0
  163. package/dist/types/CallingClient/utils/index.d.ts +6 -0
  164. package/dist/types/CallingClient/utils/index.d.ts.map +1 -0
  165. package/dist/types/CallingClient/utils/mobiusSocketMapper.d.ts +5 -0
  166. package/dist/types/CallingClient/utils/mobiusSocketMapper.d.ts.map +1 -0
  167. package/dist/types/CallingClient/utils/request.d.ts +27 -0
  168. package/dist/types/CallingClient/utils/request.d.ts.map +1 -0
  169. package/dist/types/CallingClient/utils/types.d.ts +34 -0
  170. package/dist/types/CallingClient/utils/types.d.ts.map +1 -0
  171. package/dist/types/CallingClient/utils/wsFeatureFlag.d.ts +4 -0
  172. package/dist/types/CallingClient/utils/wsFeatureFlag.d.ts.map +1 -0
  173. package/dist/types/Events/types.d.ts +14 -13
  174. package/dist/types/Events/types.d.ts.map +1 -1
  175. package/dist/types/Metrics/index.d.ts.map +1 -1
  176. package/dist/types/Metrics/types.d.ts +19 -2
  177. package/dist/types/Metrics/types.d.ts.map +1 -1
  178. package/dist/types/SDKConnector/types.d.ts +24 -0
  179. package/dist/types/SDKConnector/types.d.ts.map +1 -1
  180. package/dist/types/common/Utils.d.ts +9 -2
  181. package/dist/types/common/Utils.d.ts.map +1 -1
  182. package/dist/types/common/testUtil.d.ts +4 -1
  183. package/dist/types/common/testUtil.d.ts.map +1 -1
  184. package/dist/types/common/types.d.ts +3 -0
  185. package/dist/types/common/types.d.ts.map +1 -1
  186. package/dist/types/index.d.ts +1 -1
  187. package/dist/types/index.d.ts.map +1 -1
  188. package/dist/types/mobius-socket/config.d.ts +17 -0
  189. package/dist/types/mobius-socket/config.d.ts.map +1 -0
  190. package/dist/types/mobius-socket/errors.d.ts +32 -0
  191. package/dist/types/mobius-socket/errors.d.ts.map +1 -0
  192. package/dist/types/mobius-socket/index.d.ts +14 -0
  193. package/dist/types/mobius-socket/index.d.ts.map +1 -0
  194. package/dist/types/mobius-socket/mobius-socket.d.ts +48 -0
  195. package/dist/types/mobius-socket/mobius-socket.d.ts.map +1 -0
  196. package/dist/types/mobius-socket/socket/constants.d.ts +27 -0
  197. package/dist/types/mobius-socket/socket/constants.d.ts.map +1 -0
  198. package/dist/types/mobius-socket/socket/index.d.ts +5 -0
  199. package/dist/types/mobius-socket/socket/index.d.ts.map +1 -0
  200. package/dist/types/mobius-socket/socket/socket-base.d.ts +43 -0
  201. package/dist/types/mobius-socket/socket/socket-base.d.ts.map +1 -0
  202. package/dist/types/mobius-socket/socket/socket.d.ts +6 -0
  203. package/dist/types/mobius-socket/socket/socket.d.ts.map +1 -0
  204. package/dist/types/mobius-socket/socket/socket.shim.d.ts +6 -0
  205. package/dist/types/mobius-socket/socket/socket.shim.d.ts.map +1 -0
  206. package/dist/types/mobius-socket/socket/types.d.ts +61 -0
  207. package/dist/types/mobius-socket/socket/types.d.ts.map +1 -0
  208. package/dist/types/mobius-socket/types.d.ts +21 -0
  209. package/dist/types/mobius-socket/types.d.ts.map +1 -0
  210. package/package.json +20 -5
  211. package/src/mobius-socket/socket/socket.shim.ts +22 -0
  212. package/src/mobius-socket/socket/socket.ts +14 -0
@@ -0,0 +1,968 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
4
+ var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
5
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray"));
6
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
7
+ var _uuid = require("uuid");
8
+ var _testUtil = require("../../common/testUtil");
9
+ var _types = require("../../common/types");
10
+ var _Logger = _interopRequireDefault(require("../../Logger"));
11
+ var _request = require("./request");
12
+ var _mobiusSocket = require("../../mobius-socket");
13
+ var _Metrics = require("../../Metrics");
14
+ var _types2 = require("../../Metrics/types");
15
+ var _wsFeatureFlag = require("./wsFeatureFlag");
16
+ var _constants = require("./constants");
17
+ // Mock dependencies
18
+ jest.mock('../../mobius-socket', function () {
19
+ return {
20
+ getMobiusSocketInstance: jest.fn()
21
+ };
22
+ });
23
+ jest.mock('../../Metrics', function () {
24
+ return {
25
+ getMetricManager: jest.fn()
26
+ };
27
+ });
28
+ jest.mock('./wsFeatureFlag', function () {
29
+ return {
30
+ isMobiusWssEnabled: jest.fn()
31
+ };
32
+ });
33
+ jest.mock('uuid', function () {
34
+ return {
35
+ v4: jest.fn()
36
+ };
37
+ });
38
+ describe('APIRequest', function () {
39
+ var webex;
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
+ var mockMobiusSocket;
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ var mockMetricManager;
44
+ var infoSpy;
45
+ var logSpy;
46
+ var warnSpy;
47
+ var errorSpy;
48
+ beforeEach(function () {
49
+ _request.APIRequest.resetInstance();
50
+ webex = (0, _testUtil.getTestUtilsWebex)();
51
+ jest.clearAllMocks();
52
+ mockMobiusSocket = {
53
+ connect: jest.fn().mockResolvedValue(undefined),
54
+ disconnect: jest.fn().mockResolvedValue(undefined),
55
+ sendWssRequest: jest.fn().mockResolvedValue({
56
+ statusCode: 200,
57
+ trackingId: 'test-tracking-id',
58
+ data: {
59
+ deviceId: 'test-device-id'
60
+ }
61
+ }),
62
+ isConnected: jest.fn().mockReturnValue(false),
63
+ getConnectedWebSocketUrl: jest.fn().mockReturnValue('wss://test.webex.com'),
64
+ on: jest.fn(),
65
+ off: jest.fn()
66
+ };
67
+ mockMetricManager = {
68
+ submitMobiusSocketMetric: jest.fn()
69
+ };
70
+ _mobiusSocket.getMobiusSocketInstance.mockReturnValue(mockMobiusSocket);
71
+ _Metrics.getMetricManager.mockReturnValue(mockMetricManager);
72
+ _wsFeatureFlag.isMobiusWssEnabled.mockReturnValue(false);
73
+ _uuid.v4.mockReturnValue('mock-uuid-12345');
74
+ infoSpy = jest.spyOn(_Logger.default, 'info');
75
+ logSpy = jest.spyOn(_Logger.default, 'log');
76
+ warnSpy = jest.spyOn(_Logger.default, 'warn');
77
+ errorSpy = jest.spyOn(_Logger.default, 'error');
78
+ });
79
+ afterEach(function () {
80
+ jest.clearAllMocks();
81
+ });
82
+ describe('Constructor and singleton pattern', function () {
83
+ it('should create instance with webex config and HTTP transport', function () {
84
+ var apiRequest = _request.APIRequest.getInstance({
85
+ webex: webex
86
+ });
87
+ expect(apiRequest).toBeDefined();
88
+ expect(_mobiusSocket.getMobiusSocketInstance).toHaveBeenCalledWith(webex);
89
+ expect(_Metrics.getMetricManager).toHaveBeenCalledWith(webex);
90
+ expect(_wsFeatureFlag.isMobiusWssEnabled).toHaveBeenCalledWith(webex);
91
+ expect(infoSpy).toHaveBeenCalledWith('APIRequest initialized with transport: HTTP', {
92
+ file: 'REQUEST',
93
+ method: 'constructor'
94
+ });
95
+ });
96
+ it('should create instance with webex config and WSS transport when feature flag enabled', function () {
97
+ _wsFeatureFlag.isMobiusWssEnabled.mockReturnValue(true);
98
+ var apiRequest = _request.APIRequest.getInstance({
99
+ webex: webex
100
+ });
101
+ expect(apiRequest).toBeDefined();
102
+ expect(infoSpy).toHaveBeenCalledWith('APIRequest initialized with transport: WSS', {
103
+ file: 'REQUEST',
104
+ method: 'constructor'
105
+ });
106
+ });
107
+ it('should throw error if webex is missing from config', function () {
108
+ expect(function () {
109
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
110
+ _request.APIRequest.getInstance({
111
+ webex: undefined
112
+ });
113
+ }).toThrow('WebexSDK instance is required');
114
+ expect(errorSpy).toHaveBeenCalledWith('APIRequest instantiation failed: WebexSDK instance is required', {
115
+ file: 'REQUEST',
116
+ method: 'constructor'
117
+ });
118
+ });
119
+ it('should return same instance on subsequent getInstance() calls', function () {
120
+ var instance1 = _request.APIRequest.getInstance({
121
+ webex: webex
122
+ });
123
+ var instance2 = _request.APIRequest.getInstance({
124
+ webex: webex
125
+ });
126
+ expect(instance1).toBe(instance2);
127
+ });
128
+ it('should clear singleton when resetInstance() is called', function () {
129
+ var instance1 = _request.APIRequest.getInstance({
130
+ webex: webex
131
+ });
132
+ _request.APIRequest.resetInstance();
133
+ var instance2 = _request.APIRequest.getInstance({
134
+ webex: webex
135
+ });
136
+ expect(instance1).not.toBe(instance2);
137
+ });
138
+ });
139
+ describe('createAPIRequest factory', function () {
140
+ it('should create APIRequest instance using factory function', function () {
141
+ var apiRequest = (0, _request.createAPIRequest)({
142
+ webex: webex
143
+ });
144
+ expect(apiRequest).toBeDefined();
145
+ expect(apiRequest).toBeInstanceOf(_request.APIRequest);
146
+ });
147
+ });
148
+ describe('isSocketEnabled', function () {
149
+ it('should return false when WSS is disabled', function () {
150
+ _wsFeatureFlag.isMobiusWssEnabled.mockReturnValue(false);
151
+ var apiRequest = _request.APIRequest.getInstance({
152
+ webex: webex
153
+ });
154
+ var result = apiRequest.isSocketEnabled();
155
+ expect(result).toBe(false);
156
+ });
157
+ it('should return true when WSS is enabled', function () {
158
+ _wsFeatureFlag.isMobiusWssEnabled.mockReturnValue(true);
159
+ var apiRequest = _request.APIRequest.getInstance({
160
+ webex: webex
161
+ });
162
+ var result = apiRequest.isSocketEnabled();
163
+ expect(result).toBe(true);
164
+ });
165
+ });
166
+ describe('isSocketConnected', function () {
167
+ it.each([true, false])('should delegate to the Mobius socket isConnected() and return %s', function (connected) {
168
+ mockMobiusSocket.isConnected.mockReturnValue(connected);
169
+ var apiRequest = _request.APIRequest.getInstance({
170
+ webex: webex
171
+ });
172
+ expect(apiRequest.isSocketConnected()).toBe(connected);
173
+ expect(mockMobiusSocket.isConnected).toHaveBeenCalled();
174
+ });
175
+ });
176
+ describe('connectToMobiusSocket', function () {
177
+ it('should return immediately if socket is already connected', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee() {
178
+ var apiRequest, result;
179
+ return _regenerator.default.wrap(function (_context) {
180
+ while (1) switch (_context.prev = _context.next) {
181
+ case 0:
182
+ mockMobiusSocket.isConnected.mockReturnValue(true);
183
+ mockMobiusSocket.getConnectedWebSocketUrl.mockReturnValue('wss://existing.webex.com');
184
+ apiRequest = _request.APIRequest.getInstance({
185
+ webex: webex
186
+ });
187
+ _context.next = 1;
188
+ return apiRequest.connectToMobiusSocket('wss://test.webex.com');
189
+ case 1:
190
+ result = _context.sent;
191
+ expect(result).toBe('wss://existing.webex.com');
192
+ expect(mockMobiusSocket.connect).not.toHaveBeenCalled();
193
+ expect(infoSpy).toHaveBeenCalledWith('Mobius WebSocket already connected', {
194
+ file: 'REQUEST',
195
+ method: 'connectToMobiusSocket'
196
+ });
197
+ expect(mockMetricManager.submitMobiusSocketMetric).not.toHaveBeenCalled();
198
+ case 2:
199
+ case "end":
200
+ return _context.stop();
201
+ }
202
+ }, _callee);
203
+ })));
204
+ it('should initiate new connection if not connected', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2() {
205
+ var apiRequest, wssUrl, result;
206
+ return _regenerator.default.wrap(function (_context2) {
207
+ while (1) switch (_context2.prev = _context2.next) {
208
+ case 0:
209
+ mockMobiusSocket.isConnected.mockReturnValue(false);
210
+ apiRequest = _request.APIRequest.getInstance({
211
+ webex: webex
212
+ });
213
+ wssUrl = 'wss://test.webex.com/api/v1';
214
+ _context2.next = 1;
215
+ return apiRequest.connectToMobiusSocket(wssUrl);
216
+ case 1:
217
+ result = _context2.sent;
218
+ expect(mockMobiusSocket.connect).toHaveBeenCalledWith(wssUrl);
219
+ expect(result).toBe(wssUrl);
220
+ expect(infoSpy).toHaveBeenCalledWith('Mobius WebSocket not connected, initiating connection', {
221
+ file: 'REQUEST',
222
+ method: 'connectToMobiusSocket'
223
+ });
224
+ case 2:
225
+ case "end":
226
+ return _context2.stop();
227
+ }
228
+ }, _callee2);
229
+ })));
230
+ it('should submit success metric on successful connection', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3() {
231
+ var apiRequest, wssUrl;
232
+ return _regenerator.default.wrap(function (_context3) {
233
+ while (1) switch (_context3.prev = _context3.next) {
234
+ case 0:
235
+ mockMobiusSocket.isConnected.mockReturnValue(false);
236
+ apiRequest = _request.APIRequest.getInstance({
237
+ webex: webex
238
+ });
239
+ wssUrl = 'wss://mobius.webex.com/api/v1';
240
+ _context3.next = 1;
241
+ return apiRequest.connectToMobiusSocket(wssUrl);
242
+ case 1:
243
+ expect(logSpy).toHaveBeenCalledWith('Mobius WebSocket connected successfully', {
244
+ file: 'REQUEST',
245
+ method: 'connectToMobiusSocket'
246
+ });
247
+ expect(mockMetricManager.submitMobiusSocketMetric).toHaveBeenCalledWith(_types2.METRIC_EVENT.MOBIUS_SOCKET, _types2.MOBIUS_SOCKET_ACTION.CONNECT, _types2.METRIC_TYPE.BEHAVIORAL, wssUrl);
248
+ case 2:
249
+ case "end":
250
+ return _context3.stop();
251
+ }
252
+ }, _callee3);
253
+ })));
254
+ it('should throw normalized error on connection failure', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4() {
255
+ var connectionError, apiRequest, wssUrl;
256
+ return _regenerator.default.wrap(function (_context4) {
257
+ while (1) switch (_context4.prev = _context4.next) {
258
+ case 0:
259
+ connectionError = {
260
+ statusCode: 503,
261
+ statusMessage: 'Service Unavailable',
262
+ trackingId: 'error-tracking-id',
263
+ response: {
264
+ statusCode: 503,
265
+ trackingId: 'error-tracking-id',
266
+ data: {
267
+ error: 'Connection failed'
268
+ },
269
+ metadata: {
270
+ 'x-error': 'true'
271
+ }
272
+ }
273
+ };
274
+ mockMobiusSocket.isConnected.mockReturnValue(false);
275
+ mockMobiusSocket.connect.mockRejectedValue(connectionError);
276
+ apiRequest = _request.APIRequest.getInstance({
277
+ webex: webex
278
+ });
279
+ wssUrl = 'wss://mobius.webex.com/api/v1';
280
+ _context4.next = 1;
281
+ return expect(apiRequest.connectToMobiusSocket(wssUrl)).rejects.toEqual({
282
+ statusCode: 503,
283
+ body: {
284
+ error: 'Connection failed'
285
+ },
286
+ headers: {
287
+ trackingid: 'error-tracking-id',
288
+ 'x-error': 'true'
289
+ }
290
+ });
291
+ case 1:
292
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Mobius WebSocket connection failed'), {
293
+ file: 'REQUEST',
294
+ method: 'connectToMobiusSocket'
295
+ });
296
+ expect(mockMetricManager.submitMobiusSocketMetric).toHaveBeenCalledWith(_types2.METRIC_EVENT.MOBIUS_SOCKET_ERROR, _types2.MOBIUS_SOCKET_ACTION.CONNECT, _types2.METRIC_TYPE.BEHAVIORAL, wssUrl, undefined, expect.any(String));
297
+ case 2:
298
+ case "end":
299
+ return _context4.stop();
300
+ }
301
+ }, _callee4);
302
+ })));
303
+ it('should handle connection error with minimal error object', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5() {
304
+ var minimalError, apiRequest;
305
+ return _regenerator.default.wrap(function (_context5) {
306
+ while (1) switch (_context5.prev = _context5.next) {
307
+ case 0:
308
+ minimalError = {
309
+ statusCode: 500
310
+ };
311
+ mockMobiusSocket.isConnected.mockReturnValue(false);
312
+ mockMobiusSocket.connect.mockRejectedValue(minimalError);
313
+ apiRequest = _request.APIRequest.getInstance({
314
+ webex: webex
315
+ });
316
+ _context5.next = 1;
317
+ return expect(apiRequest.connectToMobiusSocket('wss://test.webex.com')).rejects.toEqual({
318
+ statusCode: 500,
319
+ body: undefined,
320
+ headers: {
321
+ trackingid: ''
322
+ }
323
+ });
324
+ case 1:
325
+ case "end":
326
+ return _context5.stop();
327
+ }
328
+ }, _callee5);
329
+ })));
330
+ });
331
+ describe('disconnectFromMobiusSocket', function () {
332
+ it('should disconnect successfully', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6() {
333
+ var apiRequest;
334
+ return _regenerator.default.wrap(function (_context6) {
335
+ while (1) switch (_context6.prev = _context6.next) {
336
+ case 0:
337
+ apiRequest = _request.APIRequest.getInstance({
338
+ webex: webex
339
+ });
340
+ _context6.next = 1;
341
+ return apiRequest.disconnectFromMobiusSocket();
342
+ case 1:
343
+ expect(mockMobiusSocket.disconnect).toHaveBeenCalledWith(undefined);
344
+ expect(infoSpy).toHaveBeenCalledWith('Disconnecting from Mobius WebSocket', {
345
+ file: 'REQUEST',
346
+ method: 'disconnectFromMobiusSocket'
347
+ });
348
+ expect(logSpy).toHaveBeenCalledWith('Mobius WebSocket disconnected successfully', {
349
+ file: 'REQUEST',
350
+ method: 'disconnectFromMobiusSocket'
351
+ });
352
+ case 2:
353
+ case "end":
354
+ return _context6.stop();
355
+ }
356
+ }, _callee6);
357
+ })));
358
+ it('should submit success metric after disconnect', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee7() {
359
+ var apiRequest;
360
+ return _regenerator.default.wrap(function (_context7) {
361
+ while (1) switch (_context7.prev = _context7.next) {
362
+ case 0:
363
+ apiRequest = _request.APIRequest.getInstance({
364
+ webex: webex
365
+ });
366
+ _context7.next = 1;
367
+ return apiRequest.disconnectFromMobiusSocket();
368
+ case 1:
369
+ expect(mockMetricManager.submitMobiusSocketMetric).toHaveBeenCalledWith(_types2.METRIC_EVENT.MOBIUS_SOCKET, _types2.MOBIUS_SOCKET_ACTION.DISCONNECT, _types2.METRIC_TYPE.BEHAVIORAL, 'wss://test.webex.com');
370
+ case 2:
371
+ case "end":
372
+ return _context7.stop();
373
+ }
374
+ }, _callee7);
375
+ })));
376
+ it('should disconnect with custom options', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee8() {
377
+ var apiRequest, options;
378
+ return _regenerator.default.wrap(function (_context8) {
379
+ while (1) switch (_context8.prev = _context8.next) {
380
+ case 0:
381
+ apiRequest = _request.APIRequest.getInstance({
382
+ webex: webex
383
+ });
384
+ options = {
385
+ code: 1000,
386
+ reason: 'Normal closure'
387
+ };
388
+ _context8.next = 1;
389
+ return apiRequest.disconnectFromMobiusSocket(options);
390
+ case 1:
391
+ expect(mockMobiusSocket.disconnect).toHaveBeenCalledWith(options);
392
+ case 2:
393
+ case "end":
394
+ return _context8.stop();
395
+ }
396
+ }, _callee8);
397
+ })));
398
+ it('should handle disconnect error silently and log warning', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee9() {
399
+ var apiRequest;
400
+ return _regenerator.default.wrap(function (_context9) {
401
+ while (1) switch (_context9.prev = _context9.next) {
402
+ case 0:
403
+ mockMobiusSocket.disconnect.mockRejectedValue(new Error('Disconnect failed'));
404
+ apiRequest = _request.APIRequest.getInstance({
405
+ webex: webex
406
+ });
407
+ _context9.next = 1;
408
+ return expect(apiRequest.disconnectFromMobiusSocket()).resolves.not.toThrow();
409
+ case 1:
410
+ expect(warnSpy).toHaveBeenCalledWith('Mobius WebSocket disconnection failed: Error: Disconnect failed', {
411
+ file: 'REQUEST',
412
+ method: 'disconnectFromMobiusSocket'
413
+ });
414
+ case 2:
415
+ case "end":
416
+ return _context9.stop();
417
+ }
418
+ }, _callee9);
419
+ })));
420
+ it('should submit error metric on disconnect failure', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee0() {
421
+ var apiRequest;
422
+ return _regenerator.default.wrap(function (_context0) {
423
+ while (1) switch (_context0.prev = _context0.next) {
424
+ case 0:
425
+ mockMobiusSocket.disconnect.mockRejectedValue(new Error('Disconnect failed'));
426
+ apiRequest = _request.APIRequest.getInstance({
427
+ webex: webex
428
+ });
429
+ _context0.next = 1;
430
+ return apiRequest.disconnectFromMobiusSocket();
431
+ case 1:
432
+ expect(mockMetricManager.submitMobiusSocketMetric).toHaveBeenCalledWith(_types2.METRIC_EVENT.MOBIUS_SOCKET_ERROR, _types2.MOBIUS_SOCKET_ACTION.DISCONNECT, _types2.METRIC_TYPE.BEHAVIORAL, 'wss://test.webex.com', undefined, 'Error: Disconnect failed');
433
+ case 2:
434
+ case "end":
435
+ return _context0.stop();
436
+ }
437
+ }, _callee0);
438
+ })));
439
+ });
440
+ describe('makeRequest - HTTP transport', function () {
441
+ it('should route through webex.request when WSS is disabled', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee1() {
442
+ var apiRequest, requestOptions, expectedResponse, result;
443
+ return _regenerator.default.wrap(function (_context1) {
444
+ while (1) switch (_context1.prev = _context1.next) {
445
+ case 0:
446
+ _wsFeatureFlag.isMobiusWssEnabled.mockReturnValue(false);
447
+ apiRequest = _request.APIRequest.getInstance({
448
+ webex: webex
449
+ });
450
+ requestOptions = {
451
+ uri: '/api/v1/calling/web/device',
452
+ method: _types.HTTP_METHODS.POST,
453
+ body: {
454
+ userId: 'user-123'
455
+ }
456
+ };
457
+ expectedResponse = {
458
+ statusCode: 200,
459
+ body: {
460
+ deviceId: 'device-456'
461
+ }
462
+ };
463
+ webex.request.mockResolvedValue(expectedResponse);
464
+ _context1.next = 1;
465
+ return apiRequest.makeRequest(requestOptions);
466
+ case 1:
467
+ result = _context1.sent;
468
+ expect(webex.request).toHaveBeenCalledWith(requestOptions);
469
+ expect(result).toEqual(expectedResponse);
470
+ expect(infoSpy).toHaveBeenCalledWith('Dispatching request via HTTP ', {
471
+ file: 'REQUEST',
472
+ method: 'makeRequest'
473
+ });
474
+ case 2:
475
+ case "end":
476
+ return _context1.stop();
477
+ }
478
+ }, _callee1);
479
+ })));
480
+ it('should pass request options unchanged to webex.request', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee10() {
481
+ var apiRequest, requestOptions;
482
+ return _regenerator.default.wrap(function (_context10) {
483
+ while (1) switch (_context10.prev = _context10.next) {
484
+ case 0:
485
+ _wsFeatureFlag.isMobiusWssEnabled.mockReturnValue(false);
486
+ apiRequest = _request.APIRequest.getInstance({
487
+ webex: webex
488
+ });
489
+ requestOptions = {
490
+ uri: '/api/v1/calling/web/devices/device-123',
491
+ method: _types.HTTP_METHODS.GET,
492
+ headers: {
493
+ 'x-custom-header': 'value'
494
+ }
495
+ };
496
+ webex.request.mockResolvedValue({
497
+ statusCode: 200
498
+ });
499
+ _context10.next = 1;
500
+ return apiRequest.makeRequest(requestOptions);
501
+ case 1:
502
+ expect(webex.request).toHaveBeenCalledWith(requestOptions);
503
+ case 2:
504
+ case "end":
505
+ return _context10.stop();
506
+ }
507
+ }, _callee10);
508
+ })));
509
+ it('should return webex.request result directly', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee11() {
510
+ var apiRequest, expectedResponse, result;
511
+ return _regenerator.default.wrap(function (_context11) {
512
+ while (1) switch (_context11.prev = _context11.next) {
513
+ case 0:
514
+ _wsFeatureFlag.isMobiusWssEnabled.mockReturnValue(false);
515
+ apiRequest = _request.APIRequest.getInstance({
516
+ webex: webex
517
+ });
518
+ expectedResponse = {
519
+ statusCode: 404,
520
+ body: {
521
+ error: 'Not found'
522
+ },
523
+ headers: {
524
+ 'x-tracking-id': 'track-123'
525
+ }
526
+ };
527
+ webex.request.mockResolvedValue(expectedResponse);
528
+ _context11.next = 1;
529
+ return apiRequest.makeRequest({
530
+ uri: '/api/v1/test',
531
+ method: _types.HTTP_METHODS.GET
532
+ });
533
+ case 1:
534
+ result = _context11.sent;
535
+ expect(result).toEqual(expectedResponse);
536
+ case 2:
537
+ case "end":
538
+ return _context11.stop();
539
+ }
540
+ }, _callee11);
541
+ })));
542
+ });
543
+ describe('makeRequest - WebSocket transport', function () {
544
+ beforeEach(function () {
545
+ _wsFeatureFlag.isMobiusWssEnabled.mockReturnValue(true);
546
+ });
547
+ it('should derive socket message type from URI and method', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee12() {
548
+ var apiRequest, requestOptions;
549
+ return _regenerator.default.wrap(function (_context12) {
550
+ while (1) switch (_context12.prev = _context12.next) {
551
+ case 0:
552
+ apiRequest = _request.APIRequest.getInstance({
553
+ webex: webex
554
+ });
555
+ requestOptions = {
556
+ uri: '/api/v1/calling/web/device',
557
+ method: _types.HTTP_METHODS.POST,
558
+ body: {
559
+ userId: 'user-123'
560
+ }
561
+ };
562
+ _context12.next = 1;
563
+ return apiRequest.makeRequest(requestOptions);
564
+ case 1:
565
+ expect(mockMobiusSocket.sendWssRequest).toHaveBeenCalledWith(expect.objectContaining({
566
+ type: _constants.MOBIUS_SOCKET_MESSAGE_TYPE.REGISTER
567
+ }));
568
+ expect(infoSpy).toHaveBeenCalledWith('Dispatching request via WSS ', {
569
+ file: 'REQUEST',
570
+ method: 'makeRequest'
571
+ });
572
+ case 2:
573
+ case "end":
574
+ return _context12.stop();
575
+ }
576
+ }, _callee12);
577
+ })));
578
+ it('should throw error if message type is UNKNOWN', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee13() {
579
+ var apiRequest, requestOptions;
580
+ return _regenerator.default.wrap(function (_context13) {
581
+ while (1) switch (_context13.prev = _context13.next) {
582
+ case 0:
583
+ apiRequest = _request.APIRequest.getInstance({
584
+ webex: webex
585
+ });
586
+ requestOptions = {
587
+ uri: '/api/v1/unrecognized/path',
588
+ method: _types.HTTP_METHODS.POST
589
+ };
590
+ _context13.next = 1;
591
+ return expect(apiRequest.makeRequest(requestOptions)).rejects.toThrow('Unknown Mobius Socket message type: UNKNOWN');
592
+ case 1:
593
+ expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('Unknown Mobius Socket message type'), {
594
+ file: 'REQUEST',
595
+ method: 'makeRequest'
596
+ });
597
+ case 2:
598
+ case "end":
599
+ return _context13.stop();
600
+ }
601
+ }, _callee13);
602
+ })));
603
+ it('should generate tracking ID with webex-js-sdk prefix', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee14() {
604
+ var apiRequest, requestOptions;
605
+ return _regenerator.default.wrap(function (_context14) {
606
+ while (1) switch (_context14.prev = _context14.next) {
607
+ case 0:
608
+ apiRequest = _request.APIRequest.getInstance({
609
+ webex: webex
610
+ });
611
+ requestOptions = {
612
+ uri: '/api/v1/calling/web/device',
613
+ method: _types.HTTP_METHODS.POST
614
+ };
615
+ _context14.next = 1;
616
+ return apiRequest.makeRequest(requestOptions);
617
+ case 1:
618
+ expect(_uuid.v4).toHaveBeenCalled();
619
+ expect(mockMobiusSocket.sendWssRequest).toHaveBeenCalledWith(expect.objectContaining({
620
+ trackingId: 'webex-js-sdk_mock-uuid-12345'
621
+ }));
622
+ case 2:
623
+ case "end":
624
+ return _context14.stop();
625
+ }
626
+ }, _callee14);
627
+ })));
628
+ it('should send WSS request with correct payload structure', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee15() {
629
+ var apiRequest, requestOptions;
630
+ return _regenerator.default.wrap(function (_context15) {
631
+ while (1) switch (_context15.prev = _context15.next) {
632
+ case 0:
633
+ apiRequest = _request.APIRequest.getInstance({
634
+ webex: webex
635
+ });
636
+ requestOptions = {
637
+ uri: '/api/v1/calling/web/device',
638
+ method: _types.HTTP_METHODS.POST,
639
+ body: {
640
+ userId: 'user-123'
641
+ },
642
+ headers: {
643
+ 'x-custom': 'header-value'
644
+ }
645
+ };
646
+ _context15.next = 1;
647
+ return apiRequest.makeRequest(requestOptions);
648
+ case 1:
649
+ expect(mockMobiusSocket.sendWssRequest).toHaveBeenCalledWith({
650
+ type: _constants.MOBIUS_SOCKET_MESSAGE_TYPE.REGISTER,
651
+ trackingId: 'webex-js-sdk_mock-uuid-12345',
652
+ metadata: {
653
+ 'x-custom': 'header-value',
654
+ userAgent: 'webex-calling/beta',
655
+ authorization: ''
656
+ },
657
+ data: {
658
+ userId: 'user-123'
659
+ }
660
+ });
661
+ case 2:
662
+ case "end":
663
+ return _context15.stop();
664
+ }
665
+ }, _callee15);
666
+ })));
667
+ it('should get user token for supplementary services (CALL_HOLD)', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee16() {
668
+ var apiRequest, requestOptions;
669
+ return _regenerator.default.wrap(function (_context16) {
670
+ while (1) switch (_context16.prev = _context16.next) {
671
+ case 0:
672
+ webex.credentials.getUserToken.mockResolvedValue('Bearer token-abc-123');
673
+ apiRequest = _request.APIRequest.getInstance({
674
+ webex: webex
675
+ });
676
+ requestOptions = {
677
+ uri: '/api/v1/calling/web/devices/device-123/services/callhold/hold',
678
+ method: _types.HTTP_METHODS.POST
679
+ };
680
+ _context16.next = 1;
681
+ return apiRequest.makeRequest(requestOptions);
682
+ case 1:
683
+ expect(webex.credentials.getUserToken).toHaveBeenCalled();
684
+ expect(mockMobiusSocket.sendWssRequest).toHaveBeenCalledWith(expect.objectContaining({
685
+ type: _constants.MOBIUS_SOCKET_MESSAGE_TYPE.CALL_HOLD,
686
+ metadata: expect.objectContaining({
687
+ authorization: 'Bearer token-abc-123'
688
+ })
689
+ }));
690
+ case 2:
691
+ case "end":
692
+ return _context16.stop();
693
+ }
694
+ }, _callee16);
695
+ })));
696
+ it('should not get user token for non-supplementary services', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee17() {
697
+ var apiRequest, requestOptions;
698
+ return _regenerator.default.wrap(function (_context17) {
699
+ while (1) switch (_context17.prev = _context17.next) {
700
+ case 0:
701
+ apiRequest = _request.APIRequest.getInstance({
702
+ webex: webex
703
+ });
704
+ requestOptions = {
705
+ uri: '/api/v1/calling/web/device',
706
+ method: _types.HTTP_METHODS.POST
707
+ };
708
+ _context17.next = 1;
709
+ return apiRequest.makeRequest(requestOptions);
710
+ case 1:
711
+ expect(webex.credentials.getUserToken).not.toHaveBeenCalled();
712
+ expect(mockMobiusSocket.sendWssRequest).toHaveBeenCalledWith(expect.objectContaining({
713
+ metadata: expect.objectContaining({
714
+ authorization: ''
715
+ })
716
+ }));
717
+ case 2:
718
+ case "end":
719
+ return _context17.stop();
720
+ }
721
+ }, _callee17);
722
+ })));
723
+ it('should normalize success response to WebexRequestPayload shape', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee18() {
724
+ var wsResponse, apiRequest, result;
725
+ return _regenerator.default.wrap(function (_context18) {
726
+ while (1) switch (_context18.prev = _context18.next) {
727
+ case 0:
728
+ wsResponse = {
729
+ type: 'register.response',
730
+ statusCode: 201,
731
+ statusMessage: 'Created',
732
+ trackingId: 'track-123',
733
+ data: {
734
+ deviceId: 'device-456',
735
+ correlationId: 'corr-789'
736
+ },
737
+ metadata: {
738
+ 'x-response-header': 'value'
739
+ }
740
+ };
741
+ mockMobiusSocket.sendWssRequest.mockResolvedValue(wsResponse);
742
+ apiRequest = _request.APIRequest.getInstance({
743
+ webex: webex
744
+ });
745
+ _context18.next = 1;
746
+ return apiRequest.makeRequest({
747
+ uri: '/api/v1/calling/web/device',
748
+ method: _types.HTTP_METHODS.POST
749
+ });
750
+ case 1:
751
+ result = _context18.sent;
752
+ expect(result).toEqual({
753
+ statusCode: 201,
754
+ body: {
755
+ deviceId: 'device-456',
756
+ correlationId: 'corr-789'
757
+ },
758
+ headers: {
759
+ trackingid: 'track-123',
760
+ 'x-response-header': 'value'
761
+ }
762
+ });
763
+ expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('WSS request succeeded'), {
764
+ file: 'REQUEST',
765
+ method: 'makeRequest'
766
+ });
767
+ case 2:
768
+ case "end":
769
+ return _context18.stop();
770
+ }
771
+ }, _callee18);
772
+ })));
773
+ it('should normalize error to WebexRequestPayload shape', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee19() {
774
+ var wsError, apiRequest;
775
+ return _regenerator.default.wrap(function (_context19) {
776
+ while (1) switch (_context19.prev = _context19.next) {
777
+ case 0:
778
+ wsError = {
779
+ statusCode: 400,
780
+ statusMessage: 'Bad Request',
781
+ trackingId: 'error-track-456',
782
+ response: {
783
+ statusCode: 400,
784
+ trackingId: 'error-track-456',
785
+ data: {
786
+ error: 'Invalid request'
787
+ },
788
+ metadata: {
789
+ 'x-error-code': 'ERR001'
790
+ }
791
+ }
792
+ };
793
+ mockMobiusSocket.sendWssRequest.mockRejectedValue(wsError);
794
+ apiRequest = _request.APIRequest.getInstance({
795
+ webex: webex
796
+ });
797
+ _context19.next = 1;
798
+ return expect(apiRequest.makeRequest({
799
+ uri: '/api/v1/calling/web/device',
800
+ method: _types.HTTP_METHODS.POST
801
+ })).rejects.toEqual({
802
+ statusCode: 400,
803
+ body: {
804
+ error: 'Invalid request'
805
+ },
806
+ headers: {
807
+ trackingid: 'error-track-456',
808
+ 'x-error-code': 'ERR001'
809
+ }
810
+ });
811
+ case 1:
812
+ expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('WSS request failed'), {
813
+ file: 'REQUEST',
814
+ method: 'makeRequest'
815
+ });
816
+ case 2:
817
+ case "end":
818
+ return _context19.stop();
819
+ }
820
+ }, _callee19);
821
+ })));
822
+ });
823
+ describe('registerMobiusSocketListener', function () {
824
+ it('should attach listener to event:async_event', function () {
825
+ var apiRequest = _request.APIRequest.getInstance({
826
+ webex: webex
827
+ });
828
+ var callback = jest.fn();
829
+ apiRequest.registerMobiusSocketListener(callback);
830
+ expect(mockMobiusSocket.on).toHaveBeenCalledWith('event:async_event', expect.any(Function));
831
+ expect(infoSpy).toHaveBeenCalledWith('Attaching Mobius async event listener', {
832
+ file: 'REQUEST',
833
+ method: 'registerMobiusSocketListener'
834
+ });
835
+ expect(logSpy).toHaveBeenCalledWith('Mobius async event listener attached', {
836
+ file: 'REQUEST',
837
+ method: 'registerMobiusSocketListener'
838
+ });
839
+ });
840
+ it('should invoke callback with event data when async event received', function () {
841
+ var apiRequest = _request.APIRequest.getInstance({
842
+ webex: webex
843
+ });
844
+ var callback = jest.fn();
845
+ var mockEvent = {
846
+ type: 'event:async_event',
847
+ eventId: 'evt-123',
848
+ trackingId: 'track-456',
849
+ data: {
850
+ eventType: 'registration.down'
851
+ }
852
+ };
853
+ apiRequest.registerMobiusSocketListener(callback);
854
+ var attachedCallback = mockMobiusSocket.on.mock.calls[0][1];
855
+ attachedCallback(mockEvent);
856
+ expect(callback).toHaveBeenCalledWith(mockEvent);
857
+ });
858
+ it('should submit LISTENER_REGISTERED metric', function () {
859
+ var apiRequest = _request.APIRequest.getInstance({
860
+ webex: webex
861
+ });
862
+ var callback = jest.fn();
863
+ apiRequest.registerMobiusSocketListener(callback);
864
+ expect(mockMetricManager.submitMobiusSocketMetric).toHaveBeenCalledWith(_types2.METRIC_EVENT.MOBIUS_SOCKET, _types2.MOBIUS_SOCKET_ACTION.LISTENER_REGISTERED, _types2.METRIC_TYPE.BEHAVIORAL);
865
+ });
866
+ });
867
+ describe('unregisterMobiusSocketListener', function () {
868
+ it('should detach listener from event:async_event', function () {
869
+ var apiRequest = _request.APIRequest.getInstance({
870
+ webex: webex
871
+ });
872
+ apiRequest.unregisterMobiusSocketListener();
873
+ expect(mockMobiusSocket.off).toHaveBeenCalledWith('event:async_event');
874
+ expect(infoSpy).toHaveBeenCalledWith('Detaching Mobius async event listener', {
875
+ file: 'REQUEST',
876
+ method: 'unregisterMobiusSocketListener'
877
+ });
878
+ expect(logSpy).toHaveBeenCalledWith('Mobius async event listener detached', {
879
+ file: 'REQUEST',
880
+ method: 'unregisterMobiusSocketListener'
881
+ });
882
+ });
883
+ it('should submit LISTENER_UNREGISTERED metric', function () {
884
+ var apiRequest = _request.APIRequest.getInstance({
885
+ webex: webex
886
+ });
887
+ apiRequest.unregisterMobiusSocketListener();
888
+ expect(mockMetricManager.submitMobiusSocketMetric).toHaveBeenCalledWith(_types2.METRIC_EVENT.MOBIUS_SOCKET, _types2.MOBIUS_SOCKET_ACTION.LISTENER_UNREGISTERED, _types2.METRIC_TYPE.BEHAVIORAL);
889
+ });
890
+ });
891
+ describe('registerMobiusSocketConnectionListener', function () {
892
+ var getHandlerFor = function getHandlerFor(eventName) {
893
+ var call = mockMobiusSocket.on.mock.calls.find(function (_ref20) {
894
+ var _ref21 = (0, _slicedToArray2.default)(_ref20, 1),
895
+ name = _ref21[0];
896
+ return name === eventName;
897
+ });
898
+ return call[1];
899
+ };
900
+ it('should attach listeners to online and offline.* socket events', function () {
901
+ var apiRequest = _request.APIRequest.getInstance({
902
+ webex: webex
903
+ });
904
+ apiRequest.registerMobiusSocketConnectionListener({
905
+ onConnected: jest.fn(),
906
+ onDisconnected: jest.fn()
907
+ });
908
+ expect(mockMobiusSocket.on).toHaveBeenCalledWith('online', expect.any(Function));
909
+ expect(mockMobiusSocket.on).toHaveBeenCalledWith('offline.permanent', expect.any(Function));
910
+ expect(mockMobiusSocket.on).toHaveBeenCalledWith('offline.transient', expect.any(Function));
911
+ expect(mockMobiusSocket.on).toHaveBeenCalledWith('offline.replaced', expect.any(Function));
912
+ expect(infoSpy).toHaveBeenCalledWith('Attaching Mobius socket connection listener', {
913
+ file: 'REQUEST',
914
+ method: 'registerMobiusSocketConnectionListener'
915
+ });
916
+ expect(logSpy).toHaveBeenCalledWith('Mobius socket connection listener attached', {
917
+ file: 'REQUEST',
918
+ method: 'registerMobiusSocketConnectionListener'
919
+ });
920
+ });
921
+ it('should invoke onConnected when the online event fires', function () {
922
+ var apiRequest = _request.APIRequest.getInstance({
923
+ webex: webex
924
+ });
925
+ var onConnected = jest.fn();
926
+ apiRequest.registerMobiusSocketConnectionListener({
927
+ onConnected: onConnected,
928
+ onDisconnected: jest.fn()
929
+ });
930
+ getHandlerFor('online')();
931
+ expect(onConnected).toHaveBeenCalledTimes(1);
932
+ });
933
+ it.each([['offline.permanent', _constants.MOBIUS_SOCKET_DISCONNECT_REASON.PERMANENT], ['offline.transient', _constants.MOBIUS_SOCKET_DISCONNECT_REASON.TRANSIENT], ['offline.replaced', _constants.MOBIUS_SOCKET_DISCONNECT_REASON.REPLACED]])('should invoke onDisconnected with %s reason when %s fires', function (eventName, reason) {
934
+ var apiRequest = _request.APIRequest.getInstance({
935
+ webex: webex
936
+ });
937
+ var onDisconnected = jest.fn();
938
+ apiRequest.registerMobiusSocketConnectionListener({
939
+ onConnected: jest.fn(),
940
+ onDisconnected: onDisconnected
941
+ });
942
+ getHandlerFor(eventName)();
943
+ expect(onDisconnected).toHaveBeenCalledTimes(1);
944
+ expect(onDisconnected).toHaveBeenCalledWith(reason);
945
+ });
946
+ });
947
+ describe('unregisterMobiusSocketConnectionListener', function () {
948
+ it('should detach listeners from online and offline.* socket events', function () {
949
+ var apiRequest = _request.APIRequest.getInstance({
950
+ webex: webex
951
+ });
952
+ apiRequest.unregisterMobiusSocketConnectionListener();
953
+ expect(mockMobiusSocket.off).toHaveBeenCalledWith('online');
954
+ expect(mockMobiusSocket.off).toHaveBeenCalledWith('offline.permanent');
955
+ expect(mockMobiusSocket.off).toHaveBeenCalledWith('offline.transient');
956
+ expect(mockMobiusSocket.off).toHaveBeenCalledWith('offline.replaced');
957
+ expect(infoSpy).toHaveBeenCalledWith('Detaching Mobius socket connection listener', {
958
+ file: 'REQUEST',
959
+ method: 'unregisterMobiusSocketConnectionListener'
960
+ });
961
+ expect(logSpy).toHaveBeenCalledWith('Mobius socket connection listener detached', {
962
+ file: 'REQUEST',
963
+ method: 'unregisterMobiusSocketConnectionListener'
964
+ });
965
+ });
966
+ });
967
+ });
968
+ //# sourceMappingURL=request.test.js.map