botium-core 1.12.5 → 1.13.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.
Files changed (29) hide show
  1. package/dist/botium-cjs.js +277 -171
  2. package/dist/botium-cjs.js.map +1 -1
  3. package/dist/botium-es.js +296 -190
  4. package/dist/botium-es.js.map +1 -1
  5. package/package.json +24 -24
  6. package/src/Capabilities.js +7 -0
  7. package/src/helpers/RetryHelper.js +13 -7
  8. package/src/scripting/CompilerCsv.js +150 -102
  9. package/src/scripting/Convo.js +21 -1
  10. package/src/scripting/ScriptingProvider.js +5 -1
  11. package/src/scripting/helper.js +19 -12
  12. package/src/scripting/logichook/LogicHookUtils.js +1 -1
  13. package/src/scripting/logichook/asserter/ButtonsAsserter.js +4 -2
  14. package/src/scripting/logichook/asserter/CardsAsserter.js +4 -2
  15. package/test/compiler/compilercsv.spec.js +363 -12
  16. package/test/compiler/compilertxt.spec.js +13 -0
  17. package/test/compiler/convos/csv/utterances_liveperson.csv +108 -0
  18. package/test/compiler/convos/csv/utterances_multicolumn3col.csv +3 -0
  19. package/test/compiler/convos/csv/utterances_multicolumn5col.csv +3 -0
  20. package/test/compiler/convos/csv/utterances_singlecolumn.csv +3 -0
  21. package/test/compiler/convos/csv/utterances_variable_row_len.csv +3 -0
  22. package/test/compiler/convos/txt/convos_args_escape.convo.txt +2 -0
  23. package/test/convo/convos/continuefailing_timeout.convo.txt +16 -0
  24. package/test/convo/retryconvo.spec.js +134 -0
  25. package/test/convo/transcript.spec.js +18 -1
  26. package/test/logichooks/hookfromsrc.spec.js +1 -1
  27. package/test/scripting/asserters/buttonsAsserter.spec.js +47 -0
  28. package/test/scripting/asserters/cardsAsserter.spec.js +39 -0
  29. package/test/scripting/txt/decompile.spec.js +24 -0
