wingbot 3.67.27 → 3.67.29
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
CHANGED
|
@@ -115,7 +115,7 @@ class ConversationTester {
|
|
|
115
115
|
* @param {boolean} [options.disableAssertTexts]
|
|
116
116
|
* @param {boolean} [options.disableAssertQuickReplies]
|
|
117
117
|
* @param {boolean} [options.useConversationForTextTestCases]
|
|
118
|
-
* @param {
|
|
118
|
+
* @param {number} [options.textThreshold]
|
|
119
119
|
* @param {number} [options.stepCasesPerStep]
|
|
120
120
|
* @param {number} [options.textCasesPerStep]
|
|
121
121
|
* @param {number} [options.textCaseParallel]
|
|
@@ -134,6 +134,7 @@ class ConversationTester {
|
|
|
134
134
|
};
|
|
135
135
|
this._output = '';
|
|
136
136
|
this._cachedBot = null;
|
|
137
|
+
this._cachedBotSnapshot = null;
|
|
137
138
|
this._log = options.log || console;
|
|
138
139
|
}
|
|
139
140
|
|
|
@@ -165,9 +166,10 @@ class ConversationTester {
|
|
|
165
166
|
* @param {object} validationRequestBody
|
|
166
167
|
* @param {number} [step]
|
|
167
168
|
* @param {string} [lang]
|
|
169
|
+
* @param {string} [snapshot]
|
|
168
170
|
* @returns {Promise<TestsOutput>}
|
|
169
171
|
*/
|
|
170
|
-
async test (validationRequestBody = null, step = null, lang = null) {
|
|
172
|
+
async test (validationRequestBody = null, step = null, lang = null, snapshot = null) {
|
|
171
173
|
if (step <= 1) {
|
|
172
174
|
this._cachedBot = null;
|
|
173
175
|
}
|
|
@@ -191,10 +193,20 @@ class ConversationTester {
|
|
|
191
193
|
for (const testsGroup of testsGroups) {
|
|
192
194
|
let stepResult;
|
|
193
195
|
if (testsGroup.type === 'texts') {
|
|
194
|
-
stepResult = await this._runTextCaseTests(
|
|
196
|
+
stepResult = await this._runTextCaseTests(
|
|
197
|
+
testsGroup,
|
|
198
|
+
botconfig,
|
|
199
|
+
lang,
|
|
200
|
+
snapshot
|
|
201
|
+
);
|
|
195
202
|
}
|
|
196
203
|
if (testsGroup.type === 'steps') {
|
|
197
|
-
stepResult = await this._runStepCaseTests(
|
|
204
|
+
stepResult = await this._runStepCaseTests(
|
|
205
|
+
testsGroup,
|
|
206
|
+
botconfig,
|
|
207
|
+
lang,
|
|
208
|
+
snapshot
|
|
209
|
+
);
|
|
198
210
|
}
|
|
199
211
|
results.push(stepResult);
|
|
200
212
|
}
|
|
@@ -403,21 +415,29 @@ class ConversationTester {
|
|
|
403
415
|
* @param {TestsGroup} testsGroup
|
|
404
416
|
* @param {object} [botconfig]
|
|
405
417
|
* @param {string} [lang]
|
|
406
|
-
* @
|
|
418
|
+
* @param {string} [snapshot]
|
|
419
|
+
* @returns {Promise<Tester>}
|
|
407
420
|
*/
|
|
408
|
-
_createTester (testsGroup, botconfig = null, lang = null) {
|
|
409
|
-
if (!this._cachedBot) {
|
|
410
|
-
this.
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
421
|
+
async _createTester (testsGroup, botconfig = null, lang = null, snapshot = null) {
|
|
422
|
+
if (!this._cachedBot || this._cachedBotSnapshot !== snapshot) {
|
|
423
|
+
this._cachedBotSnapshot = snapshot;
|
|
424
|
+
this._cachedBot = Promise.resolve(this._botFactory(true, snapshot))
|
|
425
|
+
.then((cb) => {
|
|
426
|
+
if (botconfig) {
|
|
427
|
+
cb.buildWithSnapshot(botconfig.blocks, Number.MAX_SAFE_INTEGER);
|
|
428
|
+
}
|
|
429
|
+
return cb;
|
|
430
|
+
})
|
|
431
|
+
.catch((e) => { this._cachedBot = null; throw e; });
|
|
414
432
|
}
|
|
415
433
|
|
|
434
|
+
const cachedBot = await this._cachedBot;
|
|
435
|
+
|
|
416
436
|
let t;
|
|
417
437
|
if (typeof this._options.testerFactory === 'function') {
|
|
418
|
-
t = this._options.testerFactory(
|
|
438
|
+
t = this._options.testerFactory(cachedBot, testsGroup);
|
|
419
439
|
} else {
|
|
420
|
-
t = new Tester(
|
|
440
|
+
t = new Tester(cachedBot);
|
|
421
441
|
t.allowEmptyResponse = !!this._options.allowEmptyResponse;
|
|
422
442
|
}
|
|
423
443
|
|
|
@@ -434,9 +454,10 @@ class ConversationTester {
|
|
|
434
454
|
* @param {TestsGroup} testsGroup
|
|
435
455
|
* @param {object} botconfig
|
|
436
456
|
* @param {string} [lang]
|
|
457
|
+
* @param {string} [snapshot]
|
|
437
458
|
*/
|
|
438
|
-
async _runTextCaseTests (testsGroup, botconfig = null, lang = null) {
|
|
439
|
-
const t = this._createTester(testsGroup, botconfig, lang);
|
|
459
|
+
async _runTextCaseTests (testsGroup, botconfig = null, lang = null, snapshot = null) {
|
|
460
|
+
const t = await this._createTester(testsGroup, botconfig, lang, snapshot);
|
|
440
461
|
let out = '';
|
|
441
462
|
let passing = 0;
|
|
442
463
|
let longestText = 0;
|
|
@@ -451,7 +472,7 @@ class ConversationTester {
|
|
|
451
472
|
|
|
452
473
|
const { textCaseParallel } = this._options;
|
|
453
474
|
const runTestCase = (textCase) => this
|
|
454
|
-
.executeTextCase(testsGroup, t, textCase, botconfig, longestText, lang);
|
|
475
|
+
.executeTextCase(testsGroup, t, textCase, botconfig, longestText, lang, snapshot);
|
|
455
476
|
|
|
456
477
|
while (iterate.length > 0) {
|
|
457
478
|
const cases = iterate.splice(0, textCaseParallel);
|
|
@@ -494,12 +515,13 @@ class ConversationTester {
|
|
|
494
515
|
* @param {TestsGroup} testsGroup
|
|
495
516
|
* @param {object} botconfig
|
|
496
517
|
* @param {string} [lang]
|
|
518
|
+
* @param {string} [snapshot]
|
|
497
519
|
*/
|
|
498
|
-
async _runStepCaseTests (testsGroup, botconfig = null, lang = null) {
|
|
520
|
+
async _runStepCaseTests (testsGroup, botconfig = null, lang = null, snapshot = null) {
|
|
499
521
|
const out = [];
|
|
500
522
|
|
|
501
523
|
for (const testCase of testsGroup.testCases) {
|
|
502
|
-
const t = this._createTester(testsGroup, botconfig, lang);
|
|
524
|
+
const t = await this._createTester(testsGroup, botconfig, lang, snapshot);
|
|
503
525
|
let o = '';
|
|
504
526
|
let fail = null;
|
|
505
527
|
// @ts-ignore
|
|
@@ -532,10 +554,19 @@ class ConversationTester {
|
|
|
532
554
|
* @param {*} botconfig
|
|
533
555
|
* @param {number} longestText
|
|
534
556
|
* @param {string} [lang]
|
|
557
|
+
* @param {string} [snapshot]
|
|
535
558
|
*/
|
|
536
|
-
async executeTextCase (
|
|
559
|
+
async executeTextCase (
|
|
560
|
+
testsGroup,
|
|
561
|
+
t,
|
|
562
|
+
textCase,
|
|
563
|
+
botconfig,
|
|
564
|
+
longestText,
|
|
565
|
+
lang = null,
|
|
566
|
+
snapshot = null
|
|
567
|
+
) {
|
|
537
568
|
if (this._options.useConversationForTextTestCases) {
|
|
538
|
-
const tester = this._createTester(testsGroup, botconfig, lang);
|
|
569
|
+
const tester = await this._createTester(testsGroup, botconfig, lang, snapshot);
|
|
539
570
|
|
|
540
571
|
try {
|
|
541
572
|
await tester.text(textCase.text);
|
package/src/graphApi/GraphApi.js
CHANGED
|
@@ -19,6 +19,11 @@ const DEFAULT_CACHE = 86400000; // 24 hours
|
|
|
19
19
|
* @param {object[]} [errors]
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {object} RequestParams
|
|
24
|
+
* @param {string} [snapshot]
|
|
25
|
+
*/
|
|
26
|
+
|
|
22
27
|
/** @typedef {import('../CallbackAuditLog')} AuditLog */
|
|
23
28
|
/** @typedef {import('graphql')} GqlLib */
|
|
24
29
|
|
|
@@ -110,9 +115,10 @@ class GraphApi {
|
|
|
110
115
|
* @param {string} [headers.Referer]
|
|
111
116
|
* @param {string} [headers.referer]
|
|
112
117
|
* @param {string} [wingbotToken]
|
|
118
|
+
* @param {RequestParams} [params]
|
|
113
119
|
* @returns {Promise<GraphQlResponse>}
|
|
114
120
|
*/
|
|
115
|
-
async request (body, headers, wingbotToken = undefined) {
|
|
121
|
+
async request (body, headers, wingbotToken = undefined, params = {}) {
|
|
116
122
|
assert.ok(body && typeof body === 'object', 'GraphQL request should be an object with a request property');
|
|
117
123
|
assert.equal(typeof body.query, 'string', 'GraphQL request should contain a query property');
|
|
118
124
|
|
|
@@ -149,7 +155,8 @@ class GraphApi {
|
|
|
149
155
|
const ctx = {
|
|
150
156
|
token,
|
|
151
157
|
groups: this._defaultGroups,
|
|
152
|
-
audit
|
|
158
|
+
audit,
|
|
159
|
+
params
|
|
153
160
|
};
|
|
154
161
|
|
|
155
162
|
const response = await this._gql.graphql({
|
|
@@ -23,7 +23,7 @@ const ConversationTester = require('../ConversationTester');
|
|
|
23
23
|
* @param {boolean} [options.disableAssertTexts]
|
|
24
24
|
* @param {boolean} [options.disableAssertQuickReplies]
|
|
25
25
|
* @param {boolean} [options.useConversationForTextTestCases]
|
|
26
|
-
* @param {
|
|
26
|
+
* @param {number} [options.textThreshold]
|
|
27
27
|
* @param {number} [options.stepCasesPerStep]
|
|
28
28
|
* @param {number} [options.textCasesPerStep]
|
|
29
29
|
* @param {number} [options.textCaseParallel]
|
|
@@ -102,7 +102,7 @@ function validateBotApi (botFactory, postBackTest = null, textTest = null, acl =
|
|
|
102
102
|
validationRequestBody = decompress(validationRequestBody);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
const bot = botFactory();
|
|
105
|
+
const bot = await Promise.resolve(botFactory(true, ctx.snapshot));
|
|
106
106
|
|
|
107
107
|
await ctx.audit('validateBot');
|
|
108
108
|
return validate(bot, validationRequestBody, postBackTest, textTest);
|