@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,1084 +0,0 @@
1
- const {
2
- composeSharedSMSLog,
3
- gatherParticipants,
4
- countEntities,
5
- processEntities,
6
- escapeHtml
7
- } = require('../../lib/sharedSMSComposer');
8
- const { LOG_DETAILS_FORMAT_TYPE } = require('../../lib/constants');
9
-
10
- describe('sharedSMSComposer', () => {
11
- describe('composeSharedSMSLog', () => {
12
- const baseConversation = {
13
- creationTime: '2024-01-15T10:30:00Z',
14
- messages: [
15
- { lastModifiedTime: '2024-01-15T10:30:00Z' },
16
- { lastModifiedTime: '2024-01-15T11:45:00Z' }
17
- ],
18
- entities: [
19
- {
20
- recordType: 'AliveMessage',
21
- creationTime: '2024-01-15T10:30:00Z',
22
- direction: 'Inbound',
23
- author: { name: 'John Customer' },
24
- text: 'Hello, I need help'
25
- },
26
- {
27
- recordType: 'AliveMessage',
28
- creationTime: '2024-01-15T10:35:00Z',
29
- direction: 'Outbound',
30
- author: { name: 'Agent Smith' },
31
- text: 'Hi! How can I assist you?'
32
- }
33
- ],
34
- owner: {
35
- name: 'Support Team',
36
- extensionType: 'User',
37
- extensionId: '12345'
38
- }
39
- };
40
-
41
- test('should compose SMS log with default settings (plain text)', () => {
42
- const result = composeSharedSMSLog({
43
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
44
- conversation: baseConversation,
45
- contactName: 'John Customer',
46
- timezoneOffset: '+00:00'
47
- });
48
-
49
- expect(result.subject).toBe('SMS conversation with John Customer');
50
- expect(result.body).toContain('Conversation summary');
51
- expect(result.body).toContain('John Customer (customer)');
52
- expect(result.body).toContain('BEGIN');
53
- expect(result.body).toContain('END');
54
- });
55
-
56
- test('should compose SMS log in HTML format', () => {
57
- const result = composeSharedSMSLog({
58
- logFormat: LOG_DETAILS_FORMAT_TYPE.HTML,
59
- conversation: baseConversation,
60
- contactName: 'John Customer',
61
- timezoneOffset: '+00:00'
62
- });
63
-
64
- expect(result.subject).toBe('SMS conversation with John Customer');
65
- expect(result.body).toContain('<b>Conversation summary</b>');
66
- expect(result.body).toContain('<b>Participants</b>');
67
- expect(result.body).toContain('<li>');
68
- });
69
-
70
- test('should compose SMS log in Markdown format', () => {
71
- const result = composeSharedSMSLog({
72
- logFormat: LOG_DETAILS_FORMAT_TYPE.MARKDOWN,
73
- conversation: baseConversation,
74
- contactName: 'John Customer',
75
- timezoneOffset: '+00:00'
76
- });
77
-
78
- expect(result.subject).toBe('**SMS conversation with John Customer**');
79
- expect(result.body).toContain('## Conversation summary');
80
- expect(result.body).toContain('### Participants');
81
- expect(result.body).toContain('---');
82
- });
83
-
84
- test('should handle conversation with call queue owner', () => {
85
- const conversationWithQueue = {
86
- ...baseConversation,
87
- owner: {
88
- name: 'Sales Queue',
89
- extensionType: 'Department',
90
- extensionId: '99999'
91
- }
92
- };
93
-
94
- const result = composeSharedSMSLog({
95
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
96
- conversation: conversationWithQueue,
97
- contactName: 'John Customer',
98
- timezoneOffset: '+00:00'
99
- });
100
-
101
- expect(result.body).toContain('Receiving call queue: Sales Queue');
102
- });
103
-
104
- test('should handle conversation with notes', () => {
105
- const conversationWithNotes = {
106
- ...baseConversation,
107
- entities: [
108
- ...baseConversation.entities,
109
- {
110
- recordType: 'AliveNote',
111
- creationTime: '2024-01-15T10:40:00Z',
112
- author: { name: 'Agent Smith' },
113
- text: 'Customer prefers email contact'
114
- }
115
- ]
116
- };
117
-
118
- const result = composeSharedSMSLog({
119
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
120
- conversation: conversationWithNotes,
121
- contactName: 'John Customer',
122
- timezoneOffset: '+00:00'
123
- });
124
-
125
- expect(result.body).toContain('2 messages');
126
- expect(result.body).toContain('1 note');
127
- expect(result.body).toContain('left a note');
128
- });
129
-
130
- test('should handle conversation with assignment', () => {
131
- const conversationWithAssignment = {
132
- ...baseConversation,
133
- entities: [
134
- ...baseConversation.entities,
135
- {
136
- recordType: 'ThreadAssignedHint',
137
- creationTime: '2024-01-15T10:32:00Z',
138
- assignee: { name: 'Agent Smith' }
139
- }
140
- ]
141
- };
142
-
143
- const result = composeSharedSMSLog({
144
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
145
- conversation: conversationWithAssignment,
146
- contactName: 'John Customer',
147
- timezoneOffset: '+00:00'
148
- });
149
-
150
- expect(result.body).toContain('Conversation assigned to Agent Smith');
151
- });
152
-
153
- test('should skip ThreadResolvedHint entities (not processed)', () => {
154
- const conversationWithResolved = {
155
- ...baseConversation,
156
- entities: [
157
- ...baseConversation.entities,
158
- {
159
- recordType: 'ThreadResolvedHint',
160
- creationTime: '2024-01-15T11:45:00Z',
161
- initiator: { name: 'Agent Smith' }
162
- }
163
- ]
164
- };
165
-
166
- const result = composeSharedSMSLog({
167
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
168
- conversation: conversationWithResolved,
169
- contactName: 'John Customer',
170
- timezoneOffset: '+00:00'
171
- });
172
-
173
- // ThreadResolvedHint is not processed, so it won't appear in the body
174
- expect(result.body).not.toContain('resolved the conversation');
175
- });
176
-
177
- test('should skip ThreadReopenedHint entities (not processed)', () => {
178
- const conversationWithReopened = {
179
- ...baseConversation,
180
- entities: [
181
- ...baseConversation.entities,
182
- {
183
- recordType: 'ThreadReopenedHint',
184
- creationTime: '2024-01-15T12:00:00Z',
185
- initiator: { name: 'Agent Smith' }
186
- }
187
- ]
188
- };
189
-
190
- const result = composeSharedSMSLog({
191
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
192
- conversation: conversationWithReopened,
193
- contactName: 'John Customer',
194
- timezoneOffset: '+00:00'
195
- });
196
-
197
- // ThreadReopenedHint is not processed, so it won't appear in the body
198
- expect(result.body).not.toContain('reopened the conversation');
199
- });
200
-
201
- test('should apply timezone offset', () => {
202
- const result = composeSharedSMSLog({
203
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
204
- conversation: baseConversation,
205
- contactName: 'John Customer',
206
- timezoneOffset: '+05:00'
207
- });
208
-
209
- // The time should be adjusted by +5 hours
210
- expect(result.body).toContain('Started:');
211
- });
212
-
213
- test('should handle empty entities array', () => {
214
- const emptyConversation = {
215
- creationTime: '2024-01-15T10:30:00Z',
216
- messages: [{ lastModifiedTime: '2024-01-15T11:45:00Z' }],
217
- entities: []
218
- };
219
-
220
- const result = composeSharedSMSLog({
221
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
222
- conversation: emptyConversation,
223
- contactName: 'John Customer',
224
- timezoneOffset: '+00:00'
225
- });
226
-
227
- expect(result.body).toContain('0 messages');
228
- });
229
-
230
- test('should handle missing entities', () => {
231
- const noEntitiesConversation = {
232
- creationTime: '2024-01-15T10:30:00Z',
233
- messages: [{ lastModifiedTime: '2024-01-15T11:45:00Z' }]
234
- };
235
-
236
- const result = composeSharedSMSLog({
237
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
238
- conversation: noEntitiesConversation,
239
- contactName: 'John Customer',
240
- timezoneOffset: '+00:00'
241
- });
242
-
243
- expect(result.body).toContain('0 messages');
244
- });
245
- });
246
-
247
- describe('gatherParticipants', () => {
248
- test('should gather participants from author names', () => {
249
- const entities = [
250
- { author: { name: 'Agent Smith' } },
251
- { author: { name: 'Agent Jones' } }
252
- ];
253
-
254
- const result = gatherParticipants(entities);
255
-
256
- expect(result).toContain('Agent Smith');
257
- expect(result).toContain('Agent Jones');
258
- });
259
-
260
- test('should gather participants from from names', () => {
261
- const entities = [
262
- { from: { name: 'Customer John' } }
263
- ];
264
-
265
- const result = gatherParticipants(entities);
266
-
267
- expect(result).toContain('Customer John');
268
- });
269
-
270
- test('should gather participants from initiator names', () => {
271
- const entities = [
272
- { initiator: { name: 'Manager Bob' } }
273
- ];
274
-
275
- const result = gatherParticipants(entities);
276
-
277
- expect(result).toContain('Manager Bob');
278
- });
279
-
280
- test('should gather participants from assignee names', () => {
281
- const entities = [
282
- { assignee: { name: 'Agent Smith' } }
283
- ];
284
-
285
- const result = gatherParticipants(entities);
286
-
287
- expect(result).toContain('Agent Smith');
288
- });
289
-
290
- test('should deduplicate participants', () => {
291
- const entities = [
292
- { author: { name: 'Agent Smith' } },
293
- { from: { name: 'Agent Smith' } },
294
- { initiator: { name: 'Agent Smith' } }
295
- ];
296
-
297
- const result = gatherParticipants(entities);
298
-
299
- expect(result).toHaveLength(1);
300
- expect(result).toContain('Agent Smith');
301
- });
302
-
303
- test('should handle empty entities array', () => {
304
- const result = gatherParticipants([]);
305
-
306
- expect(result).toEqual([]);
307
- });
308
-
309
- test('should handle entities without names', () => {
310
- const entities = [
311
- { author: {} },
312
- { from: null },
313
- {}
314
- ];
315
-
316
- const result = gatherParticipants(entities);
317
-
318
- expect(result).toEqual([]);
319
- });
320
- });
321
-
322
- describe('countEntities', () => {
323
- test('should count messages correctly', () => {
324
- const entities = [
325
- { recordType: 'AliveMessage' },
326
- { recordType: 'AliveMessage' },
327
- { recordType: 'AliveMessage' }
328
- ];
329
-
330
- const result = countEntities(entities);
331
-
332
- expect(result.messageCount).toBe(3);
333
- expect(result.noteCount).toBe(0);
334
- });
335
-
336
- test('should count AliveNote as note', () => {
337
- const entities = [
338
- { recordType: 'AliveNote' },
339
- { recordType: 'AliveNote' }
340
- ];
341
-
342
- const result = countEntities(entities);
343
-
344
- expect(result.messageCount).toBe(0);
345
- expect(result.noteCount).toBe(2);
346
- });
347
-
348
- test('should not count NoteHint as note (only AliveNote is counted)', () => {
349
- const entities = [
350
- { recordType: 'NoteHint' },
351
- { recordType: 'ThreadNoteAddedHint' }
352
- ];
353
-
354
- const result = countEntities(entities);
355
-
356
- expect(result.messageCount).toBe(0);
357
- expect(result.noteCount).toBe(0);
358
- });
359
-
360
- test('should not count ThreadAssignedHint as note', () => {
361
- const entities = [
362
- { recordType: 'ThreadAssignedHint' }
363
- ];
364
-
365
- const result = countEntities(entities);
366
-
367
- expect(result.noteCount).toBe(0);
368
- });
369
-
370
- test('should count both messages and notes', () => {
371
- const entities = [
372
- { recordType: 'AliveMessage' },
373
- { recordType: 'AliveMessage' },
374
- { recordType: 'AliveNote' },
375
- { recordType: 'AliveNote' }
376
- ];
377
-
378
- const result = countEntities(entities);
379
-
380
- expect(result.messageCount).toBe(2);
381
- expect(result.noteCount).toBe(2);
382
- });
383
-
384
- test('should return zero counts for empty array', () => {
385
- const result = countEntities([]);
386
-
387
- expect(result.messageCount).toBe(0);
388
- expect(result.noteCount).toBe(0);
389
- });
390
-
391
- test('should ignore other record types', () => {
392
- const entities = [
393
- { recordType: 'ThreadResolvedHint' },
394
- { recordType: 'ThreadReopenedHint' },
395
- { recordType: 'ThreadCreatedHint' },
396
- { recordType: 'NoteHint' },
397
- { recordType: 'ThreadNoteAddedHint' },
398
- { recordType: 'ThreadAssignedHint' }
399
- ];
400
-
401
- const result = countEntities(entities);
402
-
403
- expect(result.messageCount).toBe(0);
404
- expect(result.noteCount).toBe(0);
405
- });
406
- });
407
-
408
- describe('processEntities', () => {
409
- test('should process message entities (plain text)', () => {
410
- const entities = [
411
- {
412
- recordType: 'AliveMessage',
413
- creationTime: '2024-01-15T10:30:00Z',
414
- direction: 'Inbound',
415
- author: { name: 'Customer' },
416
- text: 'Hello!'
417
- }
418
- ];
419
-
420
- const result = processEntities({
421
- entities,
422
- timezoneOffset: '+00:00',
423
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
424
- contactName: 'Customer'
425
- });
426
-
427
- expect(result).toHaveLength(1);
428
- expect(result[0].type).toBe('message');
429
- expect(result[0].content).toContain('said on');
430
- expect(result[0].content).toContain('Hello!');
431
- });
432
-
433
- test('should process message entities (HTML)', () => {
434
- const entities = [
435
- {
436
- recordType: 'AliveMessage',
437
- creationTime: '2024-01-15T10:30:00Z',
438
- direction: 'Outbound',
439
- author: { name: 'Agent' },
440
- text: 'Hi there!'
441
- }
442
- ];
443
-
444
- const result = processEntities({
445
- entities,
446
- timezoneOffset: '+00:00',
447
- logFormat: LOG_DETAILS_FORMAT_TYPE.HTML,
448
- contactName: 'Customer'
449
- });
450
-
451
- expect(result).toHaveLength(1);
452
- expect(result[0].content).toContain('<p>');
453
- expect(result[0].content).toContain('<b>');
454
- });
455
-
456
- test('should process message entities (Markdown)', () => {
457
- const entities = [
458
- {
459
- recordType: 'AliveMessage',
460
- creationTime: '2024-01-15T10:30:00Z',
461
- direction: 'Outbound',
462
- author: { name: 'Agent' },
463
- text: 'Hi there!'
464
- }
465
- ];
466
-
467
- const result = processEntities({
468
- entities,
469
- timezoneOffset: '+00:00',
470
- logFormat: LOG_DETAILS_FORMAT_TYPE.MARKDOWN,
471
- contactName: 'Customer'
472
- });
473
-
474
- expect(result).toHaveLength(1);
475
- expect(result[0].content).toContain('**');
476
- });
477
-
478
- test('should process assignment entities', () => {
479
- const entities = [
480
- {
481
- recordType: 'ThreadAssignedHint',
482
- creationTime: '2024-01-15T10:30:00Z',
483
- assignee: { name: 'Agent Smith' }
484
- }
485
- ];
486
-
487
- const result = processEntities({
488
- entities,
489
- timezoneOffset: '+00:00',
490
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
491
- contactName: 'Customer'
492
- });
493
-
494
- expect(result).toHaveLength(1);
495
- expect(result[0].type).toBe('assignment');
496
- expect(result[0].content).toContain('assigned to Agent Smith');
497
- });
498
-
499
- test('should skip ThreadResolvedHint entities', () => {
500
- const entities = [
501
- {
502
- recordType: 'ThreadResolvedHint',
503
- creationTime: '2024-01-15T10:30:00Z',
504
- initiator: { name: 'Agent Smith' }
505
- }
506
- ];
507
-
508
- const result = processEntities({
509
- entities,
510
- timezoneOffset: '+00:00',
511
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
512
- contactName: 'Customer'
513
- });
514
-
515
- // ThreadResolvedHint is not processed (returns null)
516
- expect(result).toHaveLength(0);
517
- });
518
-
519
- test('should skip ThreadReopenedHint entities', () => {
520
- const entities = [
521
- {
522
- recordType: 'ThreadReopenedHint',
523
- creationTime: '2024-01-15T10:30:00Z',
524
- initiator: { name: 'Agent Smith' }
525
- }
526
- ];
527
-
528
- const result = processEntities({
529
- entities,
530
- timezoneOffset: '+00:00',
531
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
532
- contactName: 'Customer'
533
- });
534
-
535
- // ThreadReopenedHint is not processed (returns null)
536
- expect(result).toHaveLength(0);
537
- });
538
-
539
- test('should process AliveNote entities', () => {
540
- const entities = [
541
- {
542
- recordType: 'AliveNote',
543
- creationTime: '2024-01-15T10:30:00Z',
544
- author: { name: 'Agent Smith' },
545
- text: 'Important note here'
546
- }
547
- ];
548
-
549
- const result = processEntities({
550
- entities,
551
- timezoneOffset: '+00:00',
552
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
553
- contactName: 'Customer'
554
- });
555
-
556
- expect(result).toHaveLength(1);
557
- expect(result[0].type).toBe('note');
558
- expect(result[0].content).toContain('left a note');
559
- expect(result[0].content).toContain('Important note here');
560
- });
561
-
562
- test('should skip NoteHint entities (not processed)', () => {
563
- const entities = [
564
- {
565
- recordType: 'NoteHint',
566
- creationTime: '2024-01-15T10:30:00Z',
567
- author: { name: 'Agent Smith' },
568
- text: 'Important note here'
569
- }
570
- ];
571
-
572
- const result = processEntities({
573
- entities,
574
- timezoneOffset: '+00:00',
575
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
576
- contactName: 'Customer'
577
- });
578
-
579
- // NoteHint is counted but not processed into formatted entries
580
- expect(result).toHaveLength(0);
581
- });
582
-
583
- test('should skip ThreadCreatedHint entities', () => {
584
- const entities = [
585
- {
586
- recordType: 'ThreadCreatedHint',
587
- creationTime: '2024-01-15T10:30:00Z'
588
- }
589
- ];
590
-
591
- const result = processEntities({
592
- entities,
593
- timezoneOffset: '+00:00',
594
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
595
- contactName: 'Customer'
596
- });
597
-
598
- expect(result).toHaveLength(0);
599
- });
600
-
601
- test('should process multiple message entities', () => {
602
- const entities = [
603
- {
604
- recordType: 'AliveMessage',
605
- creationTime: '2024-01-15T10:00:00Z',
606
- direction: 'Outbound',
607
- author: { name: 'Agent' },
608
- text: 'First message'
609
- },
610
- {
611
- recordType: 'AliveMessage',
612
- creationTime: '2024-01-15T12:00:00Z',
613
- direction: 'Outbound',
614
- author: { name: 'Agent' },
615
- text: 'Third message'
616
- },
617
- {
618
- recordType: 'AliveMessage',
619
- creationTime: '2024-01-15T11:00:00Z',
620
- direction: 'Outbound',
621
- author: { name: 'Agent' },
622
- text: 'Second message'
623
- }
624
- ];
625
-
626
- const result = processEntities({
627
- entities,
628
- timezoneOffset: '+00:00',
629
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
630
- contactName: 'Customer'
631
- });
632
-
633
- expect(result).toHaveLength(3);
634
- // Verify all messages are processed
635
- const allContent = result.map(r => r.content).join(' ');
636
- expect(allContent).toContain('First message');
637
- expect(allContent).toContain('Second message');
638
- expect(allContent).toContain('Third message');
639
- });
640
-
641
- test('should apply timezone offset to timestamps', () => {
642
- const entities = [
643
- {
644
- recordType: 'AliveMessage',
645
- creationTime: '2024-01-15T10:30:00Z',
646
- direction: 'Outbound',
647
- author: { name: 'Agent' },
648
- text: 'Hello!'
649
- }
650
- ];
651
-
652
- const result = processEntities({
653
- entities,
654
- timezoneOffset: '+05:00',
655
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
656
- contactName: 'Customer'
657
- });
658
-
659
- // 10:30 UTC + 5 hours = 15:30 (3:30 PM)
660
- expect(result[0].content).toContain('03:30 PM');
661
- });
662
-
663
- test('should handle empty entities array', () => {
664
- const result = processEntities({
665
- entities: [],
666
- timezoneOffset: '+00:00',
667
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
668
- contactName: 'Customer'
669
- });
670
-
671
- expect(result).toEqual([]);
672
- });
673
- });
674
-
675
- describe('escapeHtml', () => {
676
- test('should escape ampersand', () => {
677
- expect(escapeHtml('Tom & Jerry')).toBe('Tom &amp; Jerry');
678
- });
679
-
680
- test('should escape less than', () => {
681
- expect(escapeHtml('a < b')).toBe('a &lt; b');
682
- });
683
-
684
- test('should escape greater than', () => {
685
- expect(escapeHtml('a > b')).toBe('a &gt; b');
686
- });
687
-
688
- test('should escape double quotes', () => {
689
- expect(escapeHtml('say "hello"')).toBe('say &quot;hello&quot;');
690
- });
691
-
692
- test('should escape single quotes', () => {
693
- expect(escapeHtml("it's fine")).toBe('it&#039;s fine');
694
- });
695
-
696
- test('should escape multiple special characters', () => {
697
- expect(escapeHtml('<script>alert("XSS")</script>'))
698
- .toBe('&lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;');
699
- });
700
-
701
- test('should return empty string for null input', () => {
702
- expect(escapeHtml(null)).toBe('');
703
- });
704
-
705
- test('should return empty string for undefined input', () => {
706
- expect(escapeHtml(undefined)).toBe('');
707
- });
708
-
709
- test('should return empty string for empty string input', () => {
710
- expect(escapeHtml('')).toBe('');
711
- });
712
-
713
- test('should not modify text without special characters', () => {
714
- expect(escapeHtml('Hello World')).toBe('Hello World');
715
- });
716
- });
717
-
718
- describe('Format-specific output', () => {
719
- const testConversation = {
720
- creationTime: '2024-01-15T10:30:00Z',
721
- messages: [{ lastModifiedTime: '2024-01-15T11:45:00Z' }],
722
- entities: [
723
- {
724
- recordType: 'AliveMessage',
725
- creationTime: '2024-01-15T10:30:00Z',
726
- direction: 'Inbound',
727
- author: { name: 'John Customer' },
728
- text: 'Hello!'
729
- }
730
- ],
731
- owner: {
732
- name: 'Support Team',
733
- extensionType: 'User',
734
- extensionId: '12345'
735
- }
736
- };
737
-
738
- describe('Plain Text format', () => {
739
- test('should include proper separators', () => {
740
- const result = composeSharedSMSLog({
741
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
742
- conversation: testConversation,
743
- contactName: 'John Customer',
744
- timezoneOffset: '+00:00'
745
- });
746
-
747
- expect(result.body).toContain('------------');
748
- expect(result.body).toContain('BEGIN');
749
- expect(result.body).toContain('END');
750
- });
751
-
752
- test('should use asterisks for list items', () => {
753
- const result = composeSharedSMSLog({
754
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
755
- conversation: testConversation,
756
- contactName: 'John Customer',
757
- timezoneOffset: '+00:00'
758
- });
759
-
760
- expect(result.body).toContain('* John Customer (customer)');
761
- });
762
- });
763
-
764
- describe('HTML format', () => {
765
- test('should include proper HTML tags', () => {
766
- const result = composeSharedSMSLog({
767
- logFormat: LOG_DETAILS_FORMAT_TYPE.HTML,
768
- conversation: testConversation,
769
- contactName: 'John Customer',
770
- timezoneOffset: '+00:00'
771
- });
772
-
773
- expect(result.body).toContain('<div>');
774
- expect(result.body).toContain('<ul>');
775
- expect(result.body).toContain('<li>');
776
- expect(result.body).toContain('<hr>');
777
- });
778
-
779
- test('should use bold tags for headers', () => {
780
- const result = composeSharedSMSLog({
781
- logFormat: LOG_DETAILS_FORMAT_TYPE.HTML,
782
- conversation: testConversation,
783
- contactName: 'John Customer',
784
- timezoneOffset: '+00:00'
785
- });
786
-
787
- expect(result.body).toContain('<b>Conversation summary</b>');
788
- expect(result.body).toContain('<b>Participants</b>');
789
- });
790
-
791
- test('should escape HTML in content', () => {
792
- const conversationWithSpecialChars = {
793
- ...testConversation,
794
- entities: [
795
- {
796
- recordType: 'AliveMessage',
797
- creationTime: '2024-01-15T10:30:00Z',
798
- direction: 'Inbound',
799
- author: { name: '<script>alert("XSS")</script>' },
800
- text: 'Test <b>bold</b>'
801
- }
802
- ]
803
- };
804
-
805
- const result = composeSharedSMSLog({
806
- logFormat: LOG_DETAILS_FORMAT_TYPE.HTML,
807
- conversation: conversationWithSpecialChars,
808
- contactName: 'John Customer',
809
- timezoneOffset: '+00:00'
810
- });
811
-
812
- expect(result.body).toContain('&lt;script&gt;');
813
- expect(result.body).toContain('&lt;b&gt;bold&lt;/b&gt;');
814
- });
815
- });
816
-
817
- describe('Markdown format', () => {
818
- test('should include proper Markdown headers', () => {
819
- const result = composeSharedSMSLog({
820
- logFormat: LOG_DETAILS_FORMAT_TYPE.MARKDOWN,
821
- conversation: testConversation,
822
- contactName: 'John Customer',
823
- timezoneOffset: '+00:00'
824
- });
825
-
826
- expect(result.body).toContain('## Conversation summary');
827
- expect(result.body).toContain('### Participants');
828
- });
829
-
830
- test('should use horizontal rules', () => {
831
- const result = composeSharedSMSLog({
832
- logFormat: LOG_DETAILS_FORMAT_TYPE.MARKDOWN,
833
- conversation: testConversation,
834
- contactName: 'John Customer',
835
- timezoneOffset: '+00:00'
836
- });
837
-
838
- expect(result.body).toContain('---');
839
- });
840
-
841
- test('should use asterisks for list items', () => {
842
- const result = composeSharedSMSLog({
843
- logFormat: LOG_DETAILS_FORMAT_TYPE.MARKDOWN,
844
- conversation: testConversation,
845
- contactName: 'John Customer',
846
- timezoneOffset: '+00:00'
847
- });
848
-
849
- expect(result.body).toContain('* John Customer (customer)');
850
- });
851
-
852
- test('should use bold for owner name', () => {
853
- const result = composeSharedSMSLog({
854
- logFormat: LOG_DETAILS_FORMAT_TYPE.MARKDOWN,
855
- conversation: testConversation,
856
- contactName: 'John Customer',
857
- timezoneOffset: '+00:00'
858
- });
859
-
860
- expect(result.body).toContain('**Support Team**');
861
- });
862
- });
863
- });
864
-
865
- describe('Edge Cases', () => {
866
- test('should handle conversation with no owner', () => {
867
- const conversationNoOwner = {
868
- creationTime: '2024-01-15T10:30:00Z',
869
- messages: [{ lastModifiedTime: '2024-01-15T11:45:00Z' }],
870
- entities: []
871
- };
872
-
873
- const result = composeSharedSMSLog({
874
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
875
- conversation: conversationNoOwner,
876
- contactName: 'John Customer',
877
- timezoneOffset: '+00:00'
878
- });
879
-
880
- expect(result.body).not.toContain('Owner:');
881
- expect(result.body).not.toContain('Receiving call queue:');
882
- });
883
-
884
- test('should handle message with subject instead of text', () => {
885
- const conversationWithSubject = {
886
- creationTime: '2024-01-15T10:30:00Z',
887
- messages: [{ lastModifiedTime: '2024-01-15T11:45:00Z' }],
888
- entities: [
889
- {
890
- recordType: 'AliveMessage',
891
- creationTime: '2024-01-15T10:30:00Z',
892
- direction: 'Inbound',
893
- author: { name: 'Customer' },
894
- subject: 'Subject line message'
895
- }
896
- ]
897
- };
898
-
899
- const result = composeSharedSMSLog({
900
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
901
- conversation: conversationWithSubject,
902
- contactName: 'Customer',
903
- timezoneOffset: '+00:00'
904
- });
905
-
906
- expect(result.body).toContain('Subject line message');
907
- });
908
-
909
- test('should handle note with body instead of text', () => {
910
- const conversationWithBody = {
911
- creationTime: '2024-01-15T10:30:00Z',
912
- messages: [{ lastModifiedTime: '2024-01-15T11:45:00Z' }],
913
- entities: [
914
- {
915
- recordType: 'AliveNote',
916
- creationTime: '2024-01-15T10:30:00Z',
917
- author: { name: 'Agent' },
918
- body: 'Note body content'
919
- }
920
- ]
921
- };
922
-
923
- const result = composeSharedSMSLog({
924
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
925
- conversation: conversationWithBody,
926
- contactName: 'Customer',
927
- timezoneOffset: '+00:00'
928
- });
929
-
930
- expect(result.body).toContain('Note body content');
931
- });
932
-
933
- test('should handle unknown assignee', () => {
934
- const conversationUnknownAssignee = {
935
- creationTime: '2024-01-15T10:30:00Z',
936
- messages: [{ lastModifiedTime: '2024-01-15T11:45:00Z' }],
937
- entities: [
938
- {
939
- recordType: 'ThreadAssignedHint',
940
- creationTime: '2024-01-15T10:30:00Z'
941
- }
942
- ]
943
- };
944
-
945
- const result = composeSharedSMSLog({
946
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
947
- conversation: conversationUnknownAssignee,
948
- contactName: 'Customer',
949
- timezoneOffset: '+00:00'
950
- });
951
-
952
- expect(result.body).toContain('assigned to Unknown');
953
- });
954
-
955
- test('should handle unknown note author', () => {
956
- const conversationUnknownAuthor = {
957
- creationTime: '2024-01-15T10:30:00Z',
958
- messages: [{ lastModifiedTime: '2024-01-15T11:45:00Z' }],
959
- entities: [
960
- {
961
- recordType: 'AliveNote',
962
- creationTime: '2024-01-15T10:30:00Z',
963
- text: 'Some note'
964
- }
965
- ]
966
- };
967
-
968
- const result = composeSharedSMSLog({
969
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
970
- conversation: conversationUnknownAuthor,
971
- contactName: 'Customer',
972
- timezoneOffset: '+00:00'
973
- });
974
-
975
- expect(result.body).toContain('Unknown left a note');
976
- });
977
-
978
- test('should handle missing timezone offset', () => {
979
- const conversation = {
980
- creationTime: '2024-01-15T10:30:00Z',
981
- messages: [{ lastModifiedTime: '2024-01-15T11:45:00Z' }],
982
- entities: []
983
- };
984
-
985
- const result = composeSharedSMSLog({
986
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
987
- conversation,
988
- contactName: 'Customer'
989
- });
990
-
991
- expect(result.subject).toBe('SMS conversation with Customer');
992
- expect(result.body).toContain('Conversation summary');
993
- });
994
-
995
- test('should default to plain text format', () => {
996
- const conversation = {
997
- creationTime: '2024-01-15T10:30:00Z',
998
- messages: [{ lastModifiedTime: '2024-01-15T11:45:00Z' }],
999
- entities: []
1000
- };
1001
-
1002
- const result = composeSharedSMSLog({
1003
- conversation,
1004
- contactName: 'Customer'
1005
- });
1006
-
1007
- expect(result.subject).toBe('SMS conversation with Customer');
1008
- expect(result.body).not.toContain('<b>');
1009
- expect(result.body).not.toContain('##');
1010
- });
1011
-
1012
- test('should handle owner name with queue keyword', () => {
1013
- const conversationWithQueueName = {
1014
- creationTime: '2024-01-15T10:30:00Z',
1015
- messages: [{ lastModifiedTime: '2024-01-15T11:45:00Z' }],
1016
- entities: [],
1017
- owner: {
1018
- name: 'Support Queue',
1019
- extensionType: 'User',
1020
- extensionId: '12345'
1021
- }
1022
- };
1023
-
1024
- const result = composeSharedSMSLog({
1025
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
1026
- conversation: conversationWithQueueName,
1027
- contactName: 'Customer',
1028
- timezoneOffset: '+00:00'
1029
- });
1030
-
1031
- expect(result.body).toContain('Receiving call queue: Support Queue');
1032
- });
1033
-
1034
- test('should handle message from from.name instead of author.name', () => {
1035
- const conversationWithFromName = {
1036
- creationTime: '2024-01-15T10:30:00Z',
1037
- messages: [{ lastModifiedTime: '2024-01-15T11:45:00Z' }],
1038
- entities: [
1039
- {
1040
- recordType: 'AliveMessage',
1041
- creationTime: '2024-01-15T10:30:00Z',
1042
- direction: 'Outbound',
1043
- from: { name: 'Agent via from' },
1044
- text: 'Hello!'
1045
- }
1046
- ]
1047
- };
1048
-
1049
- const result = composeSharedSMSLog({
1050
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
1051
- conversation: conversationWithFromName,
1052
- contactName: 'Customer',
1053
- timezoneOffset: '+00:00'
1054
- });
1055
-
1056
- expect(result.body).toContain('Agent via from');
1057
- });
1058
-
1059
- test('should handle note initiator as fallback for author', () => {
1060
- const conversationWithInitiator = {
1061
- creationTime: '2024-01-15T10:30:00Z',
1062
- messages: [{ lastModifiedTime: '2024-01-15T11:45:00Z' }],
1063
- entities: [
1064
- {
1065
- recordType: 'AliveNote',
1066
- creationTime: '2024-01-15T10:30:00Z',
1067
- initiator: { name: 'Note Initiator' },
1068
- text: 'A note'
1069
- }
1070
- ]
1071
- };
1072
-
1073
- const result = composeSharedSMSLog({
1074
- logFormat: LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT,
1075
- conversation: conversationWithInitiator,
1076
- contactName: 'Customer',
1077
- timezoneOffset: '+00:00'
1078
- });
1079
-
1080
- expect(result.body).toContain('Note Initiator left a note');
1081
- });
1082
- });
1083
- });
1084
-