@microsoft/omnichannel-chat-widget 1.5.1-main.ee4453c → 1.6.0

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 (47) hide show
  1. package/lib/cjs/common/Constants.js +18 -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 +23 -8
  6. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +39 -0
  7. package/lib/cjs/components/startchaterrorpanestateful/StartChatErrorPaneStateful.js +20 -6
  8. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +37 -36
  9. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +3 -1
  10. package/lib/cjs/contexts/common/StartChatFailureType.js +13 -0
  11. package/lib/cjs/contexts/createReducer.js +8 -0
  12. package/lib/esm/common/Constants.js +16 -1
  13. package/lib/esm/common/telemetry/TelemetryConstants.js +2 -0
  14. package/lib/esm/components/livechatwidget/common/endChat.js +26 -4
  15. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +8 -4
  16. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +24 -9
  17. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +40 -1
  18. package/lib/esm/components/startchaterrorpanestateful/StartChatErrorPaneStateful.js +20 -6
  19. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +37 -36
  20. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +3 -1
  21. package/lib/esm/contexts/common/StartChatFailureType.js +6 -0
  22. package/lib/esm/contexts/createReducer.js +8 -0
  23. package/lib/types/common/Constants.d.ts +16 -0
  24. package/lib/types/common/telemetry/TelemetryConstants.d.ts +1 -0
  25. package/lib/types/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneControlProps.d.ts +4 -0
  26. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -0
  27. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +37 -36
  28. package/lib/types/contexts/common/StartChatFailureType.d.ts +5 -0
  29. package/package.json +3 -3
  30. package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.js +0 -71
  31. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.js +0 -56
  32. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.spec.js +0 -282
  33. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +0 -190
  34. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +0 -82
  35. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +0 -342
  36. package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.js +0 -69
  37. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.js +0 -54
  38. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.spec.js +0 -280
  39. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +0 -188
  40. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +0 -80
  41. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +0 -338
  42. package/lib/types/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.d.ts +0 -1
  43. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.d.ts +0 -1
  44. package/lib/types/components/livechatwidget/common/startChatErrorHandler.spec.d.ts +0 -1
  45. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.d.ts +0 -1
  46. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +0 -1
  47. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.d.ts +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "1.5.1-main.ee4453c",
3
+ "version": "1.6.0",
4
4
  "description": "Microsoft Omnichannel Chat Widget",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -97,8 +97,8 @@
97
97
  "test:e2e:build": "yarn build-sample && cd automation_tests && yarn test",
98
98
  "test:visual": "jest -c jest.config.visual.cjs",
99
99
  "test:all": "yarn test:unit && yarn test:visual",
100
- "build:esm": "babel ./src --config-file ./babel.esm.config.json --out-dir lib/esm --extensions .ts,.js,.tsx --ignore **/*.test.ts,**/*.stories.tsx,**/*.test.tsx",
101
- "build:cjs": "babel ./src --config-file ./babel.config.json --out-dir lib/cjs --extensions .ts,.js,.tsx --ignore **/*.test.ts,**/*.stories.tsx,**/*.test.tsx",
100
+ "build:esm": "babel ./src --config-file ./babel.esm.config.json --out-dir lib/esm --extensions .ts,.js,.tsx --ignore **/*.test.ts,**/*.stories.tsx,**/*.test.tsx,**/*.spec.ts,**/*.spec.tsx",
101
+ "build:cjs": "babel ./src --config-file ./babel.config.json --out-dir lib/cjs --extensions .ts,.js,.tsx --ignore **/*.test.ts,**/*.stories.tsx,**/*.test.tsx,**/*.spec.ts,**/*.spec.tsx",
102
102
  "verify": "yarn install && yarn build-storybook && yarn test:all && yarn build && yarn storybook",
103
103
  "testpack": "yarn build && yarn pack",
104
104
  "build-sample": "yarn build && webpack --config ./webpack.config.cjs",
