wingbot 3.31.5 → 3.31.8
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/package.json +1 -1
- package/src/BuildRouter.js +4 -2
- package/src/ConversationTester.js +2 -2
- package/src/Tester.js +42 -5
package/package.json
CHANGED
package/src/BuildRouter.js
CHANGED
|
@@ -310,7 +310,8 @@ class BuildRouter extends Router {
|
|
|
310
310
|
this._configTs = 0;
|
|
311
311
|
}
|
|
312
312
|
if (this._prebuiltGlobalIntents !== null) {
|
|
313
|
-
this.globalIntents
|
|
313
|
+
this.globalIntents.clear();
|
|
314
|
+
this._prebuiltGlobalIntents.forEach(([k, v]) => this.globalIntents.set(k, v));
|
|
314
315
|
}
|
|
315
316
|
}
|
|
316
317
|
|
|
@@ -326,7 +327,8 @@ class BuildRouter extends Router {
|
|
|
326
327
|
if (this._prebuiltGlobalIntents === null) {
|
|
327
328
|
this._prebuiltGlobalIntents = Array.from(this.globalIntents.entries());
|
|
328
329
|
} else {
|
|
329
|
-
this.globalIntents
|
|
330
|
+
this.globalIntents.clear();
|
|
331
|
+
this._prebuiltGlobalIntents.forEach(([k, v]) => this.globalIntents.set(k, v));
|
|
330
332
|
}
|
|
331
333
|
|
|
332
334
|
if (this._prebuiltRoutesCount === null) {
|
|
@@ -524,7 +524,7 @@ class ConversationTester {
|
|
|
524
524
|
await tester.text(textCase.text);
|
|
525
525
|
|
|
526
526
|
if (textCase.action) {
|
|
527
|
-
tester.passedAction(textCase.action);
|
|
527
|
+
tester.passedAction(textCase.action, true);
|
|
528
528
|
}
|
|
529
529
|
|
|
530
530
|
if (textCase.appId) {
|
|
@@ -623,7 +623,7 @@ class ConversationTester {
|
|
|
623
623
|
if (!this._options.disableAssertActions) {
|
|
624
624
|
passedAction.split('\n')
|
|
625
625
|
.map((a) => (a.trim().match(/^[a-z\-0-9/_]+$/) ? a : tokenize(a)))
|
|
626
|
-
.forEach((a) => a && t.passedAction(a));
|
|
626
|
+
.forEach((a) => a && t.passedAction(a, true));
|
|
627
627
|
}
|
|
628
628
|
|
|
629
629
|
const any = t.any();
|
package/src/Tester.js
CHANGED
|
@@ -69,9 +69,21 @@ class Tester {
|
|
|
69
69
|
info: e => console.info(e) // eslint-disable-line
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
+
this._cachedGiMap = null;
|
|
73
|
+
|
|
72
74
|
this._listener = (senderIdentifier, action, text, req, prevAction, doNotTrack) => {
|
|
75
|
+
const reqAction = req.action();
|
|
76
|
+
if (reqAction
|
|
77
|
+
&& !this._actionMatches(action, reqAction)
|
|
78
|
+
&& this._actionHasGlobalIntent(reqAction)) {
|
|
79
|
+
|
|
80
|
+
this._actionsCollector.push({
|
|
81
|
+
action: reqAction, text, prevAction, doNotTrack, isReqAction: true
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
73
85
|
this._actionsCollector.push({
|
|
74
|
-
action, text, prevAction, doNotTrack
|
|
86
|
+
action, text, prevAction, doNotTrack, isReqAction: false
|
|
75
87
|
});
|
|
76
88
|
};
|
|
77
89
|
|
|
@@ -127,10 +139,27 @@ class Tester {
|
|
|
127
139
|
this.features = null;
|
|
128
140
|
}
|
|
129
141
|
|
|
142
|
+
_actionHasGlobalIntent (action) {
|
|
143
|
+
if (!this.processor.reducer
|
|
144
|
+
|| !('globalIntents' in this.processor.reducer)) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
if (this._cachedGiMap === null) {
|
|
148
|
+
this._cachedGiMap = new Set();
|
|
149
|
+
|
|
150
|
+
for (const value of this.processor.reducer.globalIntents.values()) {
|
|
151
|
+
this._cachedGiMap.add(value.action);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return this._cachedGiMap.has(action.replace(/^\/?/, '/'));
|
|
156
|
+
}
|
|
157
|
+
|
|
130
158
|
dealloc () {
|
|
131
159
|
this.processor.reducer
|
|
132
160
|
.removeListener('_action', this._listener);
|
|
133
161
|
this.processor.reducer = null;
|
|
162
|
+
this._cachedGiMap = null;
|
|
134
163
|
}
|
|
135
164
|
|
|
136
165
|
/**
|
|
@@ -255,22 +284,30 @@ class Tester {
|
|
|
255
284
|
return new ResponseAssert(this.responses[this.responses.length - 1]);
|
|
256
285
|
}
|
|
257
286
|
|
|
287
|
+
_actionMatches (botAction, path) {
|
|
288
|
+
return botAction === path
|
|
289
|
+
|| (path === '*' && botAction === '/*')
|
|
290
|
+
|| (!botAction.match(/\*/) && actionMatches(botAction, path));
|
|
291
|
+
}
|
|
292
|
+
|
|
258
293
|
/**
|
|
259
|
-
* Checks, that
|
|
294
|
+
* Checks, that request passed an interaction
|
|
260
295
|
*
|
|
261
296
|
* @param {string} path
|
|
297
|
+
* @param {boolean} [matchRequestActions]
|
|
262
298
|
* @returns {this}
|
|
263
299
|
*
|
|
264
300
|
* @memberOf Tester
|
|
265
301
|
*/
|
|
266
|
-
passedAction (path) {
|
|
302
|
+
passedAction (path, matchRequestActions = false) {
|
|
267
303
|
const ok = this.actions
|
|
268
|
-
.some((action) => (action.
|
|
269
|
-
|
|
304
|
+
.some((action) => (!action.isReqAction || matchRequestActions)
|
|
305
|
+
&& this._actionMatches(action.action, path));
|
|
270
306
|
let actual;
|
|
271
307
|
if (!ok) {
|
|
272
308
|
const set = new Set();
|
|
273
309
|
actual = this.actions
|
|
310
|
+
.filter((a) => !a.isReqAction || matchRequestActions)
|
|
274
311
|
.map((a) => (a.doNotTrack ? `(system interaction) ${a.action}` : a.action))
|
|
275
312
|
.filter((a) => !set.has(a) && set.add(a));
|
|
276
313
|
assert.fail(asserts.ex('Interaction was not passed', path, actual));
|