@app-connect/core 1.7.37 → 1.7.38

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 (286) hide show
  1. package/README.md +17 -16
  2. package/dist/connector/developerPortal.d.ts +6 -0
  3. package/{connector → dist/connector}/developerPortal.js +29 -12
  4. package/dist/connector/mock.d.ts +1 -0
  5. package/{connector → dist/connector}/mock.js +33 -17
  6. package/dist/connector/proxy/engine.d.ts +10 -0
  7. package/dist/connector/proxy/engine.js +222 -0
  8. package/dist/connector/proxy/index.d.ts +5 -0
  9. package/dist/connector/proxy/index.js +511 -0
  10. package/dist/connector/registry.d.ts +1 -0
  11. package/dist/connector/registry.js +243 -0
  12. package/dist/handlers/admin.d.ts +1 -0
  13. package/{handlers → dist/handlers}/admin.js +137 -78
  14. package/dist/handlers/appointment.d.ts +9 -0
  15. package/{handlers → dist/handlers}/appointment.js +58 -29
  16. package/dist/handlers/auth.d.ts +9 -0
  17. package/{handlers → dist/handlers}/auth.js +68 -40
  18. package/dist/handlers/calldown.d.ts +10 -0
  19. package/dist/handlers/calldown.js +134 -0
  20. package/dist/handlers/contact.d.ts +1 -0
  21. package/{handlers → dist/handlers}/contact.js +61 -39
  22. package/dist/handlers/disposition.d.ts +1 -0
  23. package/{handlers → dist/handlers}/disposition.js +20 -10
  24. package/dist/handlers/log.d.ts +1 -0
  25. package/{handlers → dist/handlers}/log.js +91 -124
  26. package/dist/handlers/managedAuth.d.ts +1 -0
  27. package/{handlers → dist/handlers}/managedAuth.js +134 -61
  28. package/dist/handlers/managedOAuth.d.ts +13 -0
  29. package/{handlers → dist/handlers}/managedOAuth.js +102 -30
  30. package/dist/handlers/plugin.d.ts +1 -0
  31. package/{handlers → dist/handlers}/plugin.js +59 -27
  32. package/dist/handlers/user.d.ts +1 -0
  33. package/{handlers → dist/handlers}/user.js +45 -27
  34. package/dist/index.d.ts +1 -0
  35. package/{index.js → dist/index.js} +538 -449
  36. package/dist/jest.config.d.ts +1 -0
  37. package/dist/jest.config.js +65 -0
  38. package/dist/lib/analytics.d.ts +4 -0
  39. package/{lib → dist/lib}/analytics.js +8 -6
  40. package/dist/lib/authSession.d.ts +5 -0
  41. package/{lib → dist/lib}/authSession.js +15 -43
  42. package/dist/lib/cacheCleanup.d.ts +4 -0
  43. package/{lib → dist/lib}/cacheCleanup.js +5 -17
  44. package/dist/lib/callLogComposer.d.ts +109 -0
  45. package/{lib → dist/lib}/callLogComposer.js +157 -197
  46. package/dist/lib/callLogLookup.d.ts +6 -0
  47. package/{lib → dist/lib}/callLogLookup.js +12 -34
  48. package/dist/lib/constants.d.ts +6 -0
  49. package/dist/lib/constants.js +9 -0
  50. package/dist/lib/debugTracer.d.ts +17 -0
  51. package/{lib → dist/lib}/debugTracer.js +7 -83
  52. package/dist/lib/encode.d.ts +3 -0
  53. package/dist/lib/encode.js +50 -0
  54. package/dist/lib/errorHandler.d.ts +7 -0
  55. package/dist/lib/errorHandler.js +161 -0
  56. package/dist/lib/generalErrorMessage.d.ts +7 -0
  57. package/{lib → dist/lib}/generalErrorMessage.js +6 -6
  58. package/dist/lib/jwt.d.ts +4 -0
  59. package/dist/lib/jwt.js +18 -0
  60. package/dist/lib/logger.d.ts +24 -0
  61. package/dist/lib/logger.js +126 -0
  62. package/dist/lib/migrateCallLogsSchema.d.ts +32 -0
  63. package/{lib → dist/lib}/migrateCallLogsSchema.js +75 -160
  64. package/dist/lib/oauth.d.ts +4 -0
  65. package/{lib → dist/lib}/oauth.js +157 -160
  66. package/dist/lib/ringcentral.d.ts +24 -0
  67. package/dist/lib/ringcentral.js +226 -0
  68. package/dist/lib/s3ErrorLogReport.d.ts +4 -0
  69. package/{lib → dist/lib}/s3ErrorLogReport.js +11 -23
  70. package/dist/lib/sharedSMSComposer.d.ts +7 -0
  71. package/{lib → dist/lib}/sharedSMSComposer.js +21 -107
  72. package/dist/lib/util.d.ts +7 -0
  73. package/{lib → dist/lib}/util.js +9 -20
  74. package/dist/mcp/lib/oauthError.d.ts +1 -0
  75. package/dist/mcp/lib/oauthError.js +25 -0
  76. package/dist/mcp/lib/validator.d.ts +1 -0
  77. package/{mcp → dist/mcp}/lib/validator.js +16 -20
  78. package/dist/mcp/lib/widgetSessionToken.d.ts +1 -0
  79. package/dist/mcp/lib/widgetSessionToken.js +46 -0
  80. package/dist/mcp/mcpHandler.d.ts +8 -0
  81. package/{mcp → dist/mcp}/mcpHandler.js +98 -88
  82. package/dist/mcp/tools/cancelAppointment.d.ts +1 -0
  83. package/{mcp → dist/mcp}/tools/cancelAppointment.js +7 -16
  84. package/dist/mcp/tools/checkAuthStatus.d.ts +1 -0
  85. package/{mcp → dist/mcp}/tools/checkAuthStatus.js +21 -14
  86. package/dist/mcp/tools/confirmAppointment.d.ts +1 -0
  87. package/{mcp → dist/mcp}/tools/confirmAppointment.js +7 -16
  88. package/dist/mcp/tools/createAppointment.d.ts +1 -0
  89. package/{mcp → dist/mcp}/tools/createAppointment.js +7 -19
  90. package/dist/mcp/tools/createCallLog.d.ts +1 -0
  91. package/{mcp → dist/mcp}/tools/createCallLog.js +18 -29
  92. package/dist/mcp/tools/createContact.d.ts +1 -0
  93. package/{mcp → dist/mcp}/tools/createContact.js +8 -20
  94. package/dist/mcp/tools/createMessageLog.d.ts +1 -0
  95. package/{mcp → dist/mcp}/tools/createMessageLog.js +14 -26
  96. package/dist/mcp/tools/doAuth.d.ts +1 -0
  97. package/{mcp → dist/mcp}/tools/doAuth.js +17 -13
  98. package/dist/mcp/tools/findContactByName.d.ts +1 -0
  99. package/{mcp → dist/mcp}/tools/findContactByName.js +9 -15
  100. package/dist/mcp/tools/findContactByPhone.d.ts +1 -0
  101. package/{mcp → dist/mcp}/tools/findContactByPhone.js +8 -15
  102. package/dist/mcp/tools/getCallLog.d.ts +1 -0
  103. package/{mcp → dist/mcp}/tools/getCallLog.js +12 -21
  104. package/dist/mcp/tools/getGoogleFilePicker.d.ts +1 -0
  105. package/{mcp → dist/mcp}/tools/getGoogleFilePicker.js +9 -18
  106. package/dist/mcp/tools/getHelp.d.ts +1 -0
  107. package/{mcp → dist/mcp}/tools/getHelp.js +5 -6
  108. package/dist/mcp/tools/getPublicConnectors.d.ts +1 -0
  109. package/{mcp → dist/mcp}/tools/getPublicConnectors.js +19 -18
  110. package/dist/mcp/tools/getSessionInfo.d.ts +1 -0
  111. package/{mcp → dist/mcp}/tools/getSessionInfo.js +10 -16
  112. package/dist/mcp/tools/index.d.ts +8 -0
  113. package/dist/mcp/tools/index.js +50 -0
  114. package/dist/mcp/tools/listAppointments.d.ts +1 -0
  115. package/{mcp → dist/mcp}/tools/listAppointments.js +7 -19
  116. package/dist/mcp/tools/logout.d.ts +1 -0
  117. package/{mcp → dist/mcp}/tools/logout.js +16 -14
  118. package/dist/mcp/tools/rcGetCallLogs.d.ts +1 -0
  119. package/{mcp → dist/mcp}/tools/rcGetCallLogs.js +10 -8
  120. package/dist/mcp/tools/updateAppointment.d.ts +1 -0
  121. package/{mcp → dist/mcp}/tools/updateAppointment.js +17 -22
  122. package/dist/mcp/tools/updateCallLog.d.ts +1 -0
  123. package/{mcp → dist/mcp}/tools/updateCallLog.js +16 -26
  124. package/dist/models/accountDataModel.d.ts +3 -0
  125. package/dist/models/accountDataModel.js +39 -0
  126. package/dist/models/adminConfigModel.d.ts +2 -0
  127. package/dist/models/adminConfigModel.js +39 -0
  128. package/dist/models/cacheModel.d.ts +2 -0
  129. package/{models → dist/models}/cacheModel.js +7 -3
  130. package/dist/models/callDownListModel.d.ts +2 -0
  131. package/{models → dist/models}/callDownListModel.js +8 -4
  132. package/dist/models/callLogModel.d.ts +2 -0
  133. package/dist/models/callLogModel.js +43 -0
  134. package/dist/models/dynamo/connectorSchema.d.ts +2 -0
  135. package/dist/models/dynamo/connectorSchema.js +141 -0
  136. package/dist/models/dynamo/lockSchema.d.ts +2 -0
  137. package/{models → dist/models}/dynamo/lockSchema.js +5 -7
  138. package/dist/models/dynamo/noteCacheSchema.d.ts +2 -0
  139. package/{models → dist/models}/dynamo/noteCacheSchema.js +4 -6
  140. package/dist/models/llmSessionModel.d.ts +2 -0
  141. package/dist/models/llmSessionModel.js +21 -0
  142. package/dist/models/messageLogModel.d.ts +2 -0
  143. package/{models → dist/models}/messageLogModel.js +8 -4
  144. package/dist/models/sequelize.d.ts +2 -0
  145. package/dist/models/sequelize.js +68 -0
  146. package/dist/models/userModel.d.ts +2 -0
  147. package/dist/models/userModel.js +49 -0
  148. package/dist/package.json +100 -0
  149. package/dist/releaseNotes.json +1222 -0
  150. package/dist/tsconfig.json +14 -0
  151. package/dist/types/admin.d.ts +141 -0
  152. package/dist/types/analytics.d.ts +14 -0
  153. package/dist/types/appointment.d.ts +50 -0
  154. package/dist/types/auth.d.ts +137 -0
  155. package/dist/types/authSession.d.ts +35 -0
  156. package/dist/types/cacheCleanup.d.ts +12 -0
  157. package/dist/types/calldown.d.ts +54 -0
  158. package/dist/types/common.d.ts +46 -0
  159. package/dist/types/connector.d.ts +165 -0
  160. package/dist/types/contact.d.ts +125 -0
  161. package/dist/types/errorHandler.d.ts +60 -0
  162. package/dist/types/index.d.ts +76 -0
  163. package/dist/types/json.d.ts +9 -0
  164. package/dist/types/jwt.d.ts +8 -0
  165. package/dist/types/logging.d.ts +224 -0
  166. package/dist/types/managedAuth.d.ts +114 -0
  167. package/dist/types/managedOAuth.d.ts +59 -0
  168. package/dist/types/manifest.d.ts +120 -0
  169. package/dist/types/migration.d.ts +15 -0
  170. package/dist/types/plugin.d.ts +74 -0
  171. package/dist/types/ringcentral.d.ts +61 -0
  172. package/dist/types/s3ErrorLogReport.d.ts +16 -0
  173. package/dist/types/sharedSMSComposer.d.ts +105 -0
  174. package/dist/types/user.d.ts +46 -0
  175. package/dist/types/util.d.ts +7 -0
  176. package/package.json +34 -6
  177. package/releaseNotes.json +8 -0
  178. package/.env.test +0 -5
  179. package/connector/proxy/engine.js +0 -165
  180. package/connector/proxy/index.js +0 -500
  181. package/connector/registry.js +0 -252
  182. package/docs/README.md +0 -50
  183. package/docs/architecture.md +0 -94
  184. package/docs/connectors.md +0 -116
  185. package/docs/handlers.md +0 -128
  186. package/docs/libraries.md +0 -98
  187. package/docs/models.md +0 -146
  188. package/docs/routes.md +0 -119
  189. package/docs/tests.md +0 -73
  190. package/handlers/calldown.js +0 -99
  191. package/jest.config.js +0 -57
  192. package/lib/constants.js +0 -9
  193. package/lib/encode.js +0 -30
  194. package/lib/errorHandler.js +0 -218
  195. package/lib/jwt.js +0 -18
  196. package/lib/logger.js +0 -190
  197. package/lib/ringcentral.js +0 -267
  198. package/mcp/README.md +0 -420
  199. package/mcp/tools/index.js +0 -51
  200. package/mcp/ui/App/App.tsx +0 -358
  201. package/mcp/ui/App/components/AuthInfoForm.tsx +0 -113
  202. package/mcp/ui/App/components/AuthSuccess.tsx +0 -22
  203. package/mcp/ui/App/components/ConnectorList.tsx +0 -82
  204. package/mcp/ui/App/components/DebugPanel.tsx +0 -43
  205. package/mcp/ui/App/components/OAuthConnect.tsx +0 -270
  206. package/mcp/ui/App/lib/callTool.ts +0 -130
  207. package/mcp/ui/App/lib/debugLog.ts +0 -41
  208. package/mcp/ui/App/lib/developerPortal.ts +0 -111
  209. package/mcp/ui/App/main.css +0 -6
  210. package/mcp/ui/App/root.tsx +0 -13
  211. package/mcp/ui/dist/index.html +0 -53
  212. package/mcp/ui/vite.config.ts +0 -16
  213. package/models/accountDataModel.js +0 -34
  214. package/models/adminConfigModel.js +0 -35
  215. package/models/callLogModel.js +0 -39
  216. package/models/dynamo/connectorSchema.js +0 -146
  217. package/models/llmSessionModel.js +0 -17
  218. package/models/sequelize.js +0 -17
  219. package/models/userModel.js +0 -45
  220. package/test/connector/developerPortal.test.js +0 -166
  221. package/test/connector/mock.test.js +0 -131
  222. package/test/connector/proxy/engine.test.js +0 -211
  223. package/test/connector/proxy/index.test.js +0 -525
  224. package/test/connector/proxy/sample.json +0 -162
  225. package/test/connector/registry.test.js +0 -416
  226. package/test/handlers/admin.test.js +0 -960
  227. package/test/handlers/appointment.test.js +0 -260
  228. package/test/handlers/auth.test.js +0 -1096
  229. package/test/handlers/calldown.test.js +0 -310
  230. package/test/handlers/contact.test.js +0 -1014
  231. package/test/handlers/disposition.test.js +0 -396
  232. package/test/handlers/log.test.js +0 -1847
  233. package/test/handlers/managedAuth.test.js +0 -458
  234. package/test/handlers/managedOAuth.test.js +0 -262
  235. package/test/handlers/plugin.test.js +0 -429
  236. package/test/handlers/user.test.js +0 -381
  237. package/test/index.test.js +0 -301
  238. package/test/lib/analytics.test.js +0 -146
  239. package/test/lib/authSession.test.js +0 -173
  240. package/test/lib/cacheCleanup.test.js +0 -127
  241. package/test/lib/callLogComposer.test.js +0 -1231
  242. package/test/lib/debugTracer.test.js +0 -328
  243. package/test/lib/encode.test.js +0 -59
  244. package/test/lib/errorHandler.test.js +0 -246
  245. package/test/lib/generalErrorMessage.test.js +0 -82
  246. package/test/lib/jwt.test.js +0 -176
  247. package/test/lib/logger.test.js +0 -206
  248. package/test/lib/oauth.test.js +0 -359
  249. package/test/lib/ringcentral.test.js +0 -467
  250. package/test/lib/s3ErrorLogReport.test.js +0 -187
  251. package/test/lib/sharedSMSComposer.test.js +0 -1084
  252. package/test/lib/util.test.js +0 -329
  253. package/test/mcp/mcpHandler.test.js +0 -73
  254. package/test/mcp/mcpHandlerMore.test.js +0 -384
  255. package/test/mcp/tools/appointmentTools.test.js +0 -362
  256. package/test/mcp/tools/checkAuthStatus.test.js +0 -83
  257. package/test/mcp/tools/createCallLog.test.js +0 -436
  258. package/test/mcp/tools/createContact.test.js +0 -58
  259. package/test/mcp/tools/createMessageLog.test.js +0 -595
  260. package/test/mcp/tools/doAuth.test.js +0 -113
  261. package/test/mcp/tools/findContactByName.test.js +0 -275
  262. package/test/mcp/tools/findContactByPhone.test.js +0 -296
  263. package/test/mcp/tools/getCallLog.test.js +0 -298
  264. package/test/mcp/tools/getGoogleFilePicker.test.js +0 -281
  265. package/test/mcp/tools/getPublicConnectors.test.js +0 -107
  266. package/test/mcp/tools/getSessionInfo.test.js +0 -127
  267. package/test/mcp/tools/logout.test.js +0 -233
  268. package/test/mcp/tools/rcGetCallLogs.test.js +0 -56
  269. package/test/mcp/tools/updateCallLog.test.js +0 -360
  270. package/test/models/accountDataModel.test.js +0 -98
  271. package/test/models/callDownListModel.test.js +0 -125
  272. package/test/models/dynamo/connectorSchema.test.js +0 -189
  273. package/test/models/dynamo/lockSchema.test.js +0 -37
  274. package/test/models/dynamo/noteCacheSchema.test.js +0 -45
  275. package/test/models/llmSessionModel.test.js +0 -91
  276. package/test/models/models.test.js +0 -660
  277. package/test/routes/calldownRoutes.test.js +0 -224
  278. package/test/routes/coreRouterBroadRoutes.test.js +0 -855
  279. package/test/routes/dispositionRoutes.test.js +0 -192
  280. package/test/routes/managedAuthRoutes.test.js +0 -386
  281. package/test/routes/pluginRoutes.test.js +0 -262
  282. package/test/setup.js +0 -178
  283. /package/{mcp → dist/mcp}/ui/index.html +0 -0
  284. /package/{mcp → dist/mcp}/ui/package-lock.json +0 -0
  285. /package/{mcp → dist/mcp}/ui/package.json +0 -0
  286. /package/{mcp → dist/mcp}/ui/tsconfig.json +0 -0
