@microsoft/omnichannel-chat-widget 1.5.1-main.6b98130 → 1.5.1-main.7897747

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 (33) hide show
  1. package/lib/cjs/common/Constants.js +14 -2
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +2 -0
  3. package/lib/cjs/components/livechatwidget/common/endChat.js +25 -3
  4. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +8 -4
  5. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +6 -5
  6. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +34 -0
  7. package/lib/esm/common/Constants.js +12 -1
  8. package/lib/esm/common/telemetry/TelemetryConstants.js +2 -0
  9. package/lib/esm/components/livechatwidget/common/endChat.js +26 -4
  10. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +8 -4
  11. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +7 -6
  12. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +35 -1
  13. package/lib/types/common/Constants.d.ts +12 -0
  14. package/lib/types/common/telemetry/TelemetryConstants.d.ts +1 -0
  15. package/package.json +3 -3
  16. package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.js +0 -71
  17. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.js +0 -56
  18. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.spec.js +0 -300
  19. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +0 -190
  20. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +0 -82
  21. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +0 -342
  22. package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.js +0 -69
  23. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.js +0 -54
  24. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.spec.js +0 -298
  25. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +0 -188
  26. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +0 -80
  27. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +0 -338
  28. package/lib/types/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.d.ts +0 -1
  29. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.d.ts +0 -1
  30. package/lib/types/components/livechatwidget/common/startChatErrorHandler.spec.d.ts +0 -1
  31. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.d.ts +0 -1
  32. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +0 -1
  33. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.d.ts +0 -1
