@webex/plugin-meetings 3.11.0-webex-services-ready.1 → 3.12.0-auth-prejoin-fetch.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.
Files changed (294) hide show
  1. package/AGENTS.md +9 -0
  2. package/dist/aiEnableRequest/index.js +197 -0
  3. package/dist/aiEnableRequest/index.js.map +1 -0
  4. package/dist/aiEnableRequest/utils.js +36 -0
  5. package/dist/aiEnableRequest/utils.js.map +1 -0
  6. package/dist/annotation/index.js +16 -7
  7. package/dist/annotation/index.js.map +1 -1
  8. package/dist/breakouts/breakout.js +8 -3
  9. package/dist/breakouts/breakout.js.map +1 -1
  10. package/dist/breakouts/events.js +29 -14
  11. package/dist/breakouts/events.js.map +1 -1
  12. package/dist/breakouts/index.js +99 -4
  13. package/dist/breakouts/index.js.map +1 -1
  14. package/dist/common/errors/webex-errors.js +49 -5
  15. package/dist/common/errors/webex-errors.js.map +1 -1
  16. package/dist/config.js +8 -3
  17. package/dist/config.js.map +1 -1
  18. package/dist/constants.js +60 -11
  19. package/dist/constants.js.map +1 -1
  20. package/dist/controls-options-manager/constants.js +11 -1
  21. package/dist/controls-options-manager/constants.js.map +1 -1
  22. package/dist/controls-options-manager/index.js +67 -29
  23. package/dist/controls-options-manager/index.js.map +1 -1
  24. package/dist/controls-options-manager/util.js +91 -0
  25. package/dist/controls-options-manager/util.js.map +1 -1
  26. package/dist/hashTree/constants.js +16 -2
  27. package/dist/hashTree/constants.js.map +1 -1
  28. package/dist/hashTree/hashTree.js +18 -0
  29. package/dist/hashTree/hashTree.js.map +1 -1
  30. package/dist/hashTree/hashTreeParser.js +1655 -538
  31. package/dist/hashTree/hashTreeParser.js.map +1 -1
  32. package/dist/hashTree/types.js +4 -2
  33. package/dist/hashTree/types.js.map +1 -1
  34. package/dist/hashTree/utils.js +52 -0
  35. package/dist/hashTree/utils.js.map +1 -1
  36. package/dist/index.js +18 -2
  37. package/dist/index.js.map +1 -1
  38. package/dist/interceptors/constant.js +12 -0
  39. package/dist/interceptors/constant.js.map +1 -0
  40. package/dist/interceptors/dataChannelAuthToken.js +350 -0
  41. package/dist/interceptors/dataChannelAuthToken.js.map +1 -0
  42. package/dist/interceptors/index.js +7 -0
  43. package/dist/interceptors/index.js.map +1 -1
  44. package/dist/interceptors/locusRetry.js +23 -8
  45. package/dist/interceptors/locusRetry.js.map +1 -1
  46. package/dist/interceptors/utils.js +27 -0
  47. package/dist/interceptors/utils.js.map +1 -0
  48. package/dist/interpretation/index.js +11 -2
  49. package/dist/interpretation/index.js.map +1 -1
  50. package/dist/interpretation/interpretation.types.js +7 -0
  51. package/dist/interpretation/interpretation.types.js.map +1 -0
  52. package/dist/interpretation/siLanguage.js +1 -1
  53. package/dist/locus-info/controlsUtils.js +9 -4
  54. package/dist/locus-info/controlsUtils.js.map +1 -1
  55. package/dist/locus-info/index.js +914 -212
  56. package/dist/locus-info/index.js.map +1 -1
  57. package/dist/locus-info/infoUtils.js +36 -5
  58. package/dist/locus-info/infoUtils.js.map +1 -1
  59. package/dist/locus-info/selfUtils.js +1 -0
  60. package/dist/locus-info/selfUtils.js.map +1 -1
  61. package/dist/locus-info/types.js +19 -0
  62. package/dist/locus-info/types.js.map +1 -1
  63. package/dist/media/MediaConnectionAwaiter.js +72 -3
  64. package/dist/media/MediaConnectionAwaiter.js.map +1 -1
  65. package/dist/media/index.js +8 -2
  66. package/dist/media/index.js.map +1 -1
  67. package/dist/media/properties.js +8 -7
  68. package/dist/media/properties.js.map +1 -1
  69. package/dist/meeting/in-meeting-actions.js +11 -1
  70. package/dist/meeting/in-meeting-actions.js.map +1 -1
  71. package/dist/meeting/index.js +2347 -1096
  72. package/dist/meeting/index.js.map +1 -1
  73. package/dist/meeting/locusMediaRequest.js +229 -82
  74. package/dist/meeting/locusMediaRequest.js.map +1 -1
  75. package/dist/meeting/muteState.js +10 -1
  76. package/dist/meeting/muteState.js.map +1 -1
  77. package/dist/meeting/request.js +55 -2
  78. package/dist/meeting/request.js.map +1 -1
  79. package/dist/meeting/request.type.js.map +1 -1
  80. package/dist/meeting/util.js +168 -5
  81. package/dist/meeting/util.js.map +1 -1
  82. package/dist/meeting-info/meeting-info-v2.js +100 -38
  83. package/dist/meeting-info/meeting-info-v2.js.map +1 -1
  84. package/dist/meetings/index.js +466 -174
  85. package/dist/meetings/index.js.map +1 -1
  86. package/dist/meetings/meetings.types.js +6 -1
  87. package/dist/meetings/meetings.types.js.map +1 -1
  88. package/dist/meetings/request.js +39 -0
  89. package/dist/meetings/request.js.map +1 -1
  90. package/dist/meetings/util.js +116 -18
  91. package/dist/meetings/util.js.map +1 -1
  92. package/dist/member/index.js +20 -0
  93. package/dist/member/index.js.map +1 -1
  94. package/dist/member/types.js.map +1 -1
  95. package/dist/member/util.js +40 -0
  96. package/dist/member/util.js.map +1 -1
  97. package/dist/members/index.js +101 -43
  98. package/dist/members/index.js.map +1 -1
  99. package/dist/members/util.js +8 -1
  100. package/dist/members/util.js.map +1 -1
  101. package/dist/metrics/constants.js +12 -1
  102. package/dist/metrics/constants.js.map +1 -1
  103. package/dist/multistream/codec/constants.js +63 -0
  104. package/dist/multistream/codec/constants.js.map +1 -0
  105. package/dist/multistream/mediaRequestManager.js +64 -68
  106. package/dist/multistream/mediaRequestManager.js.map +1 -1
  107. package/dist/multistream/receiveSlot.js +9 -0
  108. package/dist/multistream/receiveSlot.js.map +1 -1
  109. package/dist/multistream/remoteMediaManager.js +11 -0
  110. package/dist/multistream/remoteMediaManager.js.map +1 -1
  111. package/dist/multistream/sendSlotManager.js +116 -2
  112. package/dist/multistream/sendSlotManager.js.map +1 -1
  113. package/dist/reachability/clusterReachability.js.map +1 -1
  114. package/dist/reachability/index.js +121 -83
  115. package/dist/reachability/index.js.map +1 -1
  116. package/dist/reachability/reachability.types.js +2 -0
  117. package/dist/reachability/reachability.types.js.map +1 -1
  118. package/dist/reachability/util.js +45 -0
  119. package/dist/reachability/util.js.map +1 -1
  120. package/dist/reactions/reactions.type.js.map +1 -1
  121. package/dist/reconnection-manager/index.js +0 -1
  122. package/dist/reconnection-manager/index.js.map +1 -1
  123. package/dist/recording-controller/index.js +1 -3
  124. package/dist/recording-controller/index.js.map +1 -1
  125. package/dist/roap/turnDiscovery.js +8 -1
  126. package/dist/roap/turnDiscovery.js.map +1 -1
  127. package/dist/types/aiEnableRequest/index.d.ts +5 -0
  128. package/dist/types/aiEnableRequest/utils.d.ts +2 -0
  129. package/dist/types/common/errors/webex-errors.d.ts +32 -2
  130. package/dist/types/config.d.ts +6 -2
  131. package/dist/types/constants.d.ts +35 -1
  132. package/dist/types/controls-options-manager/constants.d.ts +6 -1
  133. package/dist/types/controls-options-manager/index.d.ts +16 -0
  134. package/dist/types/hashTree/constants.d.ts +3 -0
  135. package/dist/types/hashTree/hashTree.d.ts +7 -0
  136. package/dist/types/hashTree/hashTreeParser.d.ts +315 -30
  137. package/dist/types/hashTree/types.d.ts +3 -0
  138. package/dist/types/hashTree/utils.d.ts +24 -0
  139. package/dist/types/index.d.ts +4 -0
  140. package/dist/types/interceptors/constant.d.ts +5 -0
  141. package/dist/types/interceptors/dataChannelAuthToken.d.ts +43 -0
  142. package/dist/types/interceptors/index.d.ts +2 -1
  143. package/dist/types/interceptors/locusRetry.d.ts +4 -4
  144. package/dist/types/interceptors/utils.d.ts +1 -0
  145. package/dist/types/interpretation/interpretation.types.d.ts +10 -0
  146. package/dist/types/locus-info/index.d.ts +126 -15
  147. package/dist/types/locus-info/infoUtils.d.ts +8 -0
  148. package/dist/types/locus-info/types.d.ts +28 -1
  149. package/dist/types/media/MediaConnectionAwaiter.d.ts +20 -2
  150. package/dist/types/media/properties.d.ts +8 -3
  151. package/dist/types/meeting/in-meeting-actions.d.ts +10 -0
  152. package/dist/types/meeting/index.d.ts +253 -16
  153. package/dist/types/meeting/locusMediaRequest.d.ts +12 -0
  154. package/dist/types/meeting/request.d.ts +17 -1
  155. package/dist/types/meeting/request.type.d.ts +5 -0
  156. package/dist/types/meeting/util.d.ts +40 -0
  157. package/dist/types/meeting-info/meeting-info-v2.d.ts +25 -1
  158. package/dist/types/meetings/index.d.ts +54 -21
  159. package/dist/types/meetings/meetings.types.d.ts +30 -1
  160. package/dist/types/meetings/request.d.ts +14 -0
  161. package/dist/types/member/index.d.ts +2 -0
  162. package/dist/types/member/types.d.ts +1 -0
  163. package/dist/types/member/util.d.ts +14 -0
  164. package/dist/types/members/index.d.ts +15 -2
  165. package/dist/types/members/util.d.ts +1 -5
  166. package/dist/types/metrics/constants.d.ts +11 -0
  167. package/dist/types/multistream/codec/constants.d.ts +7 -0
  168. package/dist/types/multistream/mediaRequestManager.d.ts +20 -26
  169. package/dist/types/multistream/sendSlotManager.d.ts +23 -1
  170. package/dist/types/reachability/clusterReachability.d.ts +3 -3
  171. package/dist/types/reachability/index.d.ts +10 -3
  172. package/dist/types/reachability/reachability.types.d.ts +7 -0
  173. package/dist/types/reachability/util.d.ts +17 -0
  174. package/dist/types/reactions/reactions.type.d.ts +4 -0
  175. package/dist/types/webinar/utils.d.ts +6 -0
  176. package/dist/webinar/index.js +585 -164
  177. package/dist/webinar/index.js.map +1 -1
  178. package/dist/webinar/utils.js +25 -0
  179. package/dist/webinar/utils.js.map +1 -0
  180. package/package.json +24 -23
  181. package/src/aiEnableRequest/README.md +84 -0
  182. package/src/aiEnableRequest/index.ts +186 -0
  183. package/src/aiEnableRequest/utils.ts +25 -0
  184. package/src/annotation/index.ts +32 -10
  185. package/src/breakouts/breakout.ts +3 -1
  186. package/src/breakouts/events.ts +33 -11
  187. package/src/breakouts/index.ts +122 -2
  188. package/src/common/errors/webex-errors.ts +50 -3
  189. package/src/config.ts +6 -2
  190. package/src/constants.ts +49 -3
  191. package/src/controls-options-manager/constants.ts +14 -1
  192. package/src/controls-options-manager/index.ts +87 -28
  193. package/src/controls-options-manager/util.ts +81 -1
  194. package/src/hashTree/constants.ts +17 -0
  195. package/src/hashTree/hashTree.ts +17 -0
  196. package/src/hashTree/hashTreeParser.ts +1482 -361
  197. package/src/hashTree/types.ts +4 -0
  198. package/src/hashTree/utils.ts +45 -0
  199. package/src/index.ts +14 -1
  200. package/src/interceptors/constant.ts +6 -0
  201. package/src/interceptors/dataChannelAuthToken.ts +246 -0
  202. package/src/interceptors/index.ts +2 -1
  203. package/src/interceptors/locusRetry.ts +25 -4
  204. package/src/interceptors/utils.ts +16 -0
  205. package/src/interpretation/index.ts +29 -11
  206. package/src/interpretation/interpretation.types.ts +11 -0
  207. package/src/locus-info/controlsUtils.ts +14 -1
  208. package/src/locus-info/index.ts +976 -203
  209. package/src/locus-info/infoUtils.ts +41 -6
  210. package/src/locus-info/selfUtils.ts +1 -0
  211. package/src/locus-info/types.ts +33 -1
  212. package/src/media/MediaConnectionAwaiter.ts +62 -5
  213. package/src/media/index.ts +10 -1
  214. package/src/media/properties.ts +11 -4
  215. package/src/meeting/in-meeting-actions.ts +20 -0
  216. package/src/meeting/index.ts +1300 -180
  217. package/src/meeting/locusMediaRequest.ts +106 -6
  218. package/src/meeting/muteState.ts +10 -1
  219. package/src/meeting/request.ts +53 -0
  220. package/src/meeting/request.type.ts +6 -0
  221. package/src/meeting/util.ts +207 -7
  222. package/src/meeting-info/meeting-info-v2.ts +83 -21
  223. package/src/meetings/index.ts +402 -121
  224. package/src/meetings/meetings.types.ts +36 -1
  225. package/src/meetings/request.ts +43 -0
  226. package/src/meetings/util.ts +117 -4
  227. package/src/member/index.ts +20 -0
  228. package/src/member/types.ts +1 -0
  229. package/src/member/util.ts +41 -0
  230. package/src/members/index.ts +70 -7
  231. package/src/members/util.ts +12 -4
  232. package/src/metrics/constants.ts +12 -0
  233. package/src/multistream/codec/constants.ts +58 -0
  234. package/src/multistream/mediaRequestManager.ts +117 -76
  235. package/src/multistream/receiveSlot.ts +18 -0
  236. package/src/multistream/remoteMediaManager.ts +13 -0
  237. package/src/multistream/sendSlotManager.ts +97 -3
  238. package/src/reachability/clusterReachability.ts +3 -2
  239. package/src/reachability/index.ts +47 -16
  240. package/src/reachability/reachability.types.ts +11 -0
  241. package/src/reachability/util.ts +36 -0
  242. package/src/reactions/reactions.type.ts +4 -0
  243. package/src/reconnection-manager/index.ts +0 -1
  244. package/src/recording-controller/index.ts +1 -2
  245. package/src/roap/turnDiscovery.ts +9 -1
  246. package/src/webinar/index.ts +448 -11
  247. package/src/webinar/utils.ts +16 -0
  248. package/test/unit/spec/aiEnableRequest/index.ts +1067 -0
  249. package/test/unit/spec/aiEnableRequest/utils.ts +130 -0
  250. package/test/unit/spec/annotation/index.ts +70 -8
  251. package/test/unit/spec/breakouts/breakout.ts +9 -3
  252. package/test/unit/spec/breakouts/events.ts +120 -2
  253. package/test/unit/spec/breakouts/index.ts +223 -3
  254. package/test/unit/spec/common/errors/webex-errors.ts +78 -0
  255. package/test/unit/spec/controls-options-manager/index.js +244 -29
  256. package/test/unit/spec/controls-options-manager/util.js +165 -0
  257. package/test/unit/spec/hashTree/hashTree.ts +66 -0
  258. package/test/unit/spec/hashTree/hashTreeParser.ts +4528 -171
  259. package/test/unit/spec/hashTree/utils.ts +125 -1
  260. package/test/unit/spec/interceptors/dataChannelAuthToken.ts +406 -0
  261. package/test/unit/spec/interceptors/locusRetry.ts +205 -4
  262. package/test/unit/spec/interceptors/utils.ts +75 -0
  263. package/test/unit/spec/interpretation/index.ts +26 -4
  264. package/test/unit/spec/locus-info/controlsUtils.js +200 -56
  265. package/test/unit/spec/locus-info/index.js +1861 -149
  266. package/test/unit/spec/locus-info/infoUtils.js +184 -1
  267. package/test/unit/spec/media/MediaConnectionAwaiter.ts +96 -1
  268. package/test/unit/spec/media/index.ts +92 -0
  269. package/test/unit/spec/media/properties.ts +35 -26
  270. package/test/unit/spec/meeting/in-meeting-actions.ts +12 -2
  271. package/test/unit/spec/meeting/index.js +3691 -366
  272. package/test/unit/spec/meeting/locusMediaRequest.ts +406 -4
  273. package/test/unit/spec/meeting/muteState.js +81 -0
  274. package/test/unit/spec/meeting/request.js +82 -0
  275. package/test/unit/spec/meeting/utils.js +595 -27
  276. package/test/unit/spec/meeting-info/meetinginfov2.js +286 -10
  277. package/test/unit/spec/meetings/index.js +1400 -78
  278. package/test/unit/spec/meetings/request.js +141 -0
  279. package/test/unit/spec/meetings/utils.js +402 -51
  280. package/test/unit/spec/member/index.js +35 -4
  281. package/test/unit/spec/member/util.js +154 -27
  282. package/test/unit/spec/members/index.js +216 -0
  283. package/test/unit/spec/members/request.js +37 -1
  284. package/test/unit/spec/members/utils.js +63 -0
  285. package/test/unit/spec/multistream/mediaRequestManager.ts +503 -122
  286. package/test/unit/spec/multistream/remoteMediaManager.ts +30 -0
  287. package/test/unit/spec/multistream/sendSlotManager.ts +135 -36
  288. package/test/unit/spec/reachability/index.ts +128 -46
  289. package/test/unit/spec/reachability/util.ts +31 -0
  290. package/test/unit/spec/reconnection-manager/index.js +4 -8
  291. package/test/unit/spec/recording-controller/index.js +9 -8
  292. package/test/unit/spec/roap/turnDiscovery.ts +20 -0
  293. package/test/unit/spec/webinar/index.ts +837 -39
  294. package/test/unit/spec/webinar/utils.ts +39 -0
