botium-core 1.14.10 → 1.15.2
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/dist/botium-cjs.js +214 -114
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +213 -113
- package/dist/botium-es.js.map +1 -1
- package/package.json +4 -4
- package/samples/connectors/simplerest-async/jokebot.js +24 -18
- package/src/Capabilities.js +3 -0
- package/src/containers/BaseContainer.js +1 -2
- package/src/containers/plugins/SimpleRestContainer.js +158 -89
- package/src/scripting/Convo.js +1 -1
- package/src/scripting/helper.js +59 -22
- package/src/scripting/logichook/asserter/BaseTextAsserter.js +1 -2
- package/src/scripting/logichook/asserter/ButtonsAsserter.js +3 -4
- package/src/scripting/logichook/userinput/MediaInput.js +14 -17
- package/test/compiler/compilertxt.spec.js +18 -0
- package/test/compiler/convos/txt/convos_jsonmessage.convo.txt +10 -0
- package/test/connectors/simplerest.spec.js +290 -42
- package/test/hooks/customhooks.spec.js +3 -5
- package/test/scripting/helper.spec.js +21 -0
- package/test/scripting/scriptingProvider.spec.js +34 -0
|
@@ -172,17 +172,16 @@ describe('connectors.simplerest', function () {
|
|
|
172
172
|
.persist()
|
|
173
173
|
const driver = new BotDriver(caps)
|
|
174
174
|
const container = await driver.Build()
|
|
175
|
-
const body = JSON.stringify({})
|
|
176
175
|
const pingConfig = {
|
|
177
176
|
method: 'GET',
|
|
178
177
|
uri: 'https://mock.com/pingget',
|
|
179
|
-
body,
|
|
180
178
|
timeout: 10000
|
|
181
179
|
}
|
|
182
180
|
const response = await container.pluginInstance._waitForUrlResponse(pingConfig, 2)
|
|
183
181
|
assert.equal(response.body, '{"status":"ok"}')
|
|
184
182
|
scope.persist(false)
|
|
185
183
|
})
|
|
184
|
+
|
|
186
185
|
it('post ping endpoint', async function () {
|
|
187
186
|
const caps = {
|
|
188
187
|
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
@@ -215,6 +214,7 @@ describe('connectors.simplerest', function () {
|
|
|
215
214
|
assert.equal(response.body, '{"status":"ok"}')
|
|
216
215
|
scope.persist(false)
|
|
217
216
|
})
|
|
217
|
+
|
|
218
218
|
it('post stop endpoint', async function () {
|
|
219
219
|
const caps = {
|
|
220
220
|
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
@@ -242,6 +242,7 @@ describe('connectors.simplerest', function () {
|
|
|
242
242
|
assert.equal(response.body.status, 'ok')
|
|
243
243
|
scope.persist(false)
|
|
244
244
|
})
|
|
245
|
+
|
|
245
246
|
it('error case can\'t connect', async function () {
|
|
246
247
|
const caps = {
|
|
247
248
|
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
@@ -277,28 +278,153 @@ describe('connectors.simplerest', function () {
|
|
|
277
278
|
}
|
|
278
279
|
scope.persist(false)
|
|
279
280
|
})
|
|
280
|
-
|
|
281
|
+
|
|
282
|
+
it('error case no chat endpoint', async function () {
|
|
281
283
|
const caps = {
|
|
282
284
|
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
283
285
|
[Capabilities.SIMPLEREST_URL]: 'https://mock2.com/endpoint',
|
|
286
|
+
// [Capabilities.SIMPLEREST_URL]: 'https://jsonplaceholder.typicode.com/posts/123456',
|
|
287
|
+
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: ['$.text']
|
|
288
|
+
}
|
|
289
|
+
const scope = nock('https://mock2.com')
|
|
290
|
+
.get('/endpoint')
|
|
291
|
+
.reply(404, {
|
|
292
|
+
error: 'notOk'
|
|
293
|
+
})
|
|
294
|
+
.persist()
|
|
295
|
+
const driver = new BotDriver(caps)
|
|
296
|
+
const container = await driver.Build()
|
|
297
|
+
await container.Start()
|
|
298
|
+
|
|
299
|
+
try {
|
|
300
|
+
await container.UserSays({ text: 'hallo' })
|
|
301
|
+
await container.WaitBotSays()
|
|
302
|
+
throw new Error('should have failed')
|
|
303
|
+
} catch (err) {
|
|
304
|
+
assert.isTrue(err.message.includes('notOk'))
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
await container.Stop()
|
|
308
|
+
await container.Clean()
|
|
309
|
+
scope.persist(false)
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
it('error case chat endpoint timeout', async function () {
|
|
313
|
+
const caps = {
|
|
314
|
+
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
315
|
+
[Capabilities.SIMPLEREST_TIMEOUT]: 100,
|
|
316
|
+
[Capabilities.SIMPLEREST_URL]: 'https://mock2.com/endpointTimeout',
|
|
317
|
+
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: ['$.text']
|
|
318
|
+
}
|
|
319
|
+
const scope = nock('https://mock2.com')
|
|
320
|
+
.get('/endpointTimeout')
|
|
321
|
+
.delayConnection(200)
|
|
322
|
+
.reply(200, {
|
|
323
|
+
status: 'ok'
|
|
324
|
+
})
|
|
325
|
+
.persist()
|
|
326
|
+
const driver = new BotDriver(caps)
|
|
327
|
+
const container = await driver.Build()
|
|
328
|
+
await container.Start()
|
|
329
|
+
|
|
330
|
+
try {
|
|
331
|
+
await container.UserSays({ text: 'hallo' })
|
|
332
|
+
await container.WaitBotSays()
|
|
333
|
+
throw new Error('should have failed')
|
|
334
|
+
} catch (err) {
|
|
335
|
+
assert.isTrue(err.message.includes('The operation was aborted due to timeout'))
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
await container.Stop()
|
|
339
|
+
await container.Clean()
|
|
340
|
+
scope.persist(false)
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
it('should follow redirect', async function () {
|
|
344
|
+
const caps = {
|
|
345
|
+
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
346
|
+
[Capabilities.SIMPLEREST_URL]: 'https://mock2.com/endpoint1',
|
|
347
|
+
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: ['$.text']
|
|
348
|
+
}
|
|
349
|
+
const scope = nock('https://mock2.com')
|
|
350
|
+
.get('/endpoint1')
|
|
351
|
+
.reply(301, undefined, { location: '/endpoint2' })
|
|
352
|
+
.get('/endpoint2')
|
|
353
|
+
.reply(404, {
|
|
354
|
+
error: 'redirectedToNotExisting'
|
|
355
|
+
}).persist()
|
|
356
|
+
const driver = new BotDriver(caps)
|
|
357
|
+
const container = await driver.Build()
|
|
358
|
+
await container.Start()
|
|
359
|
+
|
|
360
|
+
try {
|
|
361
|
+
await container.UserSays({ text: 'hallo' })
|
|
362
|
+
await container.WaitBotSays()
|
|
363
|
+
throw new Error('should have failed')
|
|
364
|
+
} catch (err) {
|
|
365
|
+
assert.isTrue(err.message.includes('redirectedToNotExisting'))
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
await container.Stop()
|
|
369
|
+
await container.Clean()
|
|
370
|
+
assert.isTrue(scope.isDone())
|
|
371
|
+
scope.persist(false)
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
it('should send form parameters', async function () {
|
|
375
|
+
const FORMPARAM = {
|
|
376
|
+
formparam1: 'valueparam1+-%'
|
|
377
|
+
}
|
|
378
|
+
const caps = {
|
|
379
|
+
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
380
|
+
[Capabilities.SIMPLEREST_METHOD]: 'POST',
|
|
381
|
+
[Capabilities.SIMPLEREST_URL]: 'https://mock2.com/endpointForm',
|
|
382
|
+
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: ['$.status']
|
|
383
|
+
}
|
|
384
|
+
const scope = nock('https://mock2.com')
|
|
385
|
+
.post('/endpointForm', (body) => {
|
|
386
|
+
return body === 'formparam1=valueparam1%2B-%25'
|
|
387
|
+
})
|
|
388
|
+
.reply(200, {
|
|
389
|
+
status: 'ok'
|
|
390
|
+
})
|
|
391
|
+
.persist()
|
|
392
|
+
const driver = new BotDriver(caps)
|
|
393
|
+
const container = await driver.Build()
|
|
394
|
+
await container.Start()
|
|
395
|
+
|
|
396
|
+
const msg = {
|
|
397
|
+
ADD_FORM_PARAM: FORMPARAM
|
|
398
|
+
}
|
|
399
|
+
await container.UserSays(msg)
|
|
400
|
+
await container.WaitBotSays()
|
|
401
|
+
|
|
402
|
+
await container.Clean()
|
|
403
|
+
scope.persist(false)
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
it('should store cookies from ping and use for user says request', async function () {
|
|
407
|
+
const caps = {
|
|
408
|
+
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
409
|
+
[Capabilities.SIMPLEREST_URL]: 'http://mock2.com/endpoint',
|
|
284
410
|
[Capabilities.SIMPLEREST_HEADERS_TEMPLATE]: {
|
|
285
|
-
HEADER1: 'HEADER1VALUE'
|
|
286
|
-
HEADER2: '{{msg.token}}'
|
|
411
|
+
HEADER1: 'HEADER1VALUE'
|
|
287
412
|
},
|
|
288
413
|
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: ['$.text'],
|
|
289
|
-
[Capabilities.SIMPLEREST_PING_URL]: '
|
|
414
|
+
[Capabilities.SIMPLEREST_PING_URL]: 'http://mock2.com/pingget'
|
|
290
415
|
}
|
|
291
|
-
const scope = nock('
|
|
416
|
+
const scope = nock('http://mock2.com')
|
|
292
417
|
.get('/pingget')
|
|
293
418
|
.reply(200, {
|
|
294
419
|
status: 'ok'
|
|
295
420
|
}, {
|
|
296
|
-
'
|
|
421
|
+
'Set-Cookie': 'cookie1=value1;cookie2=value2'
|
|
297
422
|
}).persist()
|
|
298
423
|
|
|
299
|
-
const scope2 = nock('
|
|
424
|
+
const scope2 = nock('http://mock2.com', {
|
|
300
425
|
reqheaders: {
|
|
301
|
-
cookie: '
|
|
426
|
+
cookie: 'cookie1=value1;cookie2=value2',
|
|
427
|
+
header1: 'HEADER1VALUE'
|
|
302
428
|
}
|
|
303
429
|
})
|
|
304
430
|
.get('/endpoint')
|
|
@@ -319,6 +445,7 @@ describe('connectors.simplerest', function () {
|
|
|
319
445
|
scope2.persist(false)
|
|
320
446
|
})
|
|
321
447
|
})
|
|
448
|
+
|
|
322
449
|
describe('build', function () {
|
|
323
450
|
it('should build JSON GET url', async function () {
|
|
324
451
|
const myCaps = Object.assign({}, myCapsGet)
|
|
@@ -337,6 +464,7 @@ describe('connectors.simplerest', function () {
|
|
|
337
464
|
|
|
338
465
|
await container.Clean()
|
|
339
466
|
})
|
|
467
|
+
|
|
340
468
|
it('should build JSON GET url from encoded characters', async function () {
|
|
341
469
|
const myCaps = Object.assign({}, myCapsGet)
|
|
342
470
|
myCaps[Capabilities.SIMPLEREST_HEADERS_TEMPLATE] = { ORIG: '{{{msg.messageText}}}' }
|
|
@@ -370,12 +498,15 @@ describe('connectors.simplerest', function () {
|
|
|
370
498
|
|
|
371
499
|
assert.isTrue(request.json)
|
|
372
500
|
assert.isObject(request.headers)
|
|
373
|
-
assert.
|
|
501
|
+
assert.isString(request.body)
|
|
502
|
+
const body = JSON.parse(request.body)
|
|
503
|
+
assert.isObject(body)
|
|
374
504
|
assert.equal(request.headers.HEADER2, msg.token)
|
|
375
|
-
assert.equal(
|
|
505
|
+
assert.equal(body.BODY2, msg.messageText)
|
|
376
506
|
|
|
377
507
|
await container.Clean()
|
|
378
508
|
})
|
|
509
|
+
|
|
379
510
|
it('should build JSON POST request body with special chars', async function () {
|
|
380
511
|
const myCaps = Object.assign({}, myCapsPost)
|
|
381
512
|
myCaps[Capabilities.SIMPLEREST_HEADERS_TEMPLATE] = {
|
|
@@ -391,12 +522,15 @@ describe('connectors.simplerest', function () {
|
|
|
391
522
|
const request = await container.pluginInstance._buildRequest(msgSpecial)
|
|
392
523
|
assert.isTrue(request.json)
|
|
393
524
|
assert.isObject(request.headers)
|
|
394
|
-
assert.
|
|
525
|
+
assert.isString(request.body)
|
|
526
|
+
const body = JSON.parse(request.body)
|
|
527
|
+
assert.isObject(body)
|
|
395
528
|
assert.equal(request.headers.HEADER2, msgSpecial.token)
|
|
396
|
-
assert.equal(
|
|
529
|
+
assert.equal(body.BODY2, msgSpecial.messageText)
|
|
397
530
|
|
|
398
531
|
await container.Clean()
|
|
399
532
|
})
|
|
533
|
+
|
|
400
534
|
it('should build JSON POST request body from strings', async function () {
|
|
401
535
|
const myCaps = Object.assign({}, myCapsPost)
|
|
402
536
|
myCaps[Capabilities.SIMPLEREST_BODY_TEMPLATE] = JSON.stringify(myCaps[Capabilities.SIMPLEREST_BODY_TEMPLATE])
|
|
@@ -411,12 +545,15 @@ describe('connectors.simplerest', function () {
|
|
|
411
545
|
|
|
412
546
|
assert.isTrue(request.json)
|
|
413
547
|
assert.isObject(request.headers)
|
|
414
|
-
assert.
|
|
548
|
+
assert.isString(request.body)
|
|
549
|
+
const body = JSON.parse(request.body)
|
|
550
|
+
assert.isObject(body)
|
|
415
551
|
assert.equal(request.headers.HEADER2, msg.token)
|
|
416
|
-
assert.equal(
|
|
552
|
+
assert.equal(body.BODY2, msg.messageText)
|
|
417
553
|
|
|
418
554
|
await container.Clean()
|
|
419
555
|
})
|
|
556
|
+
|
|
420
557
|
it('should build url-form-encoded POST request body', async function () {
|
|
421
558
|
const myCaps = Object.assign({}, myCapsPost)
|
|
422
559
|
myCaps[Capabilities.SIMPLEREST_BODY_RAW] = true
|
|
@@ -435,6 +572,7 @@ describe('connectors.simplerest', function () {
|
|
|
435
572
|
|
|
436
573
|
await container.Clean()
|
|
437
574
|
})
|
|
575
|
+
|
|
438
576
|
it('should use scriptingMemory variables', async function () {
|
|
439
577
|
process.env.SAMPLE_ENV = 'SAMPLE_ENV'
|
|
440
578
|
|
|
@@ -446,30 +584,32 @@ describe('connectors.simplerest', function () {
|
|
|
446
584
|
const request = await container.pluginInstance._buildRequest(msg)
|
|
447
585
|
|
|
448
586
|
assert.isTrue(request.json)
|
|
449
|
-
assert.
|
|
587
|
+
assert.isString(request.body)
|
|
450
588
|
|
|
451
|
-
|
|
452
|
-
assert.
|
|
589
|
+
const body = JSON.parse(request.body)
|
|
590
|
+
assert.exists(body.FUNCTION_WITHOUT_PARAM)
|
|
591
|
+
assert.equal(body.FUNCTION_WITHOUT_PARAM.length, 4)
|
|
453
592
|
|
|
454
|
-
assert.exists(
|
|
455
|
-
assert.equal(
|
|
593
|
+
assert.exists(body.FUNCTION_WITH_PARAM)
|
|
594
|
+
assert.equal(body.FUNCTION_WITH_PARAM.length, 5)
|
|
456
595
|
|
|
457
|
-
assert.exists(
|
|
458
|
-
assert.equal(
|
|
596
|
+
assert.exists(body.FUNCTION_WITH_PARAM_FROM_SCRIPTING_MEMORY)
|
|
597
|
+
assert.equal(body.FUNCTION_WITH_PARAM_FROM_SCRIPTING_MEMORY.length, 7)
|
|
459
598
|
|
|
460
|
-
assert.exists(
|
|
461
|
-
assert.equal(
|
|
599
|
+
assert.exists(body.SAMPLE_ENV)
|
|
600
|
+
assert.equal(body.SAMPLE_ENV, 'SAMPLE_ENV')
|
|
462
601
|
|
|
463
|
-
assert.exists(
|
|
464
|
-
assert.equal(
|
|
602
|
+
assert.exists(body.VARIABLE)
|
|
603
|
+
assert.equal(body.VARIABLE, 'varvalue')
|
|
465
604
|
|
|
466
|
-
assert.equal(
|
|
467
|
-
assert.equal(
|
|
468
|
-
assert.equal(
|
|
469
|
-
assert.equal(
|
|
605
|
+
assert.equal(body.PROJECTNAME, 'MYPROJECTNAME')
|
|
606
|
+
assert.equal(body.TESTSESSIONNAME, 'MYTESTSESSIONNAME')
|
|
607
|
+
assert.equal(body.TESTCASENAME, 'MYTESTCASENAME')
|
|
608
|
+
assert.equal(body.CUSTOMCAPABILITY, 'MYCUSTOMCAPABILITY')
|
|
470
609
|
|
|
471
610
|
await container.Clean()
|
|
472
611
|
})
|
|
612
|
+
|
|
473
613
|
it('should parse string template', async function () {
|
|
474
614
|
const myCaps = Object.assign({}, myCapsStringTemplate)
|
|
475
615
|
const driver = new BotDriver(myCaps)
|
|
@@ -479,12 +619,13 @@ describe('connectors.simplerest', function () {
|
|
|
479
619
|
const request = await container.pluginInstance._buildRequest(msg)
|
|
480
620
|
|
|
481
621
|
assert.isTrue(request.json)
|
|
482
|
-
assert.
|
|
622
|
+
assert.isString(request.body)
|
|
483
623
|
|
|
484
|
-
assert.exists(request.body.timestamp)
|
|
624
|
+
assert.exists(JSON.parse(request.body).timestamp)
|
|
485
625
|
|
|
486
626
|
await container.Clean()
|
|
487
627
|
})
|
|
628
|
+
|
|
488
629
|
it('should use scriptingMemory variables for step, and conversation id if template is set', async function () {
|
|
489
630
|
const myCaps = Object.assign({}, myCapsConvAndStepId)
|
|
490
631
|
const driver = new BotDriver(myCaps)
|
|
@@ -494,28 +635,34 @@ describe('connectors.simplerest', function () {
|
|
|
494
635
|
const request = await container.pluginInstance._buildRequest(msg)
|
|
495
636
|
|
|
496
637
|
assert.isTrue(request.json)
|
|
497
|
-
assert.
|
|
638
|
+
assert.isString(request.body)
|
|
498
639
|
|
|
499
|
-
|
|
500
|
-
assert.
|
|
640
|
+
const body = JSON.parse(request.body)
|
|
641
|
+
assert.exists(body.SESSION_ID)
|
|
642
|
+
assert.equal(body.SESSION_ID.length, 13)
|
|
501
643
|
|
|
502
|
-
assert.exists(
|
|
503
|
-
assert.equal(
|
|
644
|
+
assert.exists(body.MESSAGE_ID)
|
|
645
|
+
assert.equal(body.MESSAGE_ID.length, 7)
|
|
504
646
|
|
|
505
647
|
await container.Clean()
|
|
506
648
|
})
|
|
649
|
+
|
|
507
650
|
it('should use request hook, from string', async function () {
|
|
508
651
|
await _assertHook(Object.assign({}, myCapsRequestHookFromString))
|
|
509
652
|
})
|
|
653
|
+
|
|
510
654
|
it('should use request hook, from function', async function () {
|
|
511
655
|
await _assertHook(Object.assign({}, myCapsRequestHookFromFunction))
|
|
512
656
|
})
|
|
657
|
+
|
|
513
658
|
it('should use request hook, from function2', async function () {
|
|
514
659
|
await _assertHook(Object.assign({}, myCapsRequestHookFromFunction))
|
|
515
660
|
})
|
|
661
|
+
|
|
516
662
|
it('should use request hook, from module', async function () {
|
|
517
663
|
await _assertHook(Object.assign({}, myCapsRequestHookFromModule))
|
|
518
664
|
})
|
|
665
|
+
|
|
519
666
|
it('should reject request hook, from invalid string', async function () {
|
|
520
667
|
const driver = new BotDriver(myCapsRequestHookFromStringInvalid)
|
|
521
668
|
try {
|
|
@@ -525,6 +672,7 @@ describe('connectors.simplerest', function () {
|
|
|
525
672
|
assert.isTrue(err.message.includes('Hook specification "\'!\'" invalid'))
|
|
526
673
|
}
|
|
527
674
|
})
|
|
675
|
+
|
|
528
676
|
it('should add query params from UPDATE_CUSTOM (without "?")', async function () {
|
|
529
677
|
const myCaps = Object.assign({}, myCapsGet)
|
|
530
678
|
const myMsg = Object.assign({}, msg)
|
|
@@ -544,6 +692,7 @@ describe('connectors.simplerest', function () {
|
|
|
544
692
|
|
|
545
693
|
await container.Clean()
|
|
546
694
|
})
|
|
695
|
+
|
|
547
696
|
it('should add query params from UPDATE_CUSTOM (with "?")', async function () {
|
|
548
697
|
const myCaps = Object.assign({}, myCapsGet)
|
|
549
698
|
myCaps.SIMPLEREST_URL = 'http://my-host.com/api/endpoint/messageText?const1=const1'
|
|
@@ -564,6 +713,7 @@ describe('connectors.simplerest', function () {
|
|
|
564
713
|
|
|
565
714
|
await container.Clean()
|
|
566
715
|
})
|
|
716
|
+
|
|
567
717
|
it('should handle non string query params from UPDATE_CUSTOM', async function () {
|
|
568
718
|
const myCaps = Object.assign({}, myCapsGet)
|
|
569
719
|
const myMsg = Object.assign({}, msg)
|
|
@@ -591,6 +741,7 @@ describe('connectors.simplerest', function () {
|
|
|
591
741
|
|
|
592
742
|
await container.Clean()
|
|
593
743
|
})
|
|
744
|
+
|
|
594
745
|
it('should add form params from UPDATE_CUSTOM (without "?")', async function () {
|
|
595
746
|
const myCaps = Object.assign({}, myCapsFormPost)
|
|
596
747
|
const myMsg = Object.assign({}, msg)
|
|
@@ -605,12 +756,12 @@ describe('connectors.simplerest', function () {
|
|
|
605
756
|
|
|
606
757
|
await container.Start()
|
|
607
758
|
const request = await container.pluginInstance._buildRequest(myMsg)
|
|
608
|
-
assert.
|
|
609
|
-
assert.equal(request.
|
|
610
|
-
assert.equal(request.form.formparam2, 'messageText')
|
|
759
|
+
assert.isString(request.body)
|
|
760
|
+
assert.equal(request.body, 'formparam1=valueparam1&formparam2=messageText')
|
|
611
761
|
|
|
612
762
|
await container.Clean()
|
|
613
763
|
})
|
|
764
|
+
|
|
614
765
|
it('should add header from UPDATE_CUSTOM', async function () {
|
|
615
766
|
const myCaps = Object.assign({}, myCapsGet)
|
|
616
767
|
const myMsg = Object.assign({}, msg)
|
|
@@ -631,6 +782,7 @@ describe('connectors.simplerest', function () {
|
|
|
631
782
|
|
|
632
783
|
await container.Clean()
|
|
633
784
|
})
|
|
785
|
+
|
|
634
786
|
it('should handle and add non string header from UPDATE_CUSTOM', async function () {
|
|
635
787
|
const myCaps = Object.assign({}, myCapsGet)
|
|
636
788
|
const myMsg = Object.assign({}, msg)
|
|
@@ -656,9 +808,84 @@ describe('connectors.simplerest', function () {
|
|
|
656
808
|
assert.isNull(request.headers.headerparam2.middleName)
|
|
657
809
|
assert.equal(request.headers.headerparam2.lastName, 'Last')
|
|
658
810
|
|
|
811
|
+
await container.Clean()
|
|
812
|
+
})
|
|
813
|
+
it('should parse jsonmessage from sourcedata if it enabled', async function () {
|
|
814
|
+
const msgJSON = {
|
|
815
|
+
sourceData: {
|
|
816
|
+
key: 'value'
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
const myCaps = Object.assign({}, myCapsPost)
|
|
821
|
+
myCaps[Capabilities.SIMPLEREST_BODY_FROM_JSON] = true
|
|
822
|
+
myCaps[Capabilities.SIMPLEREST_HEADERS_TEMPLATE] = undefined
|
|
823
|
+
const driver = new BotDriver(myCaps)
|
|
824
|
+
const container = await driver.Build()
|
|
825
|
+
assert.equal(container.pluginInstance.constructor.name, 'SimpleRestContainer')
|
|
826
|
+
|
|
827
|
+
await container.Start()
|
|
828
|
+
const request = await container.pluginInstance._buildRequest(msgJSON)
|
|
829
|
+
|
|
830
|
+
assert.isTrue(request.json)
|
|
831
|
+
assert.isString(request.body)
|
|
832
|
+
const body = JSON.parse(request.body)
|
|
833
|
+
assert.exists(body.key)
|
|
834
|
+
assert.exists(msgJSON.sourceData)
|
|
835
|
+
assert.exists(msgJSON.sourceData.key)
|
|
836
|
+
assert.equal(body.key, msgJSON.sourceData.key)
|
|
837
|
+
|
|
838
|
+
await container.Clean()
|
|
839
|
+
})
|
|
840
|
+
it('should fall back to text message if using jsonmessage from sourcedata is enabled, but sourcedata is not set', async function () {
|
|
841
|
+
const myCaps = Object.assign({}, myCapsPost)
|
|
842
|
+
myCaps[Capabilities.SIMPLEREST_BODY_FROM_JSON] = true
|
|
843
|
+
myCaps[Capabilities.SIMPLEREST_HEADERS_TEMPLATE] = undefined
|
|
844
|
+
const driver = new BotDriver(myCaps)
|
|
845
|
+
const container = await driver.Build()
|
|
846
|
+
assert.equal(container.pluginInstance.constructor.name, 'SimpleRestContainer')
|
|
847
|
+
|
|
848
|
+
await container.Start()
|
|
849
|
+
const request = await container.pluginInstance._buildRequest(msg)
|
|
850
|
+
|
|
851
|
+
assert.isTrue(request.json)
|
|
852
|
+
assert.isString(request.body)
|
|
853
|
+
const body = JSON.parse(request.body)
|
|
854
|
+
assert.equal(body.BODY2, msg.messageText)
|
|
855
|
+
|
|
856
|
+
await container.Clean()
|
|
857
|
+
})
|
|
858
|
+
it('should handle somehow if jsonmessage from sourcedata is enabled, and booth json, and text are set in the user message (impossible state)', async function () {
|
|
859
|
+
// this is not a valid state. In case there is a json as message in a convo.txt, text parser parses it into the sourceData field, and keeps messageText empty
|
|
860
|
+
const msgTextAndJSONIllegal = {
|
|
861
|
+
messageText: 'some user message',
|
|
862
|
+
sourceData: {
|
|
863
|
+
key: 'value'
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
const myCaps = Object.assign({}, myCapsPost)
|
|
867
|
+
myCaps[Capabilities.SIMPLEREST_BODY_FROM_JSON] = true
|
|
868
|
+
myCaps[Capabilities.SIMPLEREST_HEADERS_TEMPLATE] = undefined
|
|
869
|
+
const driver = new BotDriver(myCaps)
|
|
870
|
+
const container = await driver.Build()
|
|
871
|
+
assert.equal(container.pluginInstance.constructor.name, 'SimpleRestContainer')
|
|
872
|
+
|
|
873
|
+
await container.Start()
|
|
874
|
+
const request = await container.pluginInstance._buildRequest(msgTextAndJSONIllegal)
|
|
875
|
+
|
|
876
|
+
// json message from sourcedata wins, but we dont really care wich one. Just no error should be thrown.
|
|
877
|
+
assert.isTrue(request.json)
|
|
878
|
+
assert.isString(request.body)
|
|
879
|
+
const body = JSON.parse(request.body)
|
|
880
|
+
assert.exists(body.key)
|
|
881
|
+
assert.exists(msgTextAndJSONIllegal.sourceData)
|
|
882
|
+
assert.exists(msgTextAndJSONIllegal.sourceData.key)
|
|
883
|
+
assert.equal(body.key, msgTextAndJSONIllegal.sourceData.key)
|
|
884
|
+
|
|
659
885
|
await container.Clean()
|
|
660
886
|
})
|
|
661
887
|
})
|
|
888
|
+
|
|
662
889
|
describe('processBody', function () {
|
|
663
890
|
it('should process simple response from hook', async function () {
|
|
664
891
|
const myCaps = Object.assign({}, myCapsResponseHook)
|
|
@@ -675,6 +902,7 @@ describe('connectors.simplerest', function () {
|
|
|
675
902
|
|
|
676
903
|
await container.Clean()
|
|
677
904
|
})
|
|
905
|
+
|
|
678
906
|
it('should ignore empty response', async function () {
|
|
679
907
|
const myCaps = Object.assign({}, myCapsGet, {
|
|
680
908
|
[Capabilities.SIMPLEREST_BODY_JSONPATH]: '$.responses[*]',
|
|
@@ -694,6 +922,7 @@ describe('connectors.simplerest', function () {
|
|
|
694
922
|
|
|
695
923
|
await container.Clean()
|
|
696
924
|
})
|
|
925
|
+
|
|
697
926
|
it('should not ignore empty response', async function () {
|
|
698
927
|
const myCaps = Object.assign({}, myCapsGet, {
|
|
699
928
|
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: '$.text',
|
|
@@ -713,6 +942,7 @@ describe('connectors.simplerest', function () {
|
|
|
713
942
|
|
|
714
943
|
await container.Clean()
|
|
715
944
|
})
|
|
945
|
+
|
|
716
946
|
it('should not ignore empty response with media', async function () {
|
|
717
947
|
const myCaps = Object.assign({}, myCapsGet, {
|
|
718
948
|
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: '$.text',
|
|
@@ -734,6 +964,7 @@ describe('connectors.simplerest', function () {
|
|
|
734
964
|
|
|
735
965
|
await container.Clean()
|
|
736
966
|
})
|
|
967
|
+
|
|
737
968
|
it('should not ignore empty response with hook NLP data', async function () {
|
|
738
969
|
const myCaps = Object.assign({}, myCapsGet, {
|
|
739
970
|
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: '$.text',
|
|
@@ -757,6 +988,7 @@ describe('connectors.simplerest', function () {
|
|
|
757
988
|
|
|
758
989
|
await container.Clean()
|
|
759
990
|
})
|
|
991
|
+
|
|
760
992
|
it('should not ignore empty response with custom hook data', async function () {
|
|
761
993
|
const myCaps = Object.assign({}, myCapsGet, {
|
|
762
994
|
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: '$.text',
|
|
@@ -780,6 +1012,7 @@ describe('connectors.simplerest', function () {
|
|
|
780
1012
|
|
|
781
1013
|
await container.Clean()
|
|
782
1014
|
})
|
|
1015
|
+
|
|
783
1016
|
it('should not ignore empty response with messageText filled in response hook', async function () {
|
|
784
1017
|
const myCaps = Object.assign({}, myCapsGet, {
|
|
785
1018
|
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: '$.text',
|
|
@@ -802,6 +1035,7 @@ describe('connectors.simplerest', function () {
|
|
|
802
1035
|
|
|
803
1036
|
await container.Clean()
|
|
804
1037
|
})
|
|
1038
|
+
|
|
805
1039
|
it('should process multiple responses', async function () {
|
|
806
1040
|
const myCaps = Object.assign({}, myCapsGet, {
|
|
807
1041
|
[Capabilities.SIMPLEREST_BODY_JSONPATH]: '$.responses[*]',
|
|
@@ -841,6 +1075,7 @@ describe('connectors.simplerest', function () {
|
|
|
841
1075
|
|
|
842
1076
|
await container.Clean()
|
|
843
1077
|
})
|
|
1078
|
+
|
|
844
1079
|
it('should process card responses', async function () {
|
|
845
1080
|
const myCaps = Object.assign({}, myCapsGet, {
|
|
846
1081
|
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: '$.text',
|
|
@@ -913,6 +1148,7 @@ describe('connectors.simplerest', function () {
|
|
|
913
1148
|
|
|
914
1149
|
await container.Clean()
|
|
915
1150
|
})
|
|
1151
|
+
|
|
916
1152
|
it('should process button responses', async function () {
|
|
917
1153
|
const myCaps = Object.assign({}, myCapsGet, {
|
|
918
1154
|
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: '$.text',
|
|
@@ -955,6 +1191,7 @@ describe('connectors.simplerest', function () {
|
|
|
955
1191
|
await container.Clean()
|
|
956
1192
|
})
|
|
957
1193
|
})
|
|
1194
|
+
|
|
958
1195
|
describe('parseCapabilities', function () {
|
|
959
1196
|
it('should get multiple cap values from array', async function () {
|
|
960
1197
|
const values = getAllCapValues(Capabilities.SIMPLEREST_RESPONSE_JSONPATH, {
|
|
@@ -966,6 +1203,7 @@ describe('connectors.simplerest', function () {
|
|
|
966
1203
|
assert.lengthOf(values, 2)
|
|
967
1204
|
assert.deepEqual(values, ['$.1', '$.2'])
|
|
968
1205
|
})
|
|
1206
|
+
|
|
969
1207
|
it('should get multiple cap values from splitted string', async function () {
|
|
970
1208
|
const values = getAllCapValues(Capabilities.SIMPLEREST_RESPONSE_JSONPATH, {
|
|
971
1209
|
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: () => '$.1,$.2'
|
|
@@ -973,6 +1211,7 @@ describe('connectors.simplerest', function () {
|
|
|
973
1211
|
assert.lengthOf(values, 2)
|
|
974
1212
|
assert.deepEqual(values, ['$.1', '$.2'])
|
|
975
1213
|
})
|
|
1214
|
+
|
|
976
1215
|
it('should get multiple cap values from multiple string keys', async function () {
|
|
977
1216
|
const values = getAllCapValues(Capabilities.SIMPLEREST_RESPONSE_JSONPATH, {
|
|
978
1217
|
SIMPLEREST_RESPONSE_JSONPATH_0: '$.1,$.2',
|
|
@@ -981,6 +1220,7 @@ describe('connectors.simplerest', function () {
|
|
|
981
1220
|
assert.lengthOf(values, 4)
|
|
982
1221
|
assert.deepEqual(values, ['$.1', '$.2', '$.3', '$.4'])
|
|
983
1222
|
})
|
|
1223
|
+
|
|
984
1224
|
it('should get multiple cap values from mixed keys', async function () {
|
|
985
1225
|
const values = getAllCapValues(Capabilities.SIMPLEREST_RESPONSE_JSONPATH, {
|
|
986
1226
|
SIMPLEREST_RESPONSE_JSONPATH_0: [
|
|
@@ -993,7 +1233,8 @@ describe('connectors.simplerest', function () {
|
|
|
993
1233
|
assert.deepEqual(values, ['$.1', '$.2', '$.3', '$.4'])
|
|
994
1234
|
})
|
|
995
1235
|
})
|
|
996
|
-
|
|
1236
|
+
|
|
1237
|
+
describe('userresponse', function () {
|
|
997
1238
|
beforeEach(async function () {
|
|
998
1239
|
this.init = async (caps) => {
|
|
999
1240
|
this.scope = nock('https://mock.com')
|
|
@@ -1021,6 +1262,7 @@ describe('connectors.simplerest', function () {
|
|
|
1021
1262
|
await this.container.Start()
|
|
1022
1263
|
}
|
|
1023
1264
|
})
|
|
1265
|
+
|
|
1024
1266
|
afterEach(async function () {
|
|
1025
1267
|
await this.container.Stop()
|
|
1026
1268
|
await this.container.Clean()
|
|
@@ -1146,6 +1388,7 @@ describe('connectors.simplerest', function () {
|
|
|
1146
1388
|
}
|
|
1147
1389
|
})
|
|
1148
1390
|
})
|
|
1391
|
+
|
|
1149
1392
|
describe('inbound', function () {
|
|
1150
1393
|
it('should accept inbound message with matching jsonpath', async function () {
|
|
1151
1394
|
const myCaps = Object.assign({}, myCapsGet)
|
|
@@ -1183,6 +1426,7 @@ describe('connectors.simplerest', function () {
|
|
|
1183
1426
|
|
|
1184
1427
|
return result
|
|
1185
1428
|
})
|
|
1429
|
+
|
|
1186
1430
|
it('should reorder multiple inbound message with order jsonpath', async function () {
|
|
1187
1431
|
const myCaps = Object.assign({}, myCapsGet)
|
|
1188
1432
|
myCaps[Capabilities.SIMPLEREST_RESPONSE_JSONPATH] = '$.text'
|
|
@@ -1243,6 +1487,7 @@ describe('connectors.simplerest', function () {
|
|
|
1243
1487
|
return result
|
|
1244
1488
|
})
|
|
1245
1489
|
})
|
|
1490
|
+
|
|
1246
1491
|
describe('polling', function () {
|
|
1247
1492
|
it('should poll HTTP url', async function () {
|
|
1248
1493
|
const caps = {
|
|
@@ -1306,6 +1551,7 @@ describe('connectors.simplerest', function () {
|
|
|
1306
1551
|
scope.persist(false)
|
|
1307
1552
|
}).timeout(5000)
|
|
1308
1553
|
})
|
|
1554
|
+
|
|
1309
1555
|
describe('flow', function () {
|
|
1310
1556
|
it('should ignore matching message', async function () {
|
|
1311
1557
|
const caps = {
|
|
@@ -1334,6 +1580,7 @@ describe('connectors.simplerest', function () {
|
|
|
1334
1580
|
await container.Clean()
|
|
1335
1581
|
scope.persist(false)
|
|
1336
1582
|
})
|
|
1583
|
+
|
|
1337
1584
|
it('should skip matching message', async function () {
|
|
1338
1585
|
const caps = {
|
|
1339
1586
|
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
@@ -1358,6 +1605,7 @@ describe('connectors.simplerest', function () {
|
|
|
1358
1605
|
await container.Clean()
|
|
1359
1606
|
scope.persist(false)
|
|
1360
1607
|
})
|
|
1608
|
+
|
|
1361
1609
|
it('should continue on matching message', async function () {
|
|
1362
1610
|
const caps = {
|
|
1363
1611
|
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
@@ -103,13 +103,11 @@ describe('customhooks.hookfromsrc', function () {
|
|
|
103
103
|
|
|
104
104
|
const { container } = await buildDriver({
|
|
105
105
|
[Capabilities.CUSTOMHOOK_ONSTART]: async ({ container, request }) => {
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
return fetch('https://gettoken.com/get')
|
|
107
|
+
.then(response => response.json())
|
|
108
|
+
.then(body => {
|
|
109
109
|
container.caps.MYTOKEN = body.token
|
|
110
|
-
resolve()
|
|
111
110
|
})
|
|
112
|
-
})
|
|
113
111
|
}
|
|
114
112
|
})
|
|
115
113
|
await container.Start()
|