@@ -1,71 +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("EmailTranscriptPaneStateful unit test", () => {
7
- afterEach(() => {
8
- _react.cleanup;
9
- jest.resetAllMocks();
10
- });
11
- it("Method emailLiveChatTranscript is called", async () => {
12
- const omnichannelConfig = {
13
- orgUrl: "",
14
- orgId: "",
15
- widgetId: ""
16
- };
17
- const chatSDK = new _omnichannelChatSdk.OmnichannelChatSDK(omnichannelConfig);
18
- jest.spyOn(chatSDK, "emailLiveChatTranscript").mockResolvedValue(Promise.resolve());
19
- const chatTranscriptBody = {
20
- emailAddress: "sample@microsoft.com",
21
- attachmentMessage: "sample",
22
- locale: "sample"
23
- };
24
- try {
25
- await chatSDK.emailLiveChatTranscript(chatTranscriptBody);
26
- expect(chatSDK.emailLiveChatTranscript).toHaveBeenCalledTimes(1);
27
- // eslint-disable-next-line no-empty
28
- } catch (ex) {}
29
- });
30
- it("Method emailLiveChatTranscript throws exception", async () => {
31
- const errorMessage = "Error";
32
- const omnichannelConfig = {
33
- orgUrl: "",
34
- orgId: "",
35
- widgetId: ""
36
- };
37
- const chatSDK = new _omnichannelChatSdk.OmnichannelChatSDK(omnichannelConfig);
38
- jest.spyOn(chatSDK, "emailLiveChatTranscript").mockRejectedValue(new Error(errorMessage));
39
- const chatTranscriptBody = {
40
- emailAddress: "sample@microsoft.com",
41
- attachmentMessage: "sample",
42
- locale: "sample"
43
- };
44
- try {
45
- await chatSDK.emailLiveChatTranscript(chatTranscriptBody);
46
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
- } catch (ex) {
48
- expect(ex.message).toEqual(errorMessage);
49
- }
50
- });
51
- it("Method emailLiveChatTranscript undefined throws exception", async () => {
52
- const errorMessage = "Error";
53
- const omnichannelConfig = {
54
- orgUrl: "",
55
- orgId: "",
56
- widgetId: ""
57
- };
58
- const chatSDK = new _omnichannelChatSdk.OmnichannelChatSDK(omnichannelConfig);
59
- const chatTranscriptBody = {
60
- emailAddress: "sample@microsoft.com",
61
- attachmentMessage: "sample",
62
- locale: "sample"
63
- };
64
- try {
65
- await chatSDK.emailLiveChatTranscript(chatTranscriptBody);
66
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
- } catch (ex) {
68
- expect(ex.message).toEqual(errorMessage);
69
- }
70
- });
71
- });
@@ -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,282 +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(2);
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 UninitializedChatSDK", () => {
188
- const dispatch = jest.fn();
189
- const mockEx = new _omnichannelChatSdk.ChatSDKError(_omnichannelChatSdk.ChatSDKErrorName.UninitializedChatSDK);
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
- Description: "Widget load complete with error",
196
- ExceptionDetails: expect.objectContaining({
197
- Exception: `Widget load complete with error: ${_omnichannelChatSdk.ChatSDKErrorName.UninitializedChatSDK}`
198
- })
199
- }));
200
- expect(dispatch).toHaveBeenCalledTimes(2);
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 InvalidConversation", () => {
206
- const dispatch = jest.fn();
207
- const mockEx = new _omnichannelChatSdk.ChatSDKError(_omnichannelChatSdk.ChatSDKErrorName.InvalidConversation);
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(1);
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.InvalidConversation}`
216
- })
217
- }));
218
- expect(dispatch).toHaveBeenCalledTimes(16);
219
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
220
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
221
- payload: _ConversationState.ConversationState.Closed
222
- }));
223
- });
224
- it("handleStartChatError should log failed with error event for ClosedConversation", () => {
225
- const dispatch = jest.fn();
226
- const mockEx = new _omnichannelChatSdk.ChatSDKError(_omnichannelChatSdk.ChatSDKErrorName.ClosedConversation);
227
- spyOn(_omnichannelChatComponents.BroadcastService, "postMessage").and.callFake(() => false);
228
- spyOn(_TelemetryHelper.TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
229
- (0, _startChatErrorHandler.handleStartChatError)(dispatch, {}, {}, mockEx, false);
230
- expect(_TelemetryHelper.TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(1);
231
- expect(_TelemetryHelper.TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("WARN", expect.objectContaining({
232
- Description: "Widget load complete with error",
233
- ExceptionDetails: expect.objectContaining({
234
- Exception: `Widget load complete with error: ${_omnichannelChatSdk.ChatSDKErrorName.ClosedConversation}`
235
- })
236
- }));
237
- expect(dispatch).toHaveBeenCalledTimes(16);
238
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
239
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
240
- payload: _ConversationState.ConversationState.Closed
241
- }));
242
- });
243
- it("handleStartChatError should log failed event for any other errors", () => {
244
- const dispatch = jest.fn();
245
- const mockEx = new _omnichannelChatSdk.ChatSDKError(_omnichannelChatSdk.ChatSDKErrorName.ScriptLoadFailure, 405);
246
- spyOn(_omnichannelChatComponents.BroadcastService, "postMessage").and.callFake(() => false);
247
- spyOn(_TelemetryHelper.TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
248
- (0, _startChatErrorHandler.handleStartChatError)(dispatch, {}, {}, mockEx, false);
249
- expect(_TelemetryHelper.TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(2);
250
- expect(_TelemetryHelper.TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("ERROR", expect.objectContaining({
251
- ExceptionDetails: expect.objectContaining({
252
- Exception: `Widget load complete with error: ${_omnichannelChatSdk.ChatSDKErrorName.ScriptLoadFailure}`,
253
- HttpResponseStatusCode: 405
254
- })
255
- }));
256
- expect(dispatch).toHaveBeenCalledTimes(2);
257
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
258
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE
259
- }));
260
- });
261
- it("handleStartChatError should force end chat if isStartChatSuccessful is true", () => {
262
- const dispatch = jest.fn();
263
- const mockEx = new _omnichannelChatSdk.ChatSDKError(_omnichannelChatSdk.ChatSDKErrorName.ScriptLoadFailure, 405);
264
- const mockSDK = {
265
- endChat: jest.fn()
266
- };
267
- spyOn(_omnichannelChatComponents.BroadcastService, "postMessage").and.callFake(() => false);
268
- spyOn(_TelemetryHelper.TelemetryHelper, "logLoadingEvent").and.callFake(() => false);
269
- (0, _startChatErrorHandler.handleStartChatError)(dispatch, mockSDK, {}, mockEx, true);
270
- expect(_TelemetryHelper.TelemetryHelper.logLoadingEvent).toHaveBeenCalledTimes(3);
271
- expect(_TelemetryHelper.TelemetryHelper.logLoadingEvent).toHaveBeenCalledWith("ERROR", expect.objectContaining({
272
- ExceptionDetails: expect.objectContaining({
273
- Exception: "SessionInit was successful, but widget load failed."
274
- })
275
- }));
276
- expect(dispatch).toHaveBeenCalledTimes(2);
277
- expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({
278
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE
279
- }));
280
- expect(mockSDK.endChat).toHaveBeenCalled();
281
- });
282
- });
@@ -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
- });