@@ -0,0 +1,3 @@
1
+ singlecolumn
2
+ hello
3
+ hi
@@ -0,0 +1,3 @@
1
+ variable_row_len,goodbye, sdf, sdf, sdf,
2
+ hello,goodbye
3
+ hi,,sd,fs d,f ,sdf ,ds, fsd,f ,sdf, sd,f sd, f,sd f,
@@ -0,0 +1,2 @@
1
+ #bot
2
+ BUTTONS Test\|1|Test\|2
@@ -0,0 +1,16 @@
1
+ continuefailing
2
+
3
+ #me
4
+ Hello
5
+
6
+ #bot
7
+ Hello
8
+
9
+ #me
10
+ Hello again!
11
+
12
+ #bot
13
+ Hello again FAILING!
14
+
15
+ #bot
16
+ working again
@@ -0,0 +1,134 @@
1
+ const path = require('path')
2
+ const assert = require('chai').assert
3
+ const BotDriver = require('../../').BotDriver
4
+ const Capabilities = require('../../').Capabilities
5
+
6
+ const echoConnector = (numErrors, errorText) => ({ queueBotSays }) => {
7
+ let errors = 0
8
+ return {
9
+ UserSays (msg) {
10
+ if (errors >= numErrors) {
11
+ const botMsg = { sender: 'bot', sourceData: msg.sourceData, messageText: msg.messageText }
12
+ queueBotSays(botMsg)
13
+ } else {
14
+ errors++
15
+ return Promise.reject(errorText)
16
+ }
17
+ }
18
+ }
19
+ }
20
+
21
+ describe('convo.retries', function () {
22
+ beforeEach(async function () {
23
+ this.init = async (numErrors, errorText, errorPatterns, numRetries) => {
24
+ const myCaps = {
25
+ [Capabilities.PROJECTNAME]: 'convo.retry',
26
+ [Capabilities.CONTAINERMODE]: echoConnector(numErrors, errorText),
27
+ RETRY_CONVO_MINTIMEOUT: 10,
28
+ RETRY_CONVO_ONERROR_REGEXP: errorPatterns
29
+ }
30
+ if (!isNaN(numRetries)) {
31
+ myCaps.RETRY_CONVO_NUMRETRIES = numRetries
32
+ }
33
+ this.driver = new BotDriver(myCaps)
34
+ this.compiler = this.driver.BuildCompiler()
35
+ this.container = await this.driver.Build()
36
+ await this.container.Start()
37
+ }
38
+ })
39
+ afterEach(async function () {
40
+ await this.container.Stop()
41
+ await this.container.Clean()
42
+ })
43
+
44
+ it('should fail without retry', async function () {
45
+ await this.init(1, 'myerror')
46
+
47
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
48
+ try {
49
+ await this.compiler.convos[0].Run(this.container)
50
+ } catch (err) {
51
+ assert.isTrue(err.message.indexOf('myerror') >= 0)
52
+ return
53
+ }
54
+ assert.fail('should have failed without retry')
55
+ })
56
+ it('should succeed after one retry with default numRetries', async function () {
57
+ await this.init(1, 'myerror', 'myerror')
58
+
59
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
60
+ await this.compiler.convos[0].Run(this.container)
61
+ })
62
+ it('should succeed after one retry with joker regex', async function () {
63
+ await this.init(1, 'myerror', null, 1)
64
+
65
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
66
+ await this.compiler.convos[0].Run(this.container)
67
+ })
68
+ it('should fail after one retry with default settings', async function () {
69
+ await this.init(2, 'myerror', 'myerror')
70
+
71
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
72
+ try {
73
+ await this.compiler.convos[0].Run(this.container)
74
+ } catch (err) {
75
+ assert.isTrue(err.message.indexOf('myerror') >= 0)
76
+ return
77
+ }
78
+ assert.fail('should have failed after first retry')
79
+ })
80
+ it('should succeed after many retries', async function () {
81
+ await this.init(5, 'myerror', 'myerror', 5)
82
+
83
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
84
+ await this.compiler.convos[0].Run(this.container)
85
+ })
86
+ it('should succeed after too less retries', async function () {
87
+ await this.init(5, 'myerror', 'myerror', 4)
88
+
89
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
90
+ try {
91
+ await this.compiler.convos[0].Run(this.container)
92
+ } catch (err) {
93
+ assert.isTrue(err.message.indexOf('myerror') >= 0)
94
+ return
95
+ }
96
+ assert.fail('should have failed after four retries')
97
+ })
98
+ it('should succeed after one retry with regexp pattern', async function () {
99
+ await this.init(1, 'myerror', /myeRRor/i)
100
+
101
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
102
+ await this.compiler.convos[0].Run(this.container)
103
+ })
104
+ it('should fail after one retry with unmatched regexp pattern', async function () {
105
+ await this.init(1, 'myerror', /myeRRor1/i)
106
+
107
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
108
+ try {
109
+ await this.compiler.convos[0].Run(this.container)
110
+ } catch (err) {
111
+ assert.isTrue(err.message.indexOf('myerror') >= 0)
112
+ return
113
+ }
114
+ assert.fail('should have failed with unmatched retry pattern')
115
+ })
116
+ it('should succeed after one retry with regexp pattern array', async function () {
117
+ await this.init(1, 'myerror', [/myeRRor/i, /myeRRor1/i])
118
+
119
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
120
+ await this.compiler.convos[0].Run(this.container)
121
+ })
122
+ it('should fail after one retry with unmatched regexp pattern array', async function () {
123
+ await this.init(1, 'myerror', [/myeRRor1/i, /myeRRor2/i])
124
+
125
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
126
+ try {
127
+ await this.compiler.convos[0].Run(this.container)
128
+ } catch (err) {
129
+ assert.isTrue(err.message.indexOf('myerror') >= 0)
130
+ return
131
+ }
132
+ assert.fail('should have failed with unmatched retry pattern')
133
+ })
134
+ })
@@ -47,7 +47,8 @@ describe('convo.transcript', function () {
47
47
  [Capabilities.PROJECTNAME]: 'convo.transcript',
48
48
  [Capabilities.CONTAINERMODE]: echoConnector,
49
49
  [Capabilities.SCRIPTING_ENABLE_MULTIPLE_ASSERT_ERRORS]: true,
50
- [Capabilities.SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS]: true
50
+ [Capabilities.SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS]: true,
51
+ [Capabilities.WAITFORBOTTIMEOUT]: 500
51
52
  }
52
53
  this.driverSkipAssertErrors = new BotDriver(myCapsSkipAssertErrors)
53
54
  this.compilerSkipAssertErrors = this.driverSkipAssertErrors.BuildCompiler()
@@ -381,4 +382,20 @@ describe('convo.transcript', function () {
381
382
  assert.isNull(err.transcript.steps[5].err)
382
383
  }
383
384
  })