@@ -0,0 +1,1067 @@
1
+ /*!
2
+ * Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+ import MockWebex from '@webex/test-helper-mock-webex';
5
+ import {assert} from '@webex/test-helper-chai';
6
+ import sinon from 'sinon';
7
+ import {EventEmitter} from 'stream';
8
+
9
+ import AIEnableRequest from '../../../../src/aiEnableRequest/index';
10
+ import {AI_ENABLE_REQUEST, HTTP_VERBS, LOCUSEVENT, MEETINGS} from '../../../../src/constants';
11
+
12
+ describe('plugin-meetings', () => {
13
+ describe('AIEnableRequest', () => {
14
+ let webex: any;
15
+ let aiEnableRequest: any;
16
+
17
+ beforeEach(() => {
18
+ // @ts-ignore - MockWebex is not typed correctly
19
+ webex = new MockWebex({
20
+ children: {
21
+ aiEnableRequest: AIEnableRequest,
22
+ },
23
+ });
24
+
25
+ aiEnableRequest = webex.internal.aiEnableRequest;
26
+
27
+ // Set up mercury as an EventEmitter
28
+ webex.internal.mercury = new EventEmitter();
29
+ });
30
+
31
+ describe('#namespace', () => {
32
+ it('should have the correct namespace', () => {
33
+ assert.equal(aiEnableRequest.namespace, MEETINGS);
34
+ });
35
+ });
36
+
37
+ describe('#approvalUrlUpdate', () => {
38
+ it('should update the approvalUrl property', () => {
39
+ const testApprovalUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id/approval';
40
+
41
+ aiEnableRequest.approvalUrlUpdate(testApprovalUrl);
42
+
43
+ assert.equal(aiEnableRequest.approvalUrl, testApprovalUrl);
44
+ });
45
+
46
+ it('should handle updating approvalUrl multiple times', () => {
47
+ const firstUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id-1/approval';
48
+ const secondUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id-2/approval';
49
+
50
+ aiEnableRequest.approvalUrlUpdate(firstUrl);
51
+ assert.equal(aiEnableRequest.approvalUrl, firstUrl);
52
+
53
+ aiEnableRequest.approvalUrlUpdate(secondUrl);
54
+ assert.equal(aiEnableRequest.approvalUrl, secondUrl);
55
+ });
56
+ });
57
+
58
+ describe('#locusUrlUpdate', () => {
59
+ it('should update the locusUrl property', () => {
60
+ const testLocusUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id';
61
+
62
+ aiEnableRequest.locusUrlUpdate(testLocusUrl);
63
+
64
+ assert.equal(aiEnableRequest.locusUrl, testLocusUrl);
65
+ });
66
+
67
+ it('should handle updating locusUrl multiple times', () => {
68
+ const firstUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id-1';
69
+ const secondUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id-2';
70
+
71
+ aiEnableRequest.locusUrlUpdate(firstUrl);
72
+ assert.equal(aiEnableRequest.locusUrl, firstUrl);
73
+
74
+ aiEnableRequest.locusUrlUpdate(secondUrl);
75
+ assert.equal(aiEnableRequest.locusUrl, secondUrl);
76
+ });
77
+ });
78
+
79
+ describe('#selfParticipantIdUpdate', () => {
80
+ it('should update the selfParticipantId property', () => {
81
+ const testSelfParticipantId = 'participant-123';
82
+
83
+ aiEnableRequest.selfParticipantIdUpdate(testSelfParticipantId);
84
+
85
+ assert.equal(aiEnableRequest.selfParticipantId, testSelfParticipantId);
86
+ });
87
+
88
+ it('should handle updating selfParticipantId multiple times', () => {
89
+ const firstId = 'participant-111';
90
+ const secondId = 'participant-222';
91
+
92
+ aiEnableRequest.selfParticipantIdUpdate(firstId);
93
+ assert.equal(aiEnableRequest.selfParticipantId, firstId);
94
+
95
+ aiEnableRequest.selfParticipantIdUpdate(secondId);
96
+ assert.equal(aiEnableRequest.selfParticipantId, secondId);
97
+ });
98
+
99
+ it('should call listenToApprovalRequests on first update', () => {
100
+ const listenToApprovalRequestsSpy = sinon.spy(aiEnableRequest, 'listenToApprovalRequests');
101
+ const testSelfParticipantId = 'participant-123';
102
+
103
+ aiEnableRequest.selfParticipantIdUpdate(testSelfParticipantId);
104
+
105
+ sinon.assert.calledOnce(listenToApprovalRequestsSpy);
106
+ assert.isTrue(aiEnableRequest.hasSubscribedToEvents);
107
+ });
108
+
109
+ it('should not call listenToApprovalRequests on subsequent updates', () => {
110
+ const testSelfParticipantId = 'participant-123';
111
+
112
+ // First update
113
+ aiEnableRequest.selfParticipantIdUpdate(testSelfParticipantId);
114
+
115
+ const listenToApprovalRequestsSpy = sinon.spy(aiEnableRequest, 'listenToApprovalRequests');
116
+
117
+ // Second update
118
+ aiEnableRequest.selfParticipantIdUpdate('participant-456');
119
+
120
+ sinon.assert.notCalled(listenToApprovalRequestsSpy);
121
+ assert.isTrue(aiEnableRequest.hasSubscribedToEvents);
122
+ });
123
+ });
124
+
125
+ describe('#listenToApprovalRequests', () => {
126
+ let listenToSpy;
127
+ let triggerSpy;
128
+ const testSelfParticipantId = 'self-participant-123';
129
+ const testInitiatorId = 'initiator-participant-456';
130
+ const testApproverId = 'approver-participant-789';
131
+ const testUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id/approval';
132
+
133
+ beforeEach(() => {
134
+ aiEnableRequest.selfParticipantId = testSelfParticipantId;
135
+ listenToSpy = sinon.spy(aiEnableRequest, 'listenTo');
136
+ triggerSpy = sinon.spy(aiEnableRequest, 'trigger');
137
+ });
138
+
139
+ afterEach(() => {
140
+ sinon.restore();
141
+ });
142
+
143
+ it('should listen to mercury approval request events', () => {
144
+ aiEnableRequest.listenToApprovalRequests();
145
+
146
+ sinon.assert.calledOnce(listenToSpy);
147
+ sinon.assert.calledWith(
148
+ listenToSpy,
149
+ webex.internal.mercury,
150
+ `event:${LOCUSEVENT.APPROVAL_REQUEST}`
151
+ );
152
+ });
153
+
154
+ it('should trigger event when user is the approver', () => {
155
+ aiEnableRequest.listenToApprovalRequests();
156
+
157
+ const event = {
158
+ data: {
159
+ approval: {
160
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
161
+ receivers: [{participantId: testSelfParticipantId}],
162
+ initiator: {participantId: testInitiatorId},
163
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
164
+ url: testUrl,
165
+ },
166
+ },
167
+ };
168
+
169
+ webex.internal.mercury.emit(`event:${LOCUSEVENT.APPROVAL_REQUEST}`, event);
170
+
171
+ sinon.assert.calledOnce(triggerSpy);
172
+ sinon.assert.calledWith(triggerSpy, AI_ENABLE_REQUEST.EVENTS.APPROVAL_REQUEST_ARRIVED, {
173
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
174
+ isApprover: true,
175
+ isInitiator: false,
176
+ initiatorId: testInitiatorId,
177
+ approverId: testSelfParticipantId,
178
+ url: testUrl,
179
+ });
180
+ });
181
+
182
+ it('should trigger event when user is the initiator', () => {
183
+ aiEnableRequest.listenToApprovalRequests();
184
+
185
+ const event = {
186
+ data: {
187
+ approval: {
188
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
189
+ receivers: [{participantId: testApproverId}],
190
+ initiator: {participantId: testSelfParticipantId},
191
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
192
+ url: testUrl,
193
+ },
194
+ },
195
+ };
196
+
197
+ webex.internal.mercury.emit(`event:${LOCUSEVENT.APPROVAL_REQUEST}`, event);
198
+
199
+ sinon.assert.calledOnce(triggerSpy);
200
+ sinon.assert.calledWith(triggerSpy, AI_ENABLE_REQUEST.EVENTS.APPROVAL_REQUEST_ARRIVED, {
201
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
202
+ isApprover: false,
203
+ isInitiator: true,
204
+ initiatorId: testSelfParticipantId,
205
+ approverId: testApproverId,
206
+ url: testUrl,
207
+ });
208
+ });
209
+
210
+ it('should not trigger event when user is neither approver nor initiator', () => {
211
+ aiEnableRequest.listenToApprovalRequests();
212
+
213
+ const event = {
214
+ data: {
215
+ approval: {
216
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
217
+ receivers: [{participantId: testApproverId}],
218
+ initiator: {participantId: testInitiatorId},
219
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
220
+ url: testUrl,
221
+ },
222
+ },
223
+ };
224
+
225
+ webex.internal.mercury.emit(`event:${LOCUSEVENT.APPROVAL_REQUEST}`, event);
226
+
227
+ sinon.assert.notCalled(triggerSpy);
228
+ });
229
+
230
+ it('should trigger DECLINED_ALL event even when user is neither approver nor initiator', () => {
231
+ aiEnableRequest.listenToApprovalRequests();
232
+
233
+ const event = {
234
+ data: {
235
+ approval: {
236
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
237
+ receivers: [{participantId: testApproverId}],
238
+ initiator: {participantId: testInitiatorId},
239
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.DECLINED_ALL,
240
+ url: testUrl,
241
+ },
242
+ },
243
+ };
244
+
245
+ webex.internal.mercury.emit(`event:${LOCUSEVENT.APPROVAL_REQUEST}`, event);
246
+
247
+ sinon.assert.calledOnce(triggerSpy);
248
+ sinon.assert.calledWith(triggerSpy, AI_ENABLE_REQUEST.EVENTS.APPROVAL_REQUEST_ARRIVED, {
249
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.DECLINED_ALL,
250
+ isApprover: false,
251
+ isInitiator: false,
252
+ initiatorId: testInitiatorId,
253
+ approverId: testApproverId,
254
+ url: testUrl,
255
+ });
256
+ });
257
+
258
+ it('should not trigger event when resourceType does not match', () => {
259
+ aiEnableRequest.listenToApprovalRequests();
260
+
261
+ const event = {
262
+ data: {
263
+ approval: {
264
+ resourceType: 'SomeOtherResourceType',
265
+ receivers: [{participantId: testSelfParticipantId}],
266
+ initiator: {participantId: testInitiatorId},
267
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
268
+ url: testUrl,
269
+ },
270
+ },
271
+ };
272
+
273
+ webex.internal.mercury.emit(`event:${LOCUSEVENT.APPROVAL_REQUEST}`, event);
274
+
275
+ sinon.assert.notCalled(triggerSpy);
276
+ });
277
+
278
+ it('should not trigger event when locusUrl does not match', () => {
279
+ const testLocusUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id';
280
+ const differentLocusUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/different-id';
281
+
282
+ aiEnableRequest.locusUrl = testLocusUrl;
283
+
284
+ // Reset the spy after setting locusUrl to avoid counting property change events
285
+ triggerSpy.resetHistory();
286
+
287
+ aiEnableRequest.listenToApprovalRequests();
288
+
289
+ const event = {
290
+ data: {
291
+ locusUrl: differentLocusUrl,
292
+ approval: {
293
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
294
+ receivers: [{participantId: testSelfParticipantId}],
295
+ initiator: {participantId: testInitiatorId},
296
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
297
+ url: testUrl,
298
+ },
299
+ },
300
+ };
301
+
302
+ webex.internal.mercury.emit(`event:${LOCUSEVENT.APPROVAL_REQUEST}`, event);
303
+
304
+ sinon.assert.notCalled(triggerSpy);
305
+ });
306
+
307
+ it('should trigger event when locusUrl matches', () => {
308
+ const testLocusUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id';
309
+
310
+ aiEnableRequest.locusUrl = testLocusUrl;
311
+
312
+ // Reset the spy after setting locusUrl to avoid counting property change events
313
+ triggerSpy.resetHistory();
314
+
315
+ aiEnableRequest.listenToApprovalRequests();
316
+
317
+ const event = {
318
+ data: {
319
+ locusUrl: testLocusUrl,
320
+ approval: {
321
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
322
+ receivers: [{participantId: testSelfParticipantId}],
323
+ initiator: {participantId: testInitiatorId},
324
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
325
+ url: testUrl,
326
+ },
327
+ },
328
+ };
329
+
330
+ webex.internal.mercury.emit(`event:${LOCUSEVENT.APPROVAL_REQUEST}`, event);
331
+
332
+ sinon.assert.calledOnce(triggerSpy);
333
+ sinon.assert.calledWith(triggerSpy, AI_ENABLE_REQUEST.EVENTS.APPROVAL_REQUEST_ARRIVED, {
334
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
335
+ isApprover: true,
336
+ isInitiator: false,
337
+ initiatorId: testInitiatorId,
338
+ approverId: testSelfParticipantId,
339
+ url: testUrl,
340
+ });
341
+ });
342
+
343
+ it('should handle events with different action types', () => {
344
+ aiEnableRequest.listenToApprovalRequests();
345
+
346
+ const actionTypes = [
347
+ AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
348
+ AI_ENABLE_REQUEST.ACTION_TYPE.ACCEPTED,
349
+ AI_ENABLE_REQUEST.ACTION_TYPE.DECLINED,
350
+ AI_ENABLE_REQUEST.ACTION_TYPE.DECLINED_ALL,
351
+ ];
352
+
353
+ actionTypes.forEach((actionType) => {
354
+ const event = {
355
+ data: {
356
+ approval: {
357
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
358
+ receivers: [{participantId: testSelfParticipantId}],
359
+ initiator: {participantId: testInitiatorId},
360
+ actionType,
361
+ url: testUrl,
362
+ },
363
+ },
364
+ };
365
+
366
+ webex.internal.mercury.emit(`event:${LOCUSEVENT.APPROVAL_REQUEST}`, event);
367
+ });
368
+
369
+ sinon.assert.callCount(triggerSpy, actionTypes.length);
370
+ });
371
+
372
+ it('should handle missing approver participantId', () => {
373
+ aiEnableRequest.listenToApprovalRequests();
374
+
375
+ const event = {
376
+ data: {
377
+ approval: {
378
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
379
+ receivers: [{}],
380
+ initiator: {participantId: testSelfParticipantId},
381
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
382
+ url: testUrl,
383
+ },
384
+ },
385
+ };
386
+
387
+ webex.internal.mercury.emit(`event:${LOCUSEVENT.APPROVAL_REQUEST}`, event);
388
+
389
+ sinon.assert.calledOnce(triggerSpy);
390
+ const callArgs = triggerSpy.getCall(0).args[1];
391
+ assert.isFalse(callArgs.isApprover);
392
+ assert.isTrue(callArgs.isInitiator);
393
+ });
394
+
395
+ it('should handle missing initiator participantId', () => {
396
+ aiEnableRequest.listenToApprovalRequests();
397
+
398
+ const event = {
399
+ data: {
400
+ approval: {
401
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
402
+ receivers: [{participantId: testSelfParticipantId}],
403
+ initiator: {},
404
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
405
+ url: testUrl,
406
+ },
407
+ },
408
+ };
409
+
410
+ webex.internal.mercury.emit(`event:${LOCUSEVENT.APPROVAL_REQUEST}`, event);
411
+
412
+ sinon.assert.calledOnce(triggerSpy);
413
+ const callArgs = triggerSpy.getCall(0).args[1];
414
+ assert.isTrue(callArgs.isApprover);
415
+ assert.isFalse(callArgs.isInitiator);
416
+ });
417
+
418
+ it('should handle empty receivers array', () => {
419
+ aiEnableRequest.listenToApprovalRequests();
420
+
421
+ const event = {
422
+ data: {
423
+ approval: {
424
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
425
+ receivers: [],
426
+ initiator: {participantId: testSelfParticipantId},
427
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
428
+ url: testUrl,
429
+ },
430
+ },
431
+ };
432
+
433
+ webex.internal.mercury.emit(`event:${LOCUSEVENT.APPROVAL_REQUEST}`, event);
434
+
435
+ sinon.assert.calledOnce(triggerSpy);
436
+ const callArgs = triggerSpy.getCall(0).args[1];
437
+ assert.isFalse(callArgs.isApprover);
438
+ assert.isTrue(callArgs.isInitiator);
439
+ });
440
+
441
+ it('should include all relevant data in triggered event', () => {
442
+ aiEnableRequest.listenToApprovalRequests();
443
+
444
+ const customUrl = 'https://custom.url/approval';
445
+ const event = {
446
+ data: {
447
+ approval: {
448
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
449
+ receivers: [{participantId: testSelfParticipantId}],
450
+ initiator: {participantId: testInitiatorId},
451
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.ACCEPTED,
452
+ url: customUrl,
453
+ },
454
+ },
455
+ };
456
+
457
+ webex.internal.mercury.emit(`event:${LOCUSEVENT.APPROVAL_REQUEST}`, event);
458
+
459
+ sinon.assert.calledOnce(triggerSpy);
460
+ const triggeredEvent = triggerSpy.getCall(0).args[1];
461
+ assert.equal(triggeredEvent.actionType, AI_ENABLE_REQUEST.ACTION_TYPE.ACCEPTED);
462
+ assert.equal(triggeredEvent.url, customUrl);
463
+ assert.equal(triggeredEvent.initiatorId, testInitiatorId);
464
+ assert.equal(triggeredEvent.approverId, testSelfParticipantId);
465
+ assert.isTrue(triggeredEvent.isApprover);
466
+ assert.isFalse(triggeredEvent.isInitiator);
467
+ });
468
+ });
469
+
470
+ describe('#requestEnableAIAssistant', () => {
471
+ let requestStub;
472
+ const testApprovalUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id/approval';
473
+ const testSelfParticipantId = 'self-participant-123';
474
+ const testApproverId = 'approver-participant-456';
475
+
476
+ beforeEach(() => {
477
+ aiEnableRequest.approvalUrl = testApprovalUrl;
478
+ aiEnableRequest.selfParticipantId = testSelfParticipantId;
479
+ requestStub = sinon.stub(aiEnableRequest, 'request').resolves({
480
+ statusCode: 200,
481
+ body: {},
482
+ });
483
+ });
484
+
485
+ afterEach(() => {
486
+ sinon.restore();
487
+ });
488
+
489
+ it('should make a POST request to the approval URL', async () => {
490
+ await aiEnableRequest.requestEnableAIAssistant({approverId: testApproverId});
491
+
492
+ sinon.assert.calledOnce(requestStub);
493
+ sinon.assert.calledWith(requestStub, {
494
+ method: HTTP_VERBS.POST,
495
+ uri: testApprovalUrl,
496
+ body: {
497
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
498
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
499
+ initiator: {
500
+ participantId: testSelfParticipantId,
501
+ },
502
+ approver: {
503
+ participantId: testApproverId,
504
+ },
505
+ },
506
+ });
507
+ });
508
+
509
+ it('should use the correct action type REQUESTED', async () => {
510
+ await aiEnableRequest.requestEnableAIAssistant({approverId: testApproverId});
511
+
512
+ const callArgs = requestStub.getCall(0).args[0];
513
+ assert.equal(callArgs.body.actionType, AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED);
514
+ });
515
+
516
+ it('should use the correct resource type AiAssistant', async () => {
517
+ await aiEnableRequest.requestEnableAIAssistant({approverId: testApproverId});
518
+
519
+ const callArgs = requestStub.getCall(0).args[0];
520
+ assert.equal(callArgs.body.resourceType, AI_ENABLE_REQUEST.RESOURCE_TYPE);
521
+ });
522
+
523
+ it('should include the initiator participant ID', async () => {
524
+ await aiEnableRequest.requestEnableAIAssistant({approverId: testApproverId});
525
+
526
+ const callArgs = requestStub.getCall(0).args[0];
527
+ assert.deepEqual(callArgs.body.initiator, {
528
+ participantId: testSelfParticipantId,
529
+ });
530
+ });
531
+
532
+ it('should include the approver participant ID', async () => {
533
+ await aiEnableRequest.requestEnableAIAssistant({approverId: testApproverId});
534
+
535
+ const callArgs = requestStub.getCall(0).args[0];
536
+ assert.deepEqual(callArgs.body.approver, {
537
+ participantId: testApproverId,
538
+ });
539
+ });
540
+
541
+ it('should return a Promise', () => {
542
+ const result = aiEnableRequest.requestEnableAIAssistant({approverId: testApproverId});
543
+
544
+ assert.instanceOf(result, Promise);
545
+ });
546
+
547
+ it('should resolve with the request response', async () => {
548
+ const mockResponse = {
549
+ statusCode: 200,
550
+ body: {
551
+ approvalId: 'approval-789',
552
+ },
553
+ };
554
+
555
+ requestStub.resolves(mockResponse);
556
+
557
+ const result = await aiEnableRequest.requestEnableAIAssistant({approverId: testApproverId});
558
+
559
+ assert.deepEqual(result, mockResponse);
560
+ });
561
+
562
+ it('should handle request failures', async () => {
563
+ const mockError = new Error('Request failed');
564
+ requestStub.rejects(mockError);
565
+
566
+ try {
567
+ await aiEnableRequest.requestEnableAIAssistant({approverId: testApproverId});
568
+ assert.fail('Should have thrown an error');
569
+ } catch (error) {
570
+ assert.equal(error.message, 'Request failed');
571
+ }
572
+ });
573
+
574
+ it('should work with different participant IDs', async () => {
575
+ const differentSelfId = 'different-self-999';
576
+ const differentApproverId = 'different-approver-888';
577
+
578
+ aiEnableRequest.selfParticipantId = differentSelfId;
579
+ await aiEnableRequest.requestEnableAIAssistant({approverId: differentApproverId});
580
+
581
+ const callArgs = requestStub.getCall(0).args[0];
582
+ assert.equal(callArgs.body.initiator.participantId, differentSelfId);
583
+ assert.equal(callArgs.body.approver.participantId, differentApproverId);
584
+ });
585
+ });
586
+
587
+ describe('#sendApprovalRequest', () => {
588
+ let requestStub;
589
+ const testUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id/approval';
590
+ const testInitiatorId = 'initiator-participant-123';
591
+ const testApproverId = 'approver-participant-456';
592
+
593
+ beforeEach(() => {
594
+ requestStub = sinon.stub(aiEnableRequest, 'request').resolves({
595
+ statusCode: 200,
596
+ body: {},
597
+ });
598
+ });
599
+
600
+ afterEach(() => {
601
+ sinon.restore();
602
+ });
603
+
604
+ it('should make a request with the specified method', async () => {
605
+ await aiEnableRequest.sendApprovalRequest({
606
+ url: testUrl,
607
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
608
+ initiatorId: testInitiatorId,
609
+ approverId: testApproverId,
610
+ method: HTTP_VERBS.POST,
611
+ });
612
+
613
+ sinon.assert.calledOnce(requestStub);
614
+ sinon.assert.calledWith(requestStub, {
615
+ method: HTTP_VERBS.POST,
616
+ uri: testUrl,
617
+ body: {
618
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
619
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
620
+ initiator: {
621
+ participantId: testInitiatorId,
622
+ },
623
+ approver: {
624
+ participantId: testApproverId,
625
+ },
626
+ },
627
+ });
628
+ });
629
+
630
+ it('should accept any action type', async () => {
631
+ await aiEnableRequest.sendApprovalRequest({
632
+ url: testUrl,
633
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.ACCEPTED,
634
+ initiatorId: testInitiatorId,
635
+ approverId: testApproverId,
636
+ method: HTTP_VERBS.PUT,
637
+ });
638
+
639
+ const callArgs = requestStub.getCall(0).args[0];
640
+ assert.equal(callArgs.body.actionType, AI_ENABLE_REQUEST.ACTION_TYPE.ACCEPTED);
641
+ });
642
+
643
+ it('should include the correct resource type', async () => {
644
+ await aiEnableRequest.sendApprovalRequest({
645
+ url: testUrl,
646
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
647
+ initiatorId: testInitiatorId,
648
+ approverId: testApproverId,
649
+ method: HTTP_VERBS.POST,
650
+ });
651
+
652
+ const callArgs = requestStub.getCall(0).args[0];
653
+ assert.equal(callArgs.body.resourceType, AI_ENABLE_REQUEST.RESOURCE_TYPE);
654
+ });
655
+
656
+ it('should return a Promise', () => {
657
+ const result = aiEnableRequest.sendApprovalRequest({
658
+ url: testUrl,
659
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
660
+ initiatorId: testInitiatorId,
661
+ approverId: testApproverId,
662
+ method: HTTP_VERBS.POST,
663
+ });
664
+
665
+ assert.instanceOf(result, Promise);
666
+ });
667
+
668
+ it('should resolve with the request response', async () => {
669
+ const mockResponse = {
670
+ statusCode: 200,
671
+ body: {approvalId: 'approval-789'},
672
+ };
673
+
674
+ requestStub.resolves(mockResponse);
675
+
676
+ const result = await aiEnableRequest.sendApprovalRequest({
677
+ url: testUrl,
678
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
679
+ initiatorId: testInitiatorId,
680
+ approverId: testApproverId,
681
+ method: HTTP_VERBS.POST,
682
+ });
683
+
684
+ assert.deepEqual(result, mockResponse);
685
+ });
686
+
687
+ it('should handle request failures', async () => {
688
+ const mockError = new Error('Request failed');
689
+ requestStub.rejects(mockError);
690
+
691
+ try {
692
+ await aiEnableRequest.sendApprovalRequest({
693
+ url: testUrl,
694
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.REQUESTED,
695
+ initiatorId: testInitiatorId,
696
+ approverId: testApproverId,
697
+ method: HTTP_VERBS.POST,
698
+ });
699
+ assert.fail('Should have thrown an error');
700
+ } catch (error) {
701
+ assert.equal(error.message, 'Request failed');
702
+ }
703
+ });
704
+
705
+ it('should use the specified HTTP method', async () => {
706
+ await aiEnableRequest.sendApprovalRequest({
707
+ url: testUrl,
708
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.ACCEPTED,
709
+ initiatorId: testInitiatorId,
710
+ approverId: testApproverId,
711
+ method: HTTP_VERBS.PUT,
712
+ });
713
+
714
+ const callArgs = requestStub.getCall(0).args[0];
715
+ assert.equal(callArgs.method, HTTP_VERBS.PUT);
716
+ });
717
+ });
718
+
719
+ describe('#acceptEnableAIAssistantRequest', () => {
720
+ let requestStub;
721
+ const testUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id/approval';
722
+ const testInitiatorId = 'initiator-participant-123';
723
+ const testSelfParticipantId = 'self-participant-456';
724
+
725
+ beforeEach(() => {
726
+ aiEnableRequest.selfParticipantId = testSelfParticipantId;
727
+ requestStub = sinon.stub(aiEnableRequest, 'request').resolves({
728
+ statusCode: 200,
729
+ body: {},
730
+ });
731
+ });
732
+
733
+ afterEach(() => {
734
+ sinon.restore();
735
+ });
736
+
737
+ it('should make a PUT request to the provided URL', async () => {
738
+ await aiEnableRequest.acceptEnableAIAssistantRequest({
739
+ url: testUrl,
740
+ initiatorId: testInitiatorId,
741
+ });
742
+
743
+ sinon.assert.calledOnce(requestStub);
744
+ sinon.assert.calledWith(requestStub, {
745
+ method: HTTP_VERBS.PUT,
746
+ uri: testUrl,
747
+ body: {
748
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.ACCEPTED,
749
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
750
+ initiator: {
751
+ participantId: testInitiatorId,
752
+ },
753
+ approver: {
754
+ participantId: testSelfParticipantId,
755
+ },
756
+ },
757
+ });
758
+ });
759
+
760
+ it('should use the correct action type ACCEPTED', async () => {
761
+ await aiEnableRequest.acceptEnableAIAssistantRequest({
762
+ url: testUrl,
763
+ initiatorId: testInitiatorId,
764
+ });
765
+
766
+ const callArgs = requestStub.getCall(0).args[0];
767
+ assert.equal(callArgs.body.actionType, AI_ENABLE_REQUEST.ACTION_TYPE.ACCEPTED);
768
+ });
769
+
770
+ it('should include the initiator participant ID', async () => {
771
+ await aiEnableRequest.acceptEnableAIAssistantRequest({
772
+ url: testUrl,
773
+ initiatorId: testInitiatorId,
774
+ });
775
+
776
+ const callArgs = requestStub.getCall(0).args[0];
777
+ assert.deepEqual(callArgs.body.initiator, {
778
+ participantId: testInitiatorId,
779
+ });
780
+ });
781
+
782
+ it('should include the approver participant ID as selfParticipantId', async () => {
783
+ await aiEnableRequest.acceptEnableAIAssistantRequest({
784
+ url: testUrl,
785
+ initiatorId: testInitiatorId,
786
+ });
787
+
788
+ const callArgs = requestStub.getCall(0).args[0];
789
+ assert.deepEqual(callArgs.body.approver, {
790
+ participantId: testSelfParticipantId,
791
+ });
792
+ });
793
+
794
+ it('should return a Promise', () => {
795
+ const result = aiEnableRequest.acceptEnableAIAssistantRequest({
796
+ url: testUrl,
797
+ initiatorId: testInitiatorId,
798
+ });
799
+
800
+ assert.instanceOf(result, Promise);
801
+ });
802
+
803
+ it('should resolve with the request response', async () => {
804
+ const mockResponse = {
805
+ statusCode: 200,
806
+ body: {success: true},
807
+ };
808
+
809
+ requestStub.resolves(mockResponse);
810
+
811
+ const result = await aiEnableRequest.acceptEnableAIAssistantRequest({
812
+ url: testUrl,
813
+ initiatorId: testInitiatorId,
814
+ });
815
+
816
+ assert.deepEqual(result, mockResponse);
817
+ });
818
+
819
+ it('should handle request failures', async () => {
820
+ const mockError = new Error('Request failed');
821
+ requestStub.rejects(mockError);
822
+
823
+ try {
824
+ await aiEnableRequest.acceptEnableAIAssistantRequest({
825
+ url: testUrl,
826
+ initiatorId: testInitiatorId,
827
+ });
828
+ assert.fail('Should have thrown an error');
829
+ } catch (error) {
830
+ assert.equal(error.message, 'Request failed');
831
+ }
832
+ });
833
+ });
834
+
835
+ describe('#declineEnableAIAssistantRequest', () => {
836
+ let requestStub;
837
+ const testUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id/approval';
838
+ const testInitiatorId = 'initiator-participant-123';
839
+ const testSelfParticipantId = 'self-participant-456';
840
+
841
+ beforeEach(() => {
842
+ aiEnableRequest.selfParticipantId = testSelfParticipantId;
843
+ requestStub = sinon.stub(aiEnableRequest, 'request').resolves({
844
+ statusCode: 200,
845
+ body: {},
846
+ });
847
+ });
848
+
849
+ afterEach(() => {
850
+ sinon.restore();
851
+ });
852
+
853
+ it('should make a PUT request to the provided URL', async () => {
854
+ await aiEnableRequest.declineEnableAIAssistantRequest({
855
+ url: testUrl,
856
+ initiatorId: testInitiatorId,
857
+ });
858
+
859
+ sinon.assert.calledOnce(requestStub);
860
+ sinon.assert.calledWith(requestStub, {
861
+ method: HTTP_VERBS.PUT,
862
+ uri: testUrl,
863
+ body: {
864
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.DECLINED,
865
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
866
+ initiator: {
867
+ participantId: testInitiatorId,
868
+ },
869
+ approver: {
870
+ participantId: testSelfParticipantId,
871
+ },
872
+ },
873
+ });
874
+ });
875
+
876
+ it('should use the correct action type DECLINED', async () => {
877
+ await aiEnableRequest.declineEnableAIAssistantRequest({
878
+ url: testUrl,
879
+ initiatorId: testInitiatorId,
880
+ });
881
+
882
+ const callArgs = requestStub.getCall(0).args[0];
883
+ assert.equal(callArgs.body.actionType, AI_ENABLE_REQUEST.ACTION_TYPE.DECLINED);
884
+ });
885
+
886
+ it('should include the initiator participant ID', async () => {
887
+ await aiEnableRequest.declineEnableAIAssistantRequest({
888
+ url: testUrl,
889
+ initiatorId: testInitiatorId,
890
+ });
891
+
892
+ const callArgs = requestStub.getCall(0).args[0];
893
+ assert.deepEqual(callArgs.body.initiator, {
894
+ participantId: testInitiatorId,
895
+ });
896
+ });
897
+
898
+ it('should include the approver participant ID as selfParticipantId', async () => {
899
+ await aiEnableRequest.declineEnableAIAssistantRequest({
900
+ url: testUrl,
901
+ initiatorId: testInitiatorId,
902
+ });
903
+
904
+ const callArgs = requestStub.getCall(0).args[0];
905
+ assert.deepEqual(callArgs.body.approver, {
906
+ participantId: testSelfParticipantId,
907
+ });
908
+ });
909
+
910
+ it('should return a Promise', () => {
911
+ const result = aiEnableRequest.declineEnableAIAssistantRequest({
912
+ url: testUrl,
913
+ initiatorId: testInitiatorId,
914
+ });
915
+
916
+ assert.instanceOf(result, Promise);
917
+ });
918
+
919
+ it('should resolve with the request response', async () => {
920
+ const mockResponse = {
921
+ statusCode: 200,
922
+ body: {success: true},
923
+ };
924
+
925
+ requestStub.resolves(mockResponse);
926
+
927
+ const result = await aiEnableRequest.declineEnableAIAssistantRequest({
928
+ url: testUrl,
929
+ initiatorId: testInitiatorId,
930
+ });
931
+
932
+ assert.deepEqual(result, mockResponse);
933
+ });
934
+
935
+ it('should handle request failures', async () => {
936
+ const mockError = new Error('Request failed');
937
+ requestStub.rejects(mockError);
938
+
939
+ try {
940
+ await aiEnableRequest.declineEnableAIAssistantRequest({
941
+ url: testUrl,
942
+ initiatorId: testInitiatorId,
943
+ });
944
+ assert.fail('Should have thrown an error');
945
+ } catch (error) {
946
+ assert.equal(error.message, 'Request failed');
947
+ }
948
+ });
949
+ });
950
+
951
+ describe('#declineAllEnableAIAssistantRequests', () => {
952
+ let requestStub;
953
+ const testUrl = 'https://locus-a.wbx2.com/locus/api/v1/loci/test-id/approval';
954
+ const testInitiatorId = 'initiator-participant-123';
955
+ const testSelfParticipantId = 'self-participant-456';
956
+
957
+ beforeEach(() => {
958
+ aiEnableRequest.selfParticipantId = testSelfParticipantId;
959
+ requestStub = sinon.stub(aiEnableRequest, 'request').resolves({
960
+ statusCode: 200,
961
+ body: {},
962
+ });
963
+ });
964
+
965
+ afterEach(() => {
966
+ sinon.restore();
967
+ });
968
+
969
+ it('should make a PUT request to the provided URL', async () => {
970
+ await aiEnableRequest.declineAllEnableAIAssistantRequests({
971
+ url: testUrl,
972
+ initiatorId: testInitiatorId,
973
+ });
974
+
975
+ sinon.assert.calledOnce(requestStub);
976
+ sinon.assert.calledWith(requestStub, {
977
+ method: HTTP_VERBS.PUT,
978
+ uri: testUrl,
979
+ body: {
980
+ actionType: AI_ENABLE_REQUEST.ACTION_TYPE.DECLINED_ALL,
981
+ resourceType: AI_ENABLE_REQUEST.RESOURCE_TYPE,
982
+ initiator: {
983
+ participantId: testInitiatorId,
984
+ },
985
+ approver: {
986
+ participantId: testSelfParticipantId,
987
+ },
988
+ },
989
+ });
990
+ });
991
+
992
+ it('should use the correct action type DECLINED_ALL', async () => {
993
+ await aiEnableRequest.declineAllEnableAIAssistantRequests({
994
+ url: testUrl,
995
+ initiatorId: testInitiatorId,
996
+ });
997
+
998
+ const callArgs = requestStub.getCall(0).args[0];
999
+ assert.equal(callArgs.body.actionType, AI_ENABLE_REQUEST.ACTION_TYPE.DECLINED_ALL);
1000
+ });
1001
+
1002
+ it('should include the initiator participant ID', async () => {
1003
+ await aiEnableRequest.declineAllEnableAIAssistantRequests({
1004
+ url: testUrl,
1005
+ initiatorId: testInitiatorId,
1006
+ });
1007
+
1008
+ const callArgs = requestStub.getCall(0).args[0];
1009
+ assert.deepEqual(callArgs.body.initiator, {
1010
+ participantId: testInitiatorId,
1011
+ });
1012
+ });
1013
+
1014
+ it('should include the approver participant ID as selfParticipantId', async () => {
1015
+ await aiEnableRequest.declineAllEnableAIAssistantRequests({
1016
+ url: testUrl,
1017
+ initiatorId: testInitiatorId,
1018
+ });
1019
+
1020
+ const callArgs = requestStub.getCall(0).args[0];
1021
+ assert.deepEqual(callArgs.body.approver, {
1022
+ participantId: testSelfParticipantId,
1023
+ });
1024
+ });
1025
+
1026
+ it('should return a Promise', () => {
1027
+ const result = aiEnableRequest.declineAllEnableAIAssistantRequests({
1028
+ url: testUrl,
1029
+ initiatorId: testInitiatorId,
1030
+ });
1031
+
1032
+ assert.instanceOf(result, Promise);
1033
+ });
1034
+
1035
+ it('should resolve with the request response', async () => {
1036
+ const mockResponse = {
1037
+ statusCode: 200,
1038
+ body: {declinedCount: 3},
1039
+ };
1040
+
1041
+ requestStub.resolves(mockResponse);
1042
+
1043
+ const result = await aiEnableRequest.declineAllEnableAIAssistantRequests({
1044
+ url: testUrl,
1045
+ initiatorId: testInitiatorId,
1046
+ });
1047
+
1048
+ assert.deepEqual(result, mockResponse);
1049
+ });
1050
+
1051
+ it('should handle request failures', async () => {
1052
+ const mockError = new Error('Request failed');
1053
+ requestStub.rejects(mockError);
1054
+
1055
+ try {
1056
+ await aiEnableRequest.declineAllEnableAIAssistantRequests({
1057
+ url: testUrl,
1058
+ initiatorId: testInitiatorId,
1059
+ });
1060
+ assert.fail('Should have thrown an error');
1061
+ } catch (error) {
1062
+ assert.equal(error.message, 'Request failed');
1063
+ }
1064
+ });
1065
+ });
1066
+ });
1067
+ });