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