@@ -1,298 +0,0 @@
1
- import { BroadcastService } from "@microsoft/omnichannel-chat-components";
2
- import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
3
- import { handleStartChatError } from "./startChatErrorHandler";
4
- import { WidgetLoadCustomErrorString, WidgetLoadTelemetryMessage } from "../../../common/Constants";
5
- import { ChatSDKError, ChatSDKErrorName } from "@microsoft/omnichannel-chat-sdk";
6
- import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
7
- import { ConversationState } from "../../../contexts/common/ConversationState";
8
- describe("startChatErrorHandler unit test", () => {
9
- it("handleStartChatError should log failed event and return if exception is undefined", () => {
10
- const dispatch = jest.fn();
11
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
12
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
13
- handleStartChatError(dispatch, {}, {}, undefined, false);
14
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(1);
15
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("ERROR", expect.objectContaining({
16
- ExceptionDetails: expect.objectContaining({
17
- Exception: "Widget load complete with error: undefined"
18
- })
19
- }));
20
- expect(dispatch).not.toHaveBeenCalled();
21
- });
22
- it("handleStartChatError should log failed with error event for AuthenticationFailedErrorString", () => {
23
- const dispatch = jest.fn();
24
- const mockEx = new Error(WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
25
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
26
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
27
- handleStartChatError(dispatch, {}, {}, mockEx, false);
28
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(2);
29
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("WARN", expect.objectContaining({
30
- ExceptionDetails: expect.objectContaining({
31
- Exception: `Widget load complete with error: Error: ${WidgetLoadCustomErrorString.AuthenticationFailedErrorString}`
32
- })
33
- }));
34
- expect(dispatch).toHaveBeenCalledTimes(3);
35
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
36
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE
37
- }));
38
- });
39
- it("handleStartChatError should log failed with error event for NetworkErrorString", () => {
40
- const dispatch = jest.fn();
41
- const mockEx = new Error(WidgetLoadCustomErrorString.NetworkErrorString);
42
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
43
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
44
- handleStartChatError(dispatch, {}, {}, mockEx, false);
45
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(2);
46
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("WARN", expect.objectContaining({
47
- ExceptionDetails: expect.objectContaining({
48
- Exception: `Widget load complete with error: Error: ${WidgetLoadCustomErrorString.NetworkErrorString}`
49
- })
50
- }));
51
- expect(dispatch).toHaveBeenCalledTimes(2);
52
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
53
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE
54
- }));
55
- });
56
- it("handleStartChatError should log complete event for WidgetUseOutsideOperatingHour", () => {
57
- const dispatch = jest.fn();
58
- const mockEx = new ChatSDKError(ChatSDKErrorName.WidgetUseOutsideOperatingHour);
59
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
60
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
61
- handleStartChatError(dispatch, {}, {}, mockEx, false);
62
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(1);
63
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("INFO", expect.objectContaining({
64
- Description: `Widget load complete. ${WidgetLoadTelemetryMessage.OOOHMessage}`
65
- }));
66
- expect(dispatch).toHaveBeenCalledTimes(2);
67
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
68
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE
69
- }));
70
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
71
- type: LiveChatWidgetActionType.SET_OUTSIDE_OPERATING_HOURS
72
- }));
73
- });
74
- it("handleStartChatError should log failed with error event for PersistentChatConversationRetrievalFailure for non-400 status", () => {
75
- const dispatch = jest.fn();
76
- const mockEx = new ChatSDKError(ChatSDKErrorName.PersistentChatConversationRetrievalFailure, 429);
77
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
78
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
79
- handleStartChatError(dispatch, {}, {}, mockEx, false);
80
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(2);
81
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("WARN", expect.objectContaining({
82
- Description: "Widget load complete with error",
83
- ExceptionDetails: expect.objectContaining({
84
- Exception: `Widget load complete with error: ${ChatSDKErrorName.PersistentChatConversationRetrievalFailure}`,
85
- HttpResponseStatusCode: 429
86
- })
87
- }));
88
- expect(dispatch).toHaveBeenCalledTimes(2);
89
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
90
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE
91
- }));
92
- });
93
- it("handleStartChatError should log failed event for PersistentChatConversationRetrievalFailure for 400 status", () => {
94
- const dispatch = jest.fn();
95
- const mockEx = new ChatSDKError(ChatSDKErrorName.PersistentChatConversationRetrievalFailure, 400);
96
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
97
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
98
- handleStartChatError(dispatch, {}, {}, mockEx, false);
99
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(2);
100
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("ERROR", expect.objectContaining({
101
- ExceptionDetails: expect.objectContaining({
102
- Exception: `Widget load complete with error: ${ChatSDKErrorName.PersistentChatConversationRetrievalFailure}`,
103
- HttpResponseStatusCode: 400
104
- })
105
- }));
106
- expect(dispatch).toHaveBeenCalledTimes(2);
107
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
108
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE
109
- }));
110
- });
111
- it("handleStartChatError should log failed with error event for ConversationInitializationFailure for non-400 status", () => {
112
- const dispatch = jest.fn();
113
- const mockEx = new ChatSDKError(ChatSDKErrorName.ConversationInitializationFailure, 429);
114
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
115
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
116
- handleStartChatError(dispatch, {}, {}, mockEx, false);
117
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(2);
118
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("WARN", expect.objectContaining({
119
- Description: "Widget load complete with error",
120
- ExceptionDetails: expect.objectContaining({
121
- Exception: `Widget load complete with error: ${ChatSDKErrorName.ConversationInitializationFailure}`,
122
- HttpResponseStatusCode: 429
123
- })
124
- }));
125
- expect(dispatch).toHaveBeenCalledTimes(2);
126
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
127
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE
128
- }));
129
- });
130
- it("handleStartChatError should log failed event for ConversationInitializationFailure for 400 status", () => {
131
- const dispatch = jest.fn();
132
- const mockEx = new ChatSDKError(ChatSDKErrorName.ConversationInitializationFailure, 400);
133
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
134
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
135
- handleStartChatError(dispatch, {}, {}, mockEx, false);
136
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(2);
137
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("ERROR", expect.objectContaining({
138
- ExceptionDetails: expect.objectContaining({
139
- Exception: `Widget load complete with error: ${ChatSDKErrorName.ConversationInitializationFailure}`,
140
- HttpResponseStatusCode: 400
141
- })
142
- }));
143
- expect(dispatch).toHaveBeenCalledTimes(2);
144
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
145
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE
146
- }));
147
- });
148
- it("handleStartChatError should log failed with error event for ChatTokenRetrievalFailure for non-400 status", () => {
149
- const dispatch = jest.fn();
150
- const mockEx = new ChatSDKError(ChatSDKErrorName.ChatTokenRetrievalFailure, 429);
151
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
152
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
153
- handleStartChatError(dispatch, {}, {}, mockEx, false);
154
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(2);
155
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("WARN", expect.objectContaining({
156
- Description: "Widget load complete with error",
157
- ExceptionDetails: expect.objectContaining({
158
- Exception: `Widget load complete with error: ${ChatSDKErrorName.ChatTokenRetrievalFailure}`,
159
- HttpResponseStatusCode: 429
160
- })
161
- }));
162
- expect(dispatch).toHaveBeenCalledTimes(2);
163
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
164
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE
165
- }));
166
- });
167
- it("handleStartChatError should log failed event for ChatTokenRetrievalFailure for 400 status", () => {
168
- const dispatch = jest.fn();
169
- const mockEx = new ChatSDKError(ChatSDKErrorName.ChatTokenRetrievalFailure, 400);
170
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
171
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
172
- handleStartChatError(dispatch, {}, {}, mockEx, false);
173
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(2);
174
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("ERROR", expect.objectContaining({
175
- ExceptionDetails: expect.objectContaining({
176
- Exception: `Widget load complete with error: ${ChatSDKErrorName.ChatTokenRetrievalFailure}`,
177
- HttpResponseStatusCode: 400
178
- })
179
- }));
180
- expect(dispatch).toHaveBeenCalledTimes(2);
181
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
182
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE
183
- }));
184
- });
185
- it("handleStartChatError should log failed with error event for ChatTokenRetrievalFailure for 401 status", () => {
186
- const dispatch = jest.fn();
187
- const mockEx = new ChatSDKError(ChatSDKErrorName.ChatTokenRetrievalFailure, 401);
188
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
189
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
190
- handleStartChatError(dispatch, {}, {}, mockEx, false);
191
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(2);
192
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("WARN", expect.objectContaining({
193
- ExceptionDetails: expect.objectContaining({
194
- Exception: `Widget load complete with error: ${ChatSDKErrorName.ChatTokenRetrievalFailure}`,
195
- HttpResponseStatusCode: 401
196
- })
197
- }));
198
- expect(dispatch).toHaveBeenCalledTimes(3);
199
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
200
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE
201
- }));
202
- });
203
- it("handleStartChatError should log failed with error event for UninitializedChatSDK", () => {
204
- const dispatch = jest.fn();
205
- const mockEx = new ChatSDKError(ChatSDKErrorName.UninitializedChatSDK);
206
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
207
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
208
- handleStartChatError(dispatch, {}, {}, mockEx, false);
209
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(2);
210
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("WARN", expect.objectContaining({
211
- Description: "Widget load complete with error",
212
- ExceptionDetails: expect.objectContaining({
213
- Exception: `Widget load complete with error: ${ChatSDKErrorName.UninitializedChatSDK}`
214
- })
215
- }));
216
- expect(dispatch).toHaveBeenCalledTimes(2);
217
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
218
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE
219
- }));
220
- });
221
- it("handleStartChatError should log failed with error event for InvalidConversation", () => {
222
- const dispatch = jest.fn();
223
- const mockEx = new ChatSDKError(ChatSDKErrorName.InvalidConversation);
224
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
225
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
226
- handleStartChatError(dispatch, {}, {}, mockEx, false);
227
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(1);
228
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("WARN", expect.objectContaining({
229
- Description: "Widget load complete with error",
230
- ExceptionDetails: expect.objectContaining({
231
- Exception: `Widget load complete with error: ${ChatSDKErrorName.InvalidConversation}`
232
- })
233
- }));
234
- expect(dispatch).toHaveBeenCalledTimes(16);
235
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
236
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
237
- payload: ConversationState.Closed
238
- }));
239
- });
240
- it("handleStartChatError should log failed with error event for ClosedConversation", () => {
241
- const dispatch = jest.fn();
242
- const mockEx = new ChatSDKError(ChatSDKErrorName.ClosedConversation);
243
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
244
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
245
- handleStartChatError(dispatch, {}, {}, mockEx, false);
246
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(1);
247
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("WARN", expect.objectContaining({
248
- Description: "Widget load complete with error",
249
- ExceptionDetails: expect.objectContaining({
250
- Exception: `Widget load complete with error: ${ChatSDKErrorName.ClosedConversation}`
251
- })
252
- }));
253
- expect(dispatch).toHaveBeenCalledTimes(16);
254
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
255
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
256
- payload: ConversationState.Closed
257
- }));
258
- });
259
- it("handleStartChatError should log failed event for any other errors", () => {
260
- const dispatch = jest.fn();
261
- const mockEx = new ChatSDKError(ChatSDKErrorName.ScriptLoadFailure, 405);
262
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
263
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
264
- handleStartChatError(dispatch, {}, {}, mockEx, false);
265
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(2);
266
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("ERROR", expect.objectContaining({
267
- ExceptionDetails: expect.objectContaining({
268
- Exception: `Widget load complete with error: ${ChatSDKErrorName.ScriptLoadFailure}`,
269
- HttpResponseStatusCode: 405
270
- })
271
- }));
272
- expect(dispatch).toHaveBeenCalledTimes(2);
273
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
274
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE
275
- }));
276
- });
277
- it("handleStartChatError should force end chat if isStartChatSuccessful is true", () => {
278
- const dispatch = jest.fn();
279
- const mockEx = new ChatSDKError(ChatSDKErrorName.ScriptLoadFailure, 405);
280
- const mockSDK = {
281
- endChat: jest.fn()
282
- };
283
- spyOn(BroadcastService, "postMessage").and.callFake(() => false);
284
- spyOn(TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
285
- handleStartChatError(dispatch, mockSDK, {}, mockEx, true);
286
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(3);
287
- expect(TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("ERROR", expect.objectContaining({
288
- ExceptionDetails: expect.objectContaining({
289
- Exception: "SessionInit was successful, but widget load failed."
290
- })
291
- }));
292
- expect(dispatch).toHaveBeenCalledTimes(2);
293
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
294
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE
295
- }));
296
- expect(mockSDK.endChat).toHaveBeenCalled();
297
- });
298
- });
@@ -1,188 +0,0 @@
1
- import { Constants } from "../../../../../common/Constants";
2
- import { DirectLineActivityType } from "../../enums/DirectLineActivityType";
3
- import { DirectLineSenderRole } from "../../enums/DirectLineSenderRole";
4
- import { MessageTypes } from "../../enums/MessageType";
5
- import { TelemetryHelper } from "../../../../../common/telemetry/TelemetryHelper";
6
- import { createActivityMiddleware } from "./activityMiddleware";
7
- describe("activityMiddleware test", () => {
8
- it("createActivityMiddleware() with Channel role sender should returns nothing", () => {
9
- spyOn(TelemetryHelper, "logActionEvent").and.callFake(() => false);
10
- const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
11
- const args = {
12
- activity: {
13
- channelData: {
14
- type: MessageTypes.Thread
15
- },
16
- from: {
17
- role: DirectLineSenderRole.Channel
18
- }
19
- }
20
- };
21
- const results = createActivityMiddleware()()(next)(args);
22
- expect(results()).toEqual(false);
23
- expect(TelemetryHelper.logActionEvent).toHaveBeenCalledTimes(0);
24
- });
25
- it("createActivityMiddleware() with Hidden tag should return nothing", () => {
26
- spyOn(TelemetryHelper, "logActionEvent").and.callFake(() => false);
27
- const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
28
- const args = {
29
- activity: {
30
- channelData: {
31
- tags: [Constants.hiddenTag]
32
- },
33
- from: {
34
- role: DirectLineSenderRole.User
35
- }
36
- }
37
- };
38
- const results = createActivityMiddleware()()(next)(args);
39
- expect(results()).toEqual(false);
40
- expect(TelemetryHelper.logActionEvent).toHaveBeenCalledTimes(0);
41
- });
42
- it("createActivityMiddleware() with System tag should return system message", () => {
43
- var _results$props, _results$props$danger;
44
- spyOn(TelemetryHelper, "logActionEvent").and.callFake(() => false);
45
- const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
46
- const systemMessage = "system message";
47
- const args = {
48
- activity: {
49
- text: systemMessage,
50
- channelData: {
51
- tags: [Constants.systemMessageTag]
52
- },
53
- from: {
54
- role: DirectLineSenderRole.User
55
- }
56
- }
57
- };
58
- const results = createActivityMiddleware()()(next)(args);
59
- expect(TelemetryHelper.logActionEvent).toHaveBeenCalledTimes(0);
60
- expect((_results$props = results().props) === null || _results$props === void 0 ? void 0 : (_results$props$danger = _results$props.dangerouslySetInnerHTML) === null || _results$props$danger === void 0 ? void 0 : _results$props$danger.__html).toEqual(systemMessage);
61
- });
62
- it("createActivityMiddleware() should escape html texts to prevent XSS attacks", () => {
63
- var _results$props2, _results$props2$dange;
64
- spyOn(TelemetryHelper, "logActionEvent").and.callFake(() => false);
65
- const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
66
- const systemMessage = "<img src='' onerror=\"alert('XSS attack')\"/>";
67
- const args = {
68
- activity: {
69
- text: systemMessage,
70
- channelData: {
71
- tags: [Constants.systemMessageTag]
72
- },
73
- from: {
74
- role: DirectLineSenderRole.User
75
- }
76
- }
77
- };
78
- const results = createActivityMiddleware()()(next)(args);
79
- expect(TelemetryHelper.logActionEvent).toHaveBeenCalledTimes(0);
80
- expect((_results$props2 = results().props) === null || _results$props2 === void 0 ? void 0 : (_results$props2$dange = _results$props2.dangerouslySetInnerHTML) === null || _results$props2$dange === void 0 ? void 0 : _results$props2$dange.__html).toEqual("&lt;img src=&#39;&#39; onerror=&quot;alert(&#39;XSS attack&#39;)&quot;&#x2F;&gt;");
81
- });
82
- it("createActivityMiddleware() with QueuePosition tag should log QueuePosition message", () => {
83
- spyOn(TelemetryHelper, "logActionEvent").and.callFake(() => false);
84
- const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
85
- const systemMessage = "system message";
86
- const args = {
87
- activity: {
88
- text: systemMessage,
89
- channelData: {
90
- tags: [Constants.systemMessageTag, Constants.queuePositionMessageTag]
91
- },
92
- from: {
93
- role: DirectLineSenderRole.User
94
- }
95
- }
96
- };
97
- createActivityMiddleware()()(next)(args);
98
- expect(TelemetryHelper.logActionEvent).toHaveBeenCalledTimes(1);
99
- });
100
- it("createActivityMiddleware() with same clientmessageid with next activity should return nothing", () => {
101
- spyOn(TelemetryHelper, "logActionEvent").and.callFake(() => false);
102
- const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
103
- const systemMessage = "system message";
104
- const args = {
105
- activity: {
106
- text: systemMessage,
107
- channelData: {
108
- tags: [Constants.systemMessageTag],
109
- clientmessageid: "1234"
110
- },
111
- from: {
112
- role: DirectLineSenderRole.User
113
- }
114
- },
115
- nextVisibleActivity: {
116
- channelData: {
117
- clientmessageid: "1234"
118
- }
119
- }
120
- };
121
- const results = createActivityMiddleware()()(next)(args);
122
- expect(results()).toEqual(false);
123
- });
124
- it("createActivityMiddleware() with same messageid with next activity should return nothing", () => {
125
- spyOn(TelemetryHelper, "logActionEvent").and.callFake(() => false);
126
- const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
127
- const systemMessage = "system message";
128
- const args = {
129
- activity: {
130
- text: systemMessage,
131
- channelData: {
132
- tags: [Constants.systemMessageTag]
133
- },
134
- from: {
135
- role: DirectLineSenderRole.User
136
- },
137
- messageid: "1234"
138
- },
139
- nextVisibleActivity: {
140
- messageid: "1234"
141
- }
142
- };
143
- const results = createActivityMiddleware()()(next)(args);
144
- expect(results()).toEqual(false);
145
- });
146
- it("createActivityMiddleware() should render normal user messages", () => {
147
- var _results$props3, _results$props3$child, _results$props3$child2;
148
- spyOn(TelemetryHelper, "logActionEvent").and.callFake(() => false);
149
- const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
150
- const userMessage = "Hello World";
151
- const args = {
152
- activity: {
153
- text: userMessage,
154
- channelId: "webchat",
155
- channelData: {
156
- isHtmlEncoded: false
157
- },
158
- from: {
159
- role: DirectLineSenderRole.User
160
- },
161
- type: DirectLineActivityType.Message
162
- }
163
- };
164
- const results = createActivityMiddleware()()(next)(args);
165
- expect((_results$props3 = results().props) === null || _results$props3 === void 0 ? void 0 : (_results$props3$child = _results$props3.children) === null || _results$props3$child === void 0 ? void 0 : (_results$props3$child2 = _results$props3$child.activity) === null || _results$props3$child2 === void 0 ? void 0 : _results$props3$child2.text).toEqual(userMessage);
166
- });
167
- it("createActivityMiddleware() should not render typing messages", () => {
168
- var _results$activity;
169
- spyOn(TelemetryHelper, "logActionEvent").and.callFake(() => false);
170
- const next = args => () => args; // eslint-disable-line @typescript-eslint/no-explicit-any
171
- const userMessage = "Hello World";
172
- const args = {
173
- activity: {
174
- text: userMessage,
175
- channelId: "webchat",
176
- channelData: {
177
- isHtmlEncoded: false
178
- },
179
- from: {
180
- role: DirectLineSenderRole.User
181
- },
182
- type: DirectLineActivityType.Typing
183
- }
184
- };
185
- const results = createActivityMiddleware()()(next)(args);
186
- expect((_results$activity = results().activity) === null || _results$activity === void 0 ? void 0 : _results$activity.text).toEqual(userMessage);
187
- });
188
- });
@@ -1,80 +0,0 @@
1
- import "@testing-library/jest-dom/extend-expect";
2
- import { createCardActionMiddleware } from "./cardActionMiddleware";
3
- describe("cardActionMiddleware test", () => {
4
- it("createCardActionMiddleware() with undefined botMagicCodeConfig should not change the sign in card url", () => {
5
- const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
6
- const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
7
- const args = {
8
- cardAction: {
9
- type: "signin",
10
- value: signInUrl
11
- }
12
- };
13
- const results = createCardActionMiddleware(undefined)()(next)(args);
14
- expect(signInUrl).toEqual(results.cardAction.value);
15
- });
16
- it("createCardActionMiddleware() with botMagicCode enabled should not change the sign in card url", () => {
17
- const botMagicCodeConfig = {
18
- disabled: false
19
- };
20
- const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
21
- const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
22
- const args = {
23
- cardAction: {
24
- type: "signin",
25
- value: signInUrl
26
- }
27
- };
28
- const results = createCardActionMiddleware(botMagicCodeConfig)()(next)(args);
29
- expect(args.cardAction.value).toEqual(results.cardAction.value);
30
- });
31
- it("createCardActionMiddleware() with botMagicCode disabled & no fwdUrl should not change the sign in card url", () => {
32
- const botMagicCodeConfig = {
33
- disabled: true
34
- };
35
- const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
36
- const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
37
- const args = {
38
- cardAction: {
39
- type: "signin",
40
- value: signInUrl
41
- }
42
- };
43
- const results = createCardActionMiddleware(botMagicCodeConfig)()(next)(args);
44
- expect(args.cardAction.value).toEqual(results.cardAction.value);
45
- });
46
- it("createCardActionMiddleware() with botMagicCode disabled & fwdUrl should append the fwdUrl in the sign in card url", () => {
47
- const botMagicCodeConfig = {
48
- disabled: true,
49
- fwdUrl: "http://localhost/forwarder.html"
50
- };
51
- const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
52
- const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
53
- const args = {
54
- cardAction: {
55
- type: "signin",
56
- value: signInUrl
57
- }
58
- };
59
- const results = createCardActionMiddleware(botMagicCodeConfig)()(next)(args);
60
- expect(signInUrl === results.cardAction.value).toBe(false);
61
- expect(results.cardAction.value === `${signInUrl}&fwdUrl=${botMagicCodeConfig.fwdUrl}`).toBe(true);
62
- });
63
- it("createCardActionMiddleware() should not append fwdUrl if fwdUrl & sign in card url are not in the same domain", () => {
64
- const botMagicCodeConfig = {
65
- disabled: true,
66
- fwdUrl: "https://localhost/forwarder.html"
67
- };
68
- const next = args => args; // eslint-disable-line @typescript-eslint/no-explicit-any
69
- const signInUrl = "https://token.botframework.com/api/oauth/signin?signin=[signin]";
70
- const args = {
71
- cardAction: {
72
- type: "signin",
73
- value: signInUrl
74
- }
75
- };
76
- const results = createCardActionMiddleware(botMagicCodeConfig)()(next)(args);
77
- expect(signInUrl === results.cardAction.value).toBe(true);
78
- expect(results.cardAction.value === `${signInUrl}&fwdUrl=${botMagicCodeConfig.fwdUrl}`).toBe(false);
79
- });
80
- });