385
+ it('should continue on failing assertion with timeout', async function () {
386
+ this.compilerSkipAssertErrors.ReadScript(path.resolve(__dirname, 'convos'), 'continuefailing_timeout.convo.txt')
387
+ assert.equal(this.compilerSkipAssertErrors.convos.length, 1)
388
+
389
+ try {
390
+ await this.compilerSkipAssertErrors.convos[0].Run(this.containerSkipAssertErrors)
391
+ assert.fail('expected error')
392
+ } catch (err) {
393
+ assert.isDefined(err.cause)
394
+ assert.equal(err.cause.message, 'continuefailing/Line 12: Bot response (on Line 9: #me - Hello again!) "Hello again!" expected to match "Hello again FAILING!",\ncontinuefailing/Line 15: error waiting for bot - Bot did not respond within 500ms')
395
+ assert.equal(err.cause.context.errors.length, 2)
396
+
397
+ assert.isDefined(err.transcript)
398
+ assert.equal(err.transcript.steps.length, 5)
399
+ }
400
+ })
384
401
  })
@@ -69,7 +69,7 @@ describe('logichooks.hookfromsrc', function () {
69
69
  await compiler.convos[0].Run(container)
70
70
  assert.fail('it should have failed')
71
71
  } catch (err) {
72
- assert.isTrue(err.message.includes('Line 6: assertion error - Unexpected end of input'))
72
+ assert.isTrue(err.message.includes('Line 6: assertion error - Script assertConvoStep is not valid'))
73
73
  }
74
74
  })
75
75
  })
@@ -263,3 +263,50 @@ describe('scripting.asserters.buttonsCountAsserter', function () {
263
263
  })
264
264
  })
265
265
  })