@@ -1,360 +0,0 @@
1
- const updateCallLog = require('../../../mcp/tools/updateCallLog');
2
- const jwt = require('../../../lib/jwt');
3
- const connectorRegistry = require('../../../connector/registry');
4
- const logCore = require('../../../handlers/log');
5
- const util = require('../../../lib/util');
6
-
7
- // Mock dependencies
8
- jest.mock('../../../lib/jwt');
9
- jest.mock('../../../connector/registry');
10
- jest.mock('../../../handlers/log');
11
- jest.mock('../../../lib/util');
12
-
13
- describe('MCP Tool: updateCallLog', () => {
14
- beforeEach(() => {
15
- jest.clearAllMocks();
16
- process.env.HASH_KEY = 'test-hash-key';
17
- });
18
-
19
- describe('tool definition', () => {
20
- test('should have correct tool definition', () => {
21
- expect(updateCallLog.definition).toBeDefined();
22
- expect(updateCallLog.definition.name).toBe('updateCallLog');
23
- expect(updateCallLog.definition.description).toContain('REQUIRES AUTHENTICATION');
24
- expect(updateCallLog.definition.inputSchema).toBeDefined();
25
- });
26
-
27
- test('should require jwtToken and incomingData parameters', () => {
28
- expect(updateCallLog.definition.inputSchema.required).toContain('jwtToken');
29
- expect(updateCallLog.definition.inputSchema.required).toContain('incomingData');
30
- });
31
-
32
- test('should require sessionId in incomingData', () => {
33
- const incomingDataSchema = updateCallLog.definition.inputSchema.properties.incomingData;
34
- expect(incomingDataSchema.required).toContain('sessionId');
35
- });
36
- });
37
-
38
- describe('execute', () => {
39
- test('should update call log successfully', async () => {
40
- // Arrange
41
- const mockIncomingData = {
42
- sessionId: 'session-123',
43
- note: 'Updated call note',
44
- accountId: 'rc-account-123'
45
- };
46
-
47
- jwt.decodeJwt.mockReturnValue({
48
- id: 'user-123',
49
- platform: 'testCRM'
50
- });
51
-
52
- const mockConnector = {
53
- updateCallLog: jest.fn()
54
- };
55
- connectorRegistry.getConnector.mockReturnValue(mockConnector);
56
-
57
- util.getHashValue.mockReturnValue('hashed-account-id');
58
-
59
- logCore.updateCallLog.mockResolvedValue({
60
- successful: true,
61
- logId: 'crm-log-123',
62
- updatedNote: 'Updated call note',
63
- returnMessage: { message: 'Call log updated successfully' }
64
- });
65
-
66
- // Act
67
- const result = await updateCallLog.execute({
68
- jwtToken: 'mock-jwt-token',
69
- incomingData: mockIncomingData
70
- });
71
-
72
- // Assert
73
- expect(result).toEqual({
74
- success: true,
75
- data: {
76
- logId: 'crm-log-123',
77
- updatedNote: 'Updated call note',
78
- message: 'Call log updated successfully'
79
- }
80
- });
81
- expect(jwt.decodeJwt).toHaveBeenCalledWith('mock-jwt-token');
82
- expect(util.getHashValue).toHaveBeenCalledWith('rc-account-123', 'test-hash-key');
83
- expect(logCore.updateCallLog).toHaveBeenCalledWith({
84
- platform: 'testCRM',
85
- userId: 'user-123',
86
- incomingData: mockIncomingData,
87
- hashedAccountId: 'hashed-account-id',
88
- isFromSSCL: false
89
- });
90
- });
91
-
92
- test('should update call log with additional submission', async () => {
93
- // Arrange
94
- const mockIncomingData = {
95
- sessionId: 'session-456',
96
- note: 'Updated note with additional data',
97
- additionalSubmission: {
98
- dealId: 'deal-123',
99
- customField: 'custom-value'
100
- }
101
- };
102
-
103
- jwt.decodeJwt.mockReturnValue({
104
- id: 'user-123',
105
- platform: 'testCRM'
106
- });
107
-
108
- const mockConnector = {
109
- updateCallLog: jest.fn()
110
- };
111
- connectorRegistry.getConnector.mockReturnValue(mockConnector);
112
-
113
- logCore.updateCallLog.mockResolvedValue({
114
- successful: true,
115
- logId: 'crm-log-456',
116
- updatedNote: 'Updated note with additional data'
117
- });
118
-
119
- // Act
120
- const result = await updateCallLog.execute({
121
- jwtToken: 'mock-jwt-token',
122
- incomingData: mockIncomingData
123
- });
124
-
125
- // Assert
126
- expect(result.success).toBe(true);
127
- expect(result.data.logId).toBe('crm-log-456');
128
- });
129
-
130
- test('should update call log without accountId', async () => {
131
- // Arrange
132
- const mockIncomingData = {
133
- sessionId: 'session-789',
134
- note: 'Simple update'
135
- };
136
-
137
- jwt.decodeJwt.mockReturnValue({
138
- id: 'user-123',
139
- platform: 'testCRM'
140
- });
141
-
142
- const mockConnector = {
143
- updateCallLog: jest.fn()
144
- };
145
- connectorRegistry.getConnector.mockReturnValue(mockConnector);
146
-
147
- logCore.updateCallLog.mockResolvedValue({
148
- successful: true,
149
- logId: 'crm-log-789',
150
- updatedNote: 'Simple update'
151
- });
152
-
153
- // Act
154
- const result = await updateCallLog.execute({
155
- jwtToken: 'mock-jwt-token',
156
- incomingData: mockIncomingData
157
- });
158
-
159
- // Assert
160
- expect(result.success).toBe(true);
161
- expect(util.getHashValue).not.toHaveBeenCalled();
162
- expect(logCore.updateCallLog).toHaveBeenCalledWith({
163
- platform: 'testCRM',
164
- userId: 'user-123',
165
- incomingData: mockIncomingData,
166
- hashedAccountId: undefined,
167
- isFromSSCL: false
168
- });
169
- });
170
-
171
- test('should return error when JWT is invalid', async () => {
172
- // Arrange
173
- const mockIncomingData = {
174
- sessionId: 'session-123',
175
- note: 'Test note'
176
- };
177
-
178
- jwt.decodeJwt.mockReturnValue({
179
- platform: 'testCRM'
180
- // id is missing
181
- });
182
-
183
- // Act
184
- const result = await updateCallLog.execute({
185
- jwtToken: 'invalid-token',
186
- incomingData: mockIncomingData
187
- });
188
-
189
- // Assert
190
- expect(result.success).toBe(false);
191
- expect(result.error).toContain('Invalid JWT token');
192
- });
193
-
194
- test('should return error when decodeJwt returns null', async () => {
195
- jwt.decodeJwt.mockReturnValue(null);
196
-
197
- const result = await updateCallLog.execute({
198
- jwtToken: 'invalid-token',
199
- incomingData: {
200
- logData: { sessionId: 'session-123' }
201
- }
202
- });
203
-
204
- expect(result.success).toBe(false);
205
- expect(result.error).toContain('Invalid JWT token');
206
- });
207
-
208
- test('should return error when platform connector not found', async () => {
209
- // Arrange
210
- const mockIncomingData = {
211
- sessionId: 'session-123',
212
- note: 'Test note'
213
- };
214
-
215
- jwt.decodeJwt.mockReturnValue({
216
- id: 'user-123',
217
- platform: 'unknownCRM'
218
- });
219
-
220
- connectorRegistry.getConnector.mockReturnValue(null);
221
-
222
- // Act
223
- const result = await updateCallLog.execute({
224
- jwtToken: 'mock-jwt-token',
225
- incomingData: mockIncomingData
226
- });
227
-
228
- // Assert
229
- expect(result.success).toBe(false);
230
- expect(result.error).toContain('Platform connector not found');
231
- });
232
-
233
- test('should return error when updateCallLog is not implemented', async () => {
234
- // Arrange
235
- const mockIncomingData = {
236
- sessionId: 'session-123',
237
- note: 'Test note'
238
- };
239
-
240
- jwt.decodeJwt.mockReturnValue({
241
- id: 'user-123',
242
- platform: 'testCRM'
243
- });
244
-
245
- const mockConnector = {}; // No updateCallLog method
246
- connectorRegistry.getConnector.mockReturnValue(mockConnector);
247
-
248
- // Act
249
- const result = await updateCallLog.execute({
250
- jwtToken: 'mock-jwt-token',
251
- incomingData: mockIncomingData
252
- });
253
-
254
- // Assert
255
- expect(result.success).toBe(false);
256
- expect(result.error).toContain('not implemented');
257
- });
258
-
259
- test('should return error when update fails', async () => {
260
- // Arrange
261
- const mockIncomingData = {
262
- sessionId: 'session-999',
263
- note: 'Test note'
264
- };
265
-
266
- jwt.decodeJwt.mockReturnValue({
267
- id: 'user-123',
268
- platform: 'testCRM'
269
- });
270
-
271
- const mockConnector = {
272
- updateCallLog: jest.fn()
273
- };
274
- connectorRegistry.getConnector.mockReturnValue(mockConnector);
275
-
276
- logCore.updateCallLog.mockResolvedValue({
277
- successful: false,
278
- returnMessage: { message: 'Log not found in CRM' }
279
- });
280
-
281
- // Act
282
- const result = await updateCallLog.execute({
283
- jwtToken: 'mock-jwt-token',
284
- incomingData: mockIncomingData
285
- });
286
-
287
- // Assert
288
- expect(result.success).toBe(false);
289
- expect(result.error).toBe('Log not found in CRM');
290
- });
291
-
292
- test('should handle unexpected errors gracefully', async () => {
293
- // Arrange
294
- const mockIncomingData = {
295
- sessionId: 'session-error',
296
- note: 'Test note'
297
- };
298
-
299
- jwt.decodeJwt.mockReturnValue({
300
- id: 'user-123',
301
- platform: 'testCRM'
302
- });
303
-
304
- const mockConnector = {
305
- updateCallLog: jest.fn()
306
- };
307
- connectorRegistry.getConnector.mockReturnValue(mockConnector);
308
-
309
- logCore.updateCallLog.mockRejectedValue(
310
- new Error('API timeout')
311
- );
312
-
313
- // Act
314
- const result = await updateCallLog.execute({
315
- jwtToken: 'mock-jwt-token',
316
- incomingData: mockIncomingData
317
- });
318
-
319
- // Assert
320
- expect(result.success).toBe(false);
321
- expect(result.error).toBe('API timeout');
322
- expect(result.errorDetails).toBeDefined();
323
- });
324
-
325
- test('should update call log with empty note', async () => {
326
- // Arrange
327
- const mockIncomingData = {
328
- sessionId: 'session-empty-note',
329
- note: ''
330
- };
331
-
332
- jwt.decodeJwt.mockReturnValue({
333
- id: 'user-123',
334
- platform: 'testCRM'
335
- });
336
-
337
- const mockConnector = {
338
- updateCallLog: jest.fn()
339
- };
340
- connectorRegistry.getConnector.mockReturnValue(mockConnector);
341
-
342
- logCore.updateCallLog.mockResolvedValue({
343
- successful: true,
344
- logId: 'crm-log-empty',
345
- updatedNote: ''
346
- });
347
-
348
- // Act
349
- const result = await updateCallLog.execute({
350
- jwtToken: 'mock-jwt-token',
351
- incomingData: mockIncomingData
352
- });
353
-
354
- // Assert
355
- expect(result.success).toBe(true);
356
- expect(result.data.updatedNote).toBe('');
357
- });
358
- });
359
- });
360
-
@@ -1,98 +0,0 @@
1
- // Use in-memory SQLite for isolated model tests
2
- jest.mock('../../models/sequelize', () => {
3
- const { Sequelize } = require('sequelize');
4
- return {
5
- sequelize: new Sequelize({
6
- dialect: 'sqlite',
7
- storage: ':memory:',
8
- logging: false,
9
- }),
10
- };
11
- });
12
-
13
- const { AccountDataModel, getOrRefreshAccountData } = require('../../models/accountDataModel');
14
- const { sequelize } = require('../../models/sequelize');
15
-
16
- describe('getOrRefreshAccountData', () => {
17
- beforeAll(async () => {
18
- await AccountDataModel.sync({ force: true });
19
- });
20
-
21
- afterEach(async () => {
22
- await AccountDataModel.destroy({ where: {} });
23
- });
24
-
25
- afterAll(async () => {
26
- await sequelize.close();
27
- });
28
-
29
- test('returns cached data when record exists and refresh not forced', async () => {
30
- await AccountDataModel.create({
31
- rcAccountId: 'acc-1',
32
- platformName: 'test-platform',
33
- dataKey: 'key-1',
34
- data: { cached: true },
35
- });
36
-
37
- const fetchFn = jest.fn().mockResolvedValue({ cached: false });
38
-
39
- const out = await getOrRefreshAccountData({
40
- rcAccountId: 'acc-1',
41
- platformName: 'test-platform',
42
- dataKey: 'key-1',
43
- forceRefresh: false,
44
- fetchFn,
45
- });
46
-
47
- expect(out).toEqual({ cached: true });
48
- expect(fetchFn).not.toHaveBeenCalled();
49
- });
50
-
51
- test('creates new record when none exists', async () => {
52
- const fetchFn = jest.fn().mockResolvedValue({ fresh: 'data' });
53
-
54
- const out = await getOrRefreshAccountData({
55
- rcAccountId: 'acc-2',
56
- platformName: 'test-platform',
57
- dataKey: 'key-2',
58
- fetchFn,
59
- });
60
-
61
- expect(out).toEqual({ fresh: 'data' });
62
- expect(fetchFn).toHaveBeenCalledTimes(1);
63
-
64
- const stored = await AccountDataModel.findOne({
65
- where: { rcAccountId: 'acc-2', platformName: 'test-platform', dataKey: 'key-2' },
66
- });
67
- expect(stored).not.toBeNull();
68
- expect(stored.data).toEqual({ fresh: 'data' });
69
- });
70
-
71
- test('refreshes existing record when forceRefresh is true', async () => {
72
- await AccountDataModel.create({
73
- rcAccountId: 'acc-3',
74
- platformName: 'test-platform',
75
- dataKey: 'key-3',
76
- data: { cached: true },
77
- });
78
-
79
- const fetchFn = jest.fn().mockResolvedValue({ cached: false, updated: true });
80
-
81
- const out = await getOrRefreshAccountData({
82
- rcAccountId: 'acc-3',
83
- platformName: 'test-platform',
84
- dataKey: 'key-3',
85
- forceRefresh: true,
86
- fetchFn,
87
- });
88
-
89
- expect(fetchFn).toHaveBeenCalledTimes(1);
90
- expect(out).toEqual({ cached: false, updated: true });
91
-
92
- const refreshed = await AccountDataModel.findOne({
93
- where: { rcAccountId: 'acc-3', platformName: 'test-platform', dataKey: 'key-3' },
94
- });
95
- expect(refreshed.data).toEqual({ cached: false, updated: true });
96
- });
97
- });
98
-
@@ -1,125 +0,0 @@
1
- const { CallDownListModel } = require('../../models/callDownListModel');
2
-
3
- describe('CallDownListModel', () => {
4
- beforeAll(async () => {
5
- await CallDownListModel.sync({ force: true });
6
- });
7
-
8
- afterEach(async () => {
9
- await CallDownListModel.destroy({ where: {} });
10
- });
11
-
12
- test('defines the expected fields and indexes', () => {
13
- const attributes = CallDownListModel.rawAttributes;
14
-
15
- expect(attributes.id.primaryKey).toBe(true);
16
- expect(attributes.userId.type.key).toBe('STRING');
17
- expect(attributes.contactId.type.key).toBe('STRING');
18
- expect(attributes.contactType.type.key).toBe('STRING');
19
- expect(attributes.status.type.key).toBe('STRING');
20
- expect(attributes.scheduledAt.type.key).toBe('DATE');
21
- expect(attributes.lastCallAt.type.key).toBe('DATE');
22
- expect(CallDownListModel.options.timestamps).toBe(true);
23
- expect(CallDownListModel.options.indexes).toEqual(expect.arrayContaining([
24
- expect.objectContaining({ fields: ['userId'] }),
25
- expect.objectContaining({ fields: ['status'] }),
26
- expect.objectContaining({ fields: ['scheduledAt'] }),
27
- expect.objectContaining({ fields: ['userId', 'status'] }),
28
- ]));
29
- });
30
-
31
- test('creates and reads a scheduled callback record', async () => {
32
- const scheduledAt = new Date('2026-07-02T10:00:00.000Z');
33
-
34
- await CallDownListModel.create({
35
- id: 'call-down-1',
36
- userId: 'user-1',
37
- contactId: 'contact-1',
38
- contactType: 'Lead',
39
- status: 'Pending',
40
- scheduledAt,
41
- });
42
-
43
- const record = await CallDownListModel.findByPk('call-down-1');
44
-
45
- expect(record).toMatchObject({
46
- id: 'call-down-1',
47
- userId: 'user-1',
48
- contactId: 'contact-1',
49
- contactType: 'Lead',
50
- status: 'Pending',
51
- });
52
- expect(record.scheduledAt.toISOString()).toBe('2026-07-02T10:00:00.000Z');
53
- expect(record.lastCallAt).toBeNull();
54
- });
55
-
56
- test('allows nullable fields under the current schema', async () => {
57
- await CallDownListModel.create({
58
- id: 'minimal-call-down',
59
- });
60
-
61
- const record = await CallDownListModel.findByPk('minimal-call-down');
62
-
63
- expect(record.userId).toBeNull();
64
- expect(record.contactId).toBeNull();
65
- expect(record.status).toBeNull();
66
- expect(record.scheduledAt).toBeNull();
67
- expect(record.lastCallAt).toBeNull();
68
- });
69
-
70
- test('updates callback status and last call time', async () => {
71
- await CallDownListModel.create({
72
- id: 'call-down-update',
73
- userId: 'user-1',
74
- contactId: 'contact-1',
75
- contactType: 'Contact',
76
- status: 'Pending',
77
- scheduledAt: new Date('2026-07-02T10:00:00.000Z'),
78
- });
79
-
80
- const lastCallAt = new Date('2026-07-02T10:30:00.000Z');
81
- await CallDownListModel.update({
82
- status: 'Called',
83
- lastCallAt,
84
- }, {
85
- where: { id: 'call-down-update' },
86
- });
87
-
88
- const record = await CallDownListModel.findByPk('call-down-update');
89
- expect(record.status).toBe('Called');
90
- expect(record.lastCallAt.toISOString()).toBe('2026-07-02T10:30:00.000Z');
91
- });
92
-
93
- test('queries by user and status together', async () => {
94
- await CallDownListModel.bulkCreate([
95
- {
96
- id: 'call-down-user-1-pending',
97
- userId: 'user-1',
98
- status: 'Pending',
99
- scheduledAt: new Date('2026-07-02T10:00:00.000Z'),
100
- },
101
- {
102
- id: 'call-down-user-1-called',
103
- userId: 'user-1',
104
- status: 'Called',
105
- scheduledAt: new Date('2026-07-02T11:00:00.000Z'),
106
- },
107
- {
108
- id: 'call-down-user-2-pending',
109
- userId: 'user-2',
110
- status: 'Pending',
111
- scheduledAt: new Date('2026-07-02T12:00:00.000Z'),
112
- },
113
- ]);
114
-
115
- const records = await CallDownListModel.findAll({
116
- where: {
117
- userId: 'user-1',
118
- status: 'Pending',
119
- },
120
- });
121
-
122
- expect(records).toHaveLength(1);
123
- expect(records[0].id).toBe('call-down-user-1-pending');
124
- });
125
- });