@microsoft/omnichannel-chat-widget 1.5.1-main.ee4453c → 1.6.1
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.
- package/lib/cjs/common/Constants.js +18 -2
- package/lib/cjs/common/telemetry/TelemetryConstants.js +2 -0
- package/lib/cjs/components/livechatwidget/common/endChat.js +25 -3
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +8 -4
- package/lib/cjs/components/livechatwidget/common/startChat.js +0 -5
- package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +23 -8
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +39 -0
- package/lib/cjs/components/startchaterrorpanestateful/StartChatErrorPaneStateful.js +20 -6
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +3 -0
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +37 -36
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +3 -1
- package/lib/cjs/contexts/common/StartChatFailureType.js +13 -0
- package/lib/cjs/contexts/createReducer.js +8 -0
- package/lib/esm/common/Constants.js +16 -1
- package/lib/esm/common/telemetry/TelemetryConstants.js +2 -0
- package/lib/esm/components/livechatwidget/common/endChat.js +26 -4
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +8 -4
- package/lib/esm/components/livechatwidget/common/startChat.js +0 -5
- package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +24 -9
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +40 -1
- package/lib/esm/components/startchaterrorpanestateful/StartChatErrorPaneStateful.js +20 -6
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +3 -0
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +37 -36
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +3 -1
- package/lib/esm/contexts/common/StartChatFailureType.js +6 -0
- package/lib/esm/contexts/createReducer.js +8 -0
- package/lib/types/common/Constants.d.ts +16 -0
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +1 -0
- package/lib/types/components/startchaterrorpanestateful/interfaces/IStartChatErrorPaneControlProps.d.ts +4 -0
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +2 -0
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +37 -36
- package/lib/types/contexts/common/StartChatFailureType.d.ts +5 -0
- package/package.json +3 -3
- package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.js +0 -71
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.js +0 -56
- package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.spec.js +0 -282
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +0 -190
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +0 -82
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +0 -342
- package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.js +0 -69
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.js +0 -54
- package/lib/esm/components/livechatwidget/common/startChatErrorHandler.spec.js +0 -280
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +0 -188
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +0 -80
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +0 -338
- package/lib/types/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.spec.d.ts +0 -1
- package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.spec.d.ts +0 -1
- package/lib/types/components/livechatwidget/common/startChatErrorHandler.spec.d.ts +0 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.d.ts +0 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +0 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.d.ts +0 -1
|
@@ -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("<img src='' onerror="alert('XSS attack')"/>");
|
|
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
|
-
});
|
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _Constants = require("../../../../../common/Constants");
|
|
4
|
-
var _WebChatActionType = require("../../enums/WebChatActionType");
|
|
5
|
-
var _messageSequenceIdOverrideMiddleware = _interopRequireDefault(require("./messageSequenceIdOverrideMiddleware"));
|
|
6
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
-
|
|
9
|
-
describe("messageSequenceIdOverrideMiddleware", () => {
|
|
10
|
-
it("sequenceId is overrided", () => {
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
-
const next = args => args;
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
const dispatch = () => {
|
|
15
|
-
return 1;
|
|
16
|
-
};
|
|
17
|
-
const action = {
|
|
18
|
-
type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
|
|
19
|
-
payload: {
|
|
20
|
-
text: "test-text",
|
|
21
|
-
activity: {
|
|
22
|
-
channelId: "ACS_CHANNEL",
|
|
23
|
-
from: {
|
|
24
|
-
role: "user"
|
|
25
|
-
},
|
|
26
|
-
channelData: {
|
|
27
|
-
metadata: {
|
|
28
|
-
"OriginalMessageId": "1683742135918"
|
|
29
|
-
},
|
|
30
|
-
"webchat:sequence-id": 12345
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
|
|
36
|
-
let resultValue;
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
|
|
38
|
-
const channelData = middleware.payload.activity.channelData;
|
|
39
|
-
Object.keys(channelData).forEach(function (key) {
|
|
40
|
-
if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
|
|
41
|
-
resultValue = channelData[key];
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
expect(resultValue).toEqual(1683742135918);
|
|
45
|
-
});
|
|
46
|
-
it("sequenceId is not overrided due to empty string for originalID", () => {
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
-
const next = args => args;
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
-
const dispatch = () => {
|
|
51
|
-
return 1;
|
|
52
|
-
};
|
|
53
|
-
const action = {
|
|
54
|
-
type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
|
|
55
|
-
payload: {
|
|
56
|
-
text: "test-text",
|
|
57
|
-
activity: {
|
|
58
|
-
channelId: "ACS_CHANNEL",
|
|
59
|
-
from: {
|
|
60
|
-
role: "user"
|
|
61
|
-
},
|
|
62
|
-
channelData: {
|
|
63
|
-
metadata: {
|
|
64
|
-
"OriginalMessageId": ""
|
|
65
|
-
},
|
|
66
|
-
"webchat:sequence-id": 12345
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
|
|
72
|
-
let resultValue;
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
|
|
74
|
-
const channelData = middleware.payload.activity.channelData;
|
|
75
|
-
Object.keys(channelData).forEach(function (key) {
|
|
76
|
-
if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
|
|
77
|
-
resultValue = channelData[key];
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
expect(resultValue).toEqual(12345);
|
|
81
|
-
});
|
|
82
|
-
it("sequenceId is not overrided, due to OriginalMessageId being not a string of numbers ", () => {
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
84
|
-
const next = args => args;
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
-
const dispatch = () => {
|
|
87
|
-
return 1;
|
|
88
|
-
};
|
|
89
|
-
const action = {
|
|
90
|
-
type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
|
|
91
|
-
payload: {
|
|
92
|
-
text: "test-text",
|
|
93
|
-
activity: {
|
|
94
|
-
channelId: "ACS_CHANNEL",
|
|
95
|
-
from: {
|
|
96
|
-
role: "user"
|
|
97
|
-
},
|
|
98
|
-
channelData: {
|
|
99
|
-
metadata: {
|
|
100
|
-
"OriginalMessageId": "abcdf"
|
|
101
|
-
},
|
|
102
|
-
"webchat:sequence-id": 12345
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
|
|
108
|
-
let resultValue;
|
|
109
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
|
|
110
|
-
const channelData = middleware.payload.activity.channelData;
|
|
111
|
-
Object.keys(channelData).forEach(function (key) {
|
|
112
|
-
if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
|
|
113
|
-
resultValue = channelData[key];
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
expect(resultValue).toEqual(12345);
|
|
117
|
-
});
|
|
118
|
-
it("no changes since webchat id is not present", () => {
|
|
119
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
|
-
const next = args => args;
|
|
121
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
122
|
-
const dispatch = () => {
|
|
123
|
-
return 1;
|
|
124
|
-
};
|
|
125
|
-
const payloadExpected = {
|
|
126
|
-
payload: {
|
|
127
|
-
text: "test-text",
|
|
128
|
-
activity: {
|
|
129
|
-
channelId: "ACS_CHANNEL",
|
|
130
|
-
from: {
|
|
131
|
-
role: "user"
|
|
132
|
-
},
|
|
133
|
-
channelData: {
|
|
134
|
-
metadata: {
|
|
135
|
-
"OriginalMessageId": "123456789"
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
const action = {
|
|
142
|
-
type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
|
|
143
|
-
payload: {
|
|
144
|
-
text: "test-text",
|
|
145
|
-
activity: {
|
|
146
|
-
channelId: "ACS_CHANNEL",
|
|
147
|
-
from: {
|
|
148
|
-
role: "user"
|
|
149
|
-
},
|
|
150
|
-
channelData: {
|
|
151
|
-
metadata: {
|
|
152
|
-
"OriginalMessageId": "123456789"
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
|
|
159
|
-
expect(middleware.payload).toEqual(payloadExpected.payload);
|
|
160
|
-
});
|
|
161
|
-
it("no changes since OriginalMessageId is not present", () => {
|
|
162
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
163
|
-
const next = args => args;
|
|
164
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
165
|
-
const dispatch = () => {
|
|
166
|
-
return 1;
|
|
167
|
-
};
|
|
168
|
-
const payloadExpected = {
|
|
169
|
-
payload: {
|
|
170
|
-
text: "test-text",
|
|
171
|
-
activity: {
|
|
172
|
-
channelId: "ACS_CHANNEL",
|
|
173
|
-
from: {
|
|
174
|
-
role: "user"
|
|
175
|
-
},
|
|
176
|
-
channelData: {
|
|
177
|
-
metadata: {},
|
|
178
|
-
"webchat:sequence-id": 12345
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
const action = {
|
|
184
|
-
type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
|
|
185
|
-
payload: {
|
|
186
|
-
text: "test-text",
|
|
187
|
-
activity: {
|
|
188
|
-
channelId: "ACS_CHANNEL",
|
|
189
|
-
from: {
|
|
190
|
-
role: "user"
|
|
191
|
-
},
|
|
192
|
-
channelData: {
|
|
193
|
-
metadata: {},
|
|
194
|
-
"webchat:sequence-id": 12345
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
|
|
200
|
-
expect(middleware.payload).toEqual(payloadExpected.payload);
|
|
201
|
-
});
|
|
202
|
-
it("no override, since the type of message is not incoming activity", () => {
|
|
203
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
204
|
-
const next = args => args;
|
|
205
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
206
|
-
const dispatch = () => {
|
|
207
|
-
return 1;
|
|
208
|
-
};
|
|
209
|
-
const action = {
|
|
210
|
-
type: "something else",
|
|
211
|
-
payload: {
|
|
212
|
-
text: "test-text",
|
|
213
|
-
activity: {
|
|
214
|
-
channelId: "ACS_CHANNEL",
|
|
215
|
-
from: {
|
|
216
|
-
role: "user"
|
|
217
|
-
},
|
|
218
|
-
channelData: {
|
|
219
|
-
metadata: {
|
|
220
|
-
"OriginalMessageId": "1683742135918"
|
|
221
|
-
},
|
|
222
|
-
"webchat:sequence-id": 12345
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
|
|
228
|
-
let resultValue;
|
|
229
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
|
|
230
|
-
const channelData = middleware.payload.activity.channelData;
|
|
231
|
-
Object.keys(channelData).forEach(function (key) {
|
|
232
|
-
if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
|
|
233
|
-
resultValue = channelData[key];
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
expect(resultValue).toEqual(12345);
|
|
237
|
-
});
|
|
238
|
-
it("no override, since the channel is not ACS", () => {
|
|
239
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
240
|
-
const next = args => args;
|
|
241
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
242
|
-
const dispatch = () => {
|
|
243
|
-
return 1;
|
|
244
|
-
};
|
|
245
|
-
const action = {
|
|
246
|
-
type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
|
|
247
|
-
payload: {
|
|
248
|
-
text: "test-text",
|
|
249
|
-
activity: {
|
|
250
|
-
channelId: "something_else",
|
|
251
|
-
from: {
|
|
252
|
-
role: "user"
|
|
253
|
-
},
|
|
254
|
-
channelData: {
|
|
255
|
-
metadata: {
|
|
256
|
-
"OriginalMessageId": "1683742135918"
|
|
257
|
-
},
|
|
258
|
-
"webchat:sequence-id": 12345
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
|
|
264
|
-
let resultValue;
|
|
265
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
|
|
266
|
-
const channelData = middleware.payload.activity.channelData;
|
|
267
|
-
Object.keys(channelData).forEach(function (key) {
|
|
268
|
-
if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
|
|
269
|
-
resultValue = channelData[key];
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
expect(resultValue).toEqual(12345);
|
|
273
|
-
});
|
|
274
|
-
it("no override, since the channel channelData is not present", () => {
|
|
275
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
276
|
-
const next = args => args;
|
|
277
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
278
|
-
const dispatch = () => {
|
|
279
|
-
return 1;
|
|
280
|
-
};
|
|
281
|
-
const action = {
|
|
282
|
-
type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
|
|
283
|
-
payload: {
|
|
284
|
-
text: "test-text channel data is not present",
|
|
285
|
-
activity: {
|
|
286
|
-
channelId: "ACS_CHANNEL",
|
|
287
|
-
from: {
|
|
288
|
-
role: "user"
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
|
|
294
|
-
expect(middleware.payload).toEqual(action.payload);
|
|
295
|
-
});
|
|
296
|
-
it("no override, since channelData is empty object", () => {
|
|
297
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
298
|
-
const next = args => args;
|
|
299
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
300
|
-
const dispatch = () => {
|
|
301
|
-
return 1;
|
|
302
|
-
};
|
|
303
|
-
const action = {
|
|
304
|
-
type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
|
|
305
|
-
payload: {
|
|
306
|
-
text: "test-text channel data empty",
|
|
307
|
-
activity: {
|
|
308
|
-
channelId: "ACS_CHANNEL",
|
|
309
|
-
from: {
|
|
310
|
-
role: "user"
|
|
311
|
-
},
|
|
312
|
-
channelData: {}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
|
|
317
|
-
expect(middleware.payload).toEqual(action.payload);
|
|
318
|
-
});
|
|
319
|
-
it("no override, since channelData null", () => {
|
|
320
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
321
|
-
const next = args => args;
|
|
322
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
323
|
-
const dispatch = () => {
|
|
324
|
-
return 1;
|
|
325
|
-
};
|
|
326
|
-
const action = {
|
|
327
|
-
type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
|
|
328
|
-
payload: {
|
|
329
|
-
text: "test-channel Data null",
|
|
330
|
-
activity: {
|
|
331
|
-
channelId: "ACS_CHANNEL",
|
|
332
|
-
from: {
|
|
333
|
-
role: "user"
|
|
334
|
-
},
|
|
335
|
-
channelData: null
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
|
|
340
|
-
expect(middleware.payload).toEqual(action.payload);
|
|
341
|
-
});
|
|
342
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { OmnichannelChatSDK } from "@microsoft/omnichannel-chat-sdk";
|
|
2
|
-
import { cleanup } from "@testing-library/react";
|
|
3
|
-
jest.mock("@microsoft/omnichannel-chat-sdk");
|
|
4
|
-
describe("EmailTranscriptPaneStateful unit test", () => {
|
|
5
|
-
afterEach(() => {
|
|
6
|
-
cleanup;
|
|
7
|
-
jest.resetAllMocks();
|
|
8
|
-
});
|
|
9
|
-
it("Method emailLiveChatTranscript is called", async () => {
|
|
10
|
-
const omnichannelConfig = {
|
|
11
|
-
orgUrl: "",
|
|
12
|
-
orgId: "",
|
|
13
|
-
widgetId: ""
|
|
14
|
-
};
|
|
15
|
-
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
|
|
16
|
-
jest.spyOn(chatSDK, "emailLiveChatTranscript").mockResolvedValue(Promise.resolve());
|
|
17
|
-
const chatTranscriptBody = {
|
|
18
|
-
emailAddress: "sample@microsoft.com",
|
|
19
|
-
attachmentMessage: "sample",
|
|
20
|
-
locale: "sample"
|
|
21
|
-
};
|
|
22
|
-
try {
|
|
23
|
-
await chatSDK.emailLiveChatTranscript(chatTranscriptBody);
|
|
24
|
-
expect(chatSDK.emailLiveChatTranscript).toHaveBeenCalledTimes(1);
|
|
25
|
-
// eslint-disable-next-line no-empty
|
|
26
|
-
} catch (ex) {}
|
|
27
|
-
});
|
|
28
|
-
it("Method emailLiveChatTranscript throws exception", async () => {
|
|
29
|
-
const errorMessage = "Error";
|
|
30
|
-
const omnichannelConfig = {
|
|
31
|
-
orgUrl: "",
|
|
32
|
-
orgId: "",
|
|
33
|
-
widgetId: ""
|
|
34
|
-
};
|
|
35
|
-
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
|
|
36
|
-
jest.spyOn(chatSDK, "emailLiveChatTranscript").mockRejectedValue(new Error(errorMessage));
|
|
37
|
-
const chatTranscriptBody = {
|
|
38
|
-
emailAddress: "sample@microsoft.com",
|
|
39
|
-
attachmentMessage: "sample",
|
|
40
|
-
locale: "sample"
|
|
41
|
-
};
|
|
42
|
-
try {
|
|
43
|
-
await chatSDK.emailLiveChatTranscript(chatTranscriptBody);
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
-
} catch (ex) {
|
|
46
|
-
expect(ex.message).toEqual(errorMessage);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
it("Method emailLiveChatTranscript undefined throws exception", async () => {
|
|
50
|
-
const errorMessage = "Error";
|
|
51
|
-
const omnichannelConfig = {
|
|
52
|
-
orgUrl: "",
|
|
53
|
-
orgId: "",
|
|
54
|
-
widgetId: ""
|
|
55
|
-
};
|
|
56
|
-
const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
|
|
57
|
-
const chatTranscriptBody = {
|
|
58
|
-
emailAddress: "sample@microsoft.com",
|
|
59
|
-
attachmentMessage: "sample",
|
|
60
|
-
locale: "sample"
|
|
61
|
-
};
|
|
62
|
-
try {
|
|
63
|
-
await chatSDK.emailLiveChatTranscript(chatTranscriptBody);
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
-
} catch (ex) {
|
|
66
|
-
expect(ex.message).toEqual(errorMessage);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|