266
+
267
+ describe('scripting.asserters.buttonsNormalizeAsserter', function () {
268
+ beforeEach(async function () {
269
+ this.cardsAsserter = new ButtonsAsserter({
270
+ Match: (botresponse, utterance) => botresponse.toLowerCase().indexOf(utterance.toLowerCase()) >= 0
271
+ }, { SCRIPTING_NORMALIZE_TEXT: true })
272
+ })
273
+
274
+ it('should succeed with normalized text', async function () {
275
+ await this.cardsAsserter.assertConvoStep({
276
+ convoStep: { stepTag: 'test' },
277
+ args: ['Test Html header test html text'],
278
+ botMsg: {
279
+ buttons: [
280
+ {
281
+ text: '<html><h1>test html header</h1><p>test html text</p>'
282
+ }
283
+ ]
284
+ }
285
+ })
286
+ })
287
+
288
+ it('should fail with normalized text', async function () {
289
+ try {
290
+ await this.cardsAsserter.assertConvoStep({
291
+ convoStep: { stepTag: 'test' },
292
+ args: ['Test Html header1 test html text'],
293
+ botMsg: {
294
+ buttons: [
295
+ {
296
+ text: '<html><h1>test html header</h1><p>test html text</p>'
297
+ }
298
+ ]
299
+ }
300
+ })
301
+ assert.fail('should have failed')
302
+ } catch (err) {
303
+ assert.isTrue(err.message.indexOf('Expected button(s) with text "Test Html header1 test html text"') > 0)
304
+ assert.isNotNull(err.context)
305
+ assert.isNotNull(err.context.cause)
306
+ assert.isArray(err.context.cause.expected)
307
+ assert.deepEqual(err.context.cause.expected, ['Test Html header1 test html text'])
308
+ assert.deepEqual(err.context.cause.actual, ['test html header test html text'])
309
+ assert.deepEqual(err.context.cause.diff, ['Test Html header1 test html text'])
310
+ }
311
+ })
312
+ })
@@ -243,3 +243,42 @@ describe('scripting.asserters.cardsCountAsserter', function () {
243
243
  })
244
244
  })
245
245
  })
246
+
247
+ describe('scripting.asserters.cardsNormalizeAsserter', function () {
248
+ beforeEach(async function () {
249
+ this.cardsAsserter = new CardsAsserter({
250
+ Match: (botresponse, utterance) => botresponse.toLowerCase().indexOf(utterance.toLowerCase()) >= 0
251
+ }, { SCRIPTING_NORMALIZE_TEXT: true })
252
+ })
253
+
254
+ it('should succeed with normalized text', async function () {
255
+ await this.cardsAsserter.assertConvoStep({
256
+ convoStep: { stepTag: 'test' },
257
+ args: ['Test Html header test html text'],
258
+ botMsg: {
259
+ cards: [{ text: '<html><h1>test html header</h1><p>test html text</p>' }]
260
+ }
261
+ })
262
+ })
263
+
264
+ it('should fail with normalized text', async function () {
265
+ try {
266
+ await this.cardsAsserter.assertConvoStep({
267
+ convoStep: { stepTag: 'test' },
268
+ args: ['Test Html header1 test html text'],
269
+ botMsg: {
270
+ cards: [{ text: '<html><h1>test html header</h1><p>test html text</p>' }]
271
+ }
272
+ })
273
+ assert.fail('should have failed')
274
+ } catch (err) {
275
+ assert.isTrue(err.message.indexOf('Expected card(s) with text "Test Html header1 test html text"') > 0)
276
+ assert.isNotNull(err.context)
277
+ assert.isNotNull(err.context.cause)
278
+ assert.isArray(err.context.cause.expected)
279
+ assert.deepEqual(err.context.cause.expected, ['Test Html header1 test html text'])
280
+ assert.deepEqual(err.context.cause.actual, ['test html header test html text'])
281
+ assert.deepEqual(err.context.cause.diff, ['Test Html header1 test html text'])
282
+ }
283
+ })
284
+ })
@@ -634,6 +634,30 @@ CARDS text of card2
634
634
  #me
635
635
  some text
636
636
  CUSTOMINPUT arg1|arg2
637
+ `
638
+ )
639
+ })
640
+ it('should escape pipe in args', async function () {
641
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
642
+ await scriptingProvider.Build()
643
+
644
+ const convo = {
645
+ header: {
646
+ name: 'test convo'
647
+ },
648
+ conversation: [
649
+ {
650
+ sender: 'me',
651
+ userInputs: [{ name: 'CUSTOMINPUT', args: ['arg|1', 'arg|2'] }]
652
+ }
653
+ ]
654
+ }
655
+
656
+ const script = scriptingProvider.Decompile([convo], 'SCRIPTING_FORMAT_TXT')
657
+ assert.equal(script, `test convo
658
+
659
+ #me
660
+ CUSTOMINPUT arg\\|1|arg\\|2
637
661
  `
638
662
  )
639
663
  })