botium-core 1.13.0 → 1.13.3

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 (57) hide show
  1. package/.eslintrc.js +6 -3
  2. package/dist/botium-cjs.js +305 -123
  3. package/dist/botium-cjs.js.map +1 -1
  4. package/dist/botium-es.js +323 -142
  5. package/dist/botium-es.js.map +1 -1
  6. package/package.json +17 -15
  7. package/src/Capabilities.js +2 -1
  8. package/src/containers/plugins/SimpleRestContainer.js +23 -16
  9. package/src/grid/inbound/proxy.js +2 -1
  10. package/src/helpers/RetryHelper.js +13 -7
  11. package/src/scripting/Convo.js +36 -10
  12. package/src/scripting/MatchFunctions.js +10 -0
  13. package/src/scripting/ScriptingProvider.js +106 -37
  14. package/src/scripting/logichook/LogicHookConsts.js +1 -1
  15. package/src/scripting/logichook/LogicHookUtils.js +1 -1
  16. package/src/scripting/logichook/asserter/WerAsserter.js +59 -0
  17. package/src/scripting/logichook/logichooks/UpdateCustomLogicHook.js +3 -2
  18. package/test/compiler/compilercsv.spec.js +104 -3
  19. package/test/compiler/compilerjson.spec.js +0 -2
  20. package/test/compiler/compilerxlsx.spec.js +1 -1
  21. package/test/compiler/convos/csv/utterances_liveperson2.csv +12 -0
  22. package/test/connectors/simplerest.spec.js +1012 -969
  23. package/test/convo/fillAndApplyScriptingMemory.spec.js +804 -785
  24. package/test/convo/partialconvo.spec.js +345 -339
  25. package/test/convo/retryconvo.spec.js +134 -0
  26. package/test/driver/capabilities.spec.js +156 -151
  27. package/test/logichooks/hookfromsrc.spec.js +79 -73
  28. package/test/plugins/plugins.spec.js +44 -42
  29. package/test/scripting/asserters/buttonsAsserter.spec.js +257 -240
  30. package/test/scripting/asserters/cardsAsserter.spec.js +214 -212
  31. package/test/scripting/asserters/convos/wer_threshold_nok.yml +7 -0
  32. package/test/scripting/asserters/convos/wer_threshold_ok.yml +7 -0
  33. package/test/scripting/asserters/intentConfidenceAsserter.spec.js +34 -35
  34. package/test/scripting/asserters/jsonpathAsserter.spec.js +307 -308
  35. package/test/scripting/asserters/mediaAsserter.spec.js +236 -234
  36. package/test/scripting/asserters/werAsserter.spec.js +51 -0
  37. package/test/scripting/logichooks/setClearScriptingMemory.spec.js +202 -192
  38. package/test/scripting/matching/matchingmode.spec.js +306 -258
  39. package/test/scripting/scriptingProvider.spec.js +666 -633
  40. package/test/scripting/scriptingmemory/fillScriptingMemoryFromFile.spec.js +299 -281
  41. package/test/scripting/scriptingmemory/useScriptingMemoryForAssertion.spec.js +94 -80
  42. package/test/scripting/userinputs/defaultUserInputs.spec.js +233 -127
  43. package/test/scripting/userinputs/mediaInputConvos.spec.js +409 -403
  44. package/test/scripting/utteranceexpansion/associateByIndex.spec.js +259 -0
  45. package/test/scripting/utteranceexpansion/convos/associate_utterances_by_index.json +33 -0
  46. package/test/scripting/utteranceexpansion/convos/media.convo.txt +19 -0
  47. package/test/scripting/utteranceexpansion/files/step0voice0.wav +0 -0
  48. package/test/scripting/utteranceexpansion/files/step0voice1.wav +0 -0
  49. package/test/scripting/utteranceexpansion/files/step0voice2.wav +0 -0
  50. package/test/scripting/utteranceexpansion/files/step1voice0.wav +0 -0
  51. package/test/scripting/utteranceexpansion/files/step2voice0.wav +0 -0
  52. package/test/scripting/utteranceexpansion/files/step2voice1.wav +0 -0
  53. package/test/scripting/utteranceexpansion/files/step2voice2.wav +0 -0
  54. package/test/scripting/utteranceexpansion/files/step2voice4.wav +0 -0
  55. package/test/scripting/utteranceexpansion/files/step2voice5.wav +0 -0
  56. package/test/security/allowUnsafe.spec.js +274 -268
  57. package/test/utils.spec.js +40 -38
@@ -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
+ })
@@ -3,162 +3,167 @@ const BotDriver = require('../../').BotDriver
3
3
  const Capabilities = require('../../').Capabilities
4
4
  const DefaultCapabilities = require('../../src/Defaults').Capabilities
5
5
 
6
- describe('driver.fetchConfigFromFiles', function () {
7
- it('fetch capabilities from files', function () {
8
- const driver = new BotDriver()
9
- const result = driver._fetchConfigFromFiles(['test/driver/configFiles/config1.json'])
10
- assert.isArray(result)
11
- assert.lengthOf(result, 1)
12
- })
13
- it('fetch capabilities from non existing files', function () {
14
- const driver = new BotDriver()
15
- const result = driver._fetchConfigFromFiles(['test/driver/configFiles/configNotExists.json'])
16
- assert.isArray(result)
17
- assert.lengthOf(result, 0)
18
- })
19
- it('fetch capabilities from multiple files', function () {
20
- const driver = new BotDriver()
21
- const result = driver._fetchConfigFromFiles(['test/driver/configFiles/config1.json', 'test/driver/configFiles/config2.json'])
22
- assert.isArray(result)
23
- assert.lengthOf(result, 2)
24
- })
25
- it('fetch capabilities from multiple files and check if overwritten', function () {
26
- const driver = new BotDriver()
27
- driver._fetchConfigFromFiles(['test/driver/configFiles/config1.json', 'test/driver/configFiles/config2.json'])
28
- assert.equal(driver.caps.PROJECTNAME, 'Botium Example 2')
29
- assert.equal(driver.sources.GITURL, 'https://github.com/codeforequity-at/botium-bindings')
30
- assert.equal(driver.envs.IS_BOTIUM_CONTAINER, true)
6
+ describe('driver.capabilities', function () {
7
+ describe('fetchConfigFromFiles', function () {
8
+ it('fetch capabilities from files', function () {
9
+ const driver = new BotDriver()
10
+ const result = driver._fetchConfigFromFiles(['test/driver/configFiles/config1.json'])
11
+ assert.isArray(result)
12
+ assert.lengthOf(result, 1)
13
+ })
14
+ it('fetch capabilities from non existing files', function () {
15
+ const driver = new BotDriver()
16
+ const result = driver._fetchConfigFromFiles(['test/driver/configFiles/configNotExists.json'])
17
+ assert.isArray(result)
18
+ assert.lengthOf(result, 0)
19
+ })
20
+ it('fetch capabilities from multiple files', function () {
21
+ const driver = new BotDriver()
22
+ const result = driver._fetchConfigFromFiles(['test/driver/configFiles/config1.json', 'test/driver/configFiles/config2.json'])
23
+ assert.isArray(result)
24
+ assert.lengthOf(result, 2)
25
+ })
26
+ it('fetch capabilities from multiple files and check if overwritten', function () {
27
+ const driver = new BotDriver()
28
+ driver._fetchConfigFromFiles(['test/driver/configFiles/config1.json', 'test/driver/configFiles/config2.json'])
29
+ assert.equal(driver.caps.PROJECTNAME, 'Botium Example 2')
30
+ assert.equal(driver.sources.GITURL, 'https://github.com/codeforequity-at/botium-bindings')
31
+ assert.equal(driver.envs.IS_BOTIUM_CONTAINER, true)
32
+ })
31
33
  })
32
- })
33
34
 
34
- describe('driver.loadConfigFile', function () {
35
- it('load Config from file', function () {
36
- const driver = new BotDriver()
37
- const result = driver._loadConfigFile('test/driver/configFiles/config1.json')
38
- assert.isTrue(result)
35
+ describe('loadConfigFile', function () {
36
+ it('load Config from file', function () {
37
+ const driver = new BotDriver()
38
+ const result = driver._loadConfigFile('test/driver/configFiles/config1.json')
39
+ assert.isTrue(result)
40
+ })
41
+ it('load Config from non existing file', function () {
42
+ const driver = new BotDriver()
43
+ assert.throws(() => driver._loadConfigFile('test/driver/configFiles/configNonExisting.json'))
44
+ })
45
+ it('load Config from file only once', function () {
46
+ const driver = new BotDriver()
47
+ driver._fetchConfigFromFiles(['test/driver/configFiles/config1.json', 'test/driver/configFiles/config1.json', 'test/driver/configFiles/config1.json'])
48
+ assert.lengthOf(driver._fetchedConfigFiles, 1)
49
+ assert.lengthOf(driver.caps.ARR_CAP, 2)
50
+ })
51
+ it('should make unique array', function () {
52
+ const driver = new BotDriver()
53
+ driver._fetchConfigFromFiles(['test/driver/configFiles/config1.json', 'test/driver/configFiles/config2.json'])
54
+ assert.lengthOf(driver._fetchedConfigFiles, 2)
55
+ assert.lengthOf(driver.caps.ARR_CAP, 3)
56
+ assert.deepEqual(driver.caps.ARR_CAP, ['val1', 'val2', 'val3'])
57
+ })
39
58
  })
40
- it('load Config from non existing file', function () {
41
- const driver = new BotDriver()
42
- assert.throws(() => driver._loadConfigFile('test/driver/configFiles/configNonExisting.json'))
43
- })
44
- it('load Config from file only once', function () {
45
- const driver = new BotDriver()
46
- driver._fetchConfigFromFiles(['test/driver/configFiles/config1.json', 'test/driver/configFiles/config1.json', 'test/driver/configFiles/config1.json'])
47
- assert.lengthOf(driver._fetchedConfigFiles, 1)
48
- assert.lengthOf(driver.caps.ARR_CAP, 2)
49
- })
50
- it('should make unique array', function () {
51
- const driver = new BotDriver()
52
- driver._fetchConfigFromFiles(['test/driver/configFiles/config1.json', 'test/driver/configFiles/config2.json'])
53
- assert.lengthOf(driver._fetchedConfigFiles, 2)
54
- assert.lengthOf(driver.caps.ARR_CAP, 3)
55
- assert.deepEqual(driver.caps.ARR_CAP, ['val1', 'val2', 'val3'])
56
- })
57
- })
58
59
 
59
- describe('driver.capabilities', function () {
60
- it('should merge boolean caps', function () {
61
- const myCaps = {
62
- [Capabilities.SIMULATE_WRITING_SPEED]: 'YES'
63
- }
64
- const driver = new BotDriver(myCaps)
65
- assert.isBoolean(driver.caps[Capabilities.SIMULATE_WRITING_SPEED])
66
- assert.isTrue(driver.caps[Capabilities.SIMULATE_WRITING_SPEED])
60
+ describe('capabilities', function () {
61
+ it('should merge boolean caps', function () {
62
+ const myCaps = {
63
+ [Capabilities.SIMULATE_WRITING_SPEED]: 'YES'
64
+ }
65
+ const driver = new BotDriver(myCaps)
66
+ assert.isBoolean(driver.caps[Capabilities.SIMULATE_WRITING_SPEED])
67
+ assert.isTrue(driver.caps[Capabilities.SIMULATE_WRITING_SPEED])
68
+ })
69
+ it('should merge string caps', function () {
70
+ const myCaps = {
71
+ CAP_STRING_1: 'Test',
72
+ CAP_STRING_2: '12345'
73
+ }
74
+ const driver = new BotDriver(myCaps)
75
+ assert.isString(driver.caps.CAP_STRING_1)
76
+ assert.isString(driver.caps.CAP_STRING_2)
77
+ })
78
+ it('should merge boolean envs', function () {
79
+ process.env.BOTIUM_SIMULATE_WRITING_SPEED = 'NO'
80
+ const driver = new BotDriver()
81
+ delete process.env.BOTIUM_SIMULATE_WRITING_SPEED
82
+ assert.isBoolean(driver.caps[Capabilities.SIMULATE_WRITING_SPEED])
83
+ assert.isFalse(driver.caps[Capabilities.SIMULATE_WRITING_SPEED])
84
+ })
85
+ it('should parse array caps', function () {
86
+ DefaultCapabilities.MYCAP = []
87
+ const myCaps = {
88
+ MYCAP: '[{"KEY":"VALUE"},{"KEY":"VALUE1"}]'
89
+ }
90
+ const driver = new BotDriver(myCaps)
91
+ assert.isArray(driver.caps.MYCAP)
92
+ assert.lengthOf(driver.caps.MYCAP, 2)
93
+ })
94
+ it('should merge array caps', function () {
95
+ DefaultCapabilities.MYCAP = [{
96
+ id: 'id1',
97
+ key: 'VALUE'
98
+ }]
99
+ const myCaps = {
100
+ MYCAP: '[{"id":"id1", "key1": "VALUE1"},{"key":"VALUE1"}]'
101
+ }
102
+ const driver = new BotDriver(myCaps)
103
+ assert.isArray(driver.caps.MYCAP)
104
+ assert.lengthOf(driver.caps.MYCAP, 2)
105
+ assert.equal(driver.caps.MYCAP[0].key, 'VALUE')
106
+ assert.equal(driver.caps.MYCAP[0].key1, 'VALUE1')
107
+ assert.isUndefined(driver.caps.MYCAP[1].id)
108
+ assert.equal(driver.caps.MYCAP[1].key, 'VALUE1')
109
+ })
110
+ it('should parse object caps', function () {
111
+ DefaultCapabilities.MYCAP = { KEY: 'VALUE' }
112
+ const myCaps = {
113
+ MYCAP: '{"KEY":"VALUE1"}'
114
+ }
115
+ const driver = new BotDriver(myCaps)
116
+ assert.isObject(driver.caps.MYCAP)
117
+ assert.equal(driver.caps.MYCAP.KEY, 'VALUE1')
118
+ })
119
+ it('should merge object caps', function () {
120
+ DefaultCapabilities.MYCAP = { KEY: 'VALUE' }
121
+ const myCaps = {
122
+ MYCAP: '{"KEY1":"VALUE1"}'
123
+ }
124
+ const driver = new BotDriver(myCaps)
125
+ assert.isObject(driver.caps.MYCAP)
126
+ assert.equal(driver.caps.MYCAP.KEY, 'VALUE')
127
+ assert.equal(driver.caps.MYCAP.KEY1, 'VALUE1')
128
+ })
129
+ it('should not parse JSON caps', function () {
130
+ const myCaps = {
131
+ MYJSONCAP: '{"KEY":"VALUE1"}'
132
+ }
133
+ const driver = new BotDriver(myCaps)
134
+ assert.isObject(driver.caps.MYJSONCAP)
135
+ assert.equal(driver.caps.MYJSONCAP.KEY, 'VALUE1')
136
+ })
137
+ it('should override not matching object caps', function () {
138
+ DefaultCapabilities.MYCAP = { KEY: 'VALUE' }
139
+ const myCaps = {
140
+ MYCAP: 'SIMPLESTRING'
141
+ }
142
+ const driver = new BotDriver(myCaps)
143
+ assert.isString(driver.caps.MYCAP)
144
+ assert.equal(driver.caps.MYCAP, 'SIMPLESTRING')
145
+ })
146
+ it('should override not matching array caps', function () {
147
+ DefaultCapabilities.MYCAP = ['VAL1', 'VAL2']
148
+ const myCaps = {
149
+ MYCAP: { VAL1: 'VALUE1' }
150
+ }
151
+ const driver = new BotDriver(myCaps)
152
+ assert.isObject(driver.caps.MYCAP)
153
+ assert.equal(driver.caps.MYCAP.VAL1, 'VALUE1')
154
+ })
67
155
  })
68
- it('should merge string caps', function () {
69
- const myCaps = {
70
- CAP_STRING_1: 'Test',
71
- CAP_STRING_2: '12345'
72
- }
73
- const driver = new BotDriver(myCaps)
74
- assert.isString(driver.caps.CAP_STRING_1)
75
- assert.isString(driver.caps.CAP_STRING_2)
76
- })
77
- it('should merge boolean envs', function () {
78
- process.env.BOTIUM_SIMULATE_WRITING_SPEED = 'NO'
79
- const driver = new BotDriver()
80
- delete process.env.BOTIUM_SIMULATE_WRITING_SPEED
81
- assert.isBoolean(driver.caps[Capabilities.SIMULATE_WRITING_SPEED])
82
- assert.isFalse(driver.caps[Capabilities.SIMULATE_WRITING_SPEED])
83
- })
84
- it('should parse array caps', function () {
85
- DefaultCapabilities.MYCAP = []
86
- const myCaps = {
87
- MYCAP: '[{"KEY":"VALUE"},{"KEY":"VALUE1"}]'
88
- }
89
- const driver = new BotDriver(myCaps)
90
- assert.isArray(driver.caps.MYCAP)
91
- assert.lengthOf(driver.caps.MYCAP, 2)
92
- })
93
- it('should merge array caps', function () {
94
- DefaultCapabilities.MYCAP = [{ id: 'id1', key: 'VALUE' }]
95
- const myCaps = {
96
- MYCAP: '[{"id":"id1", "key1": "VALUE1"},{"key":"VALUE1"}]'
97
- }
98
- const driver = new BotDriver(myCaps)
99
- assert.isArray(driver.caps.MYCAP)
100
- assert.lengthOf(driver.caps.MYCAP, 2)
101
- assert.equal(driver.caps.MYCAP[0].key, 'VALUE')
102
- assert.equal(driver.caps.MYCAP[0].key1, 'VALUE1')
103
- assert.isUndefined(driver.caps.MYCAP[1].id)
104
- assert.equal(driver.caps.MYCAP[1].key, 'VALUE1')
105
- })
106
- it('should parse object caps', function () {
107
- DefaultCapabilities.MYCAP = { KEY: 'VALUE' }
108
- const myCaps = {
109
- MYCAP: '{"KEY":"VALUE1"}'
110
- }
111
- const driver = new BotDriver(myCaps)
112
- assert.isObject(driver.caps.MYCAP)
113
- assert.equal(driver.caps.MYCAP.KEY, 'VALUE1')
114
- })
115
- it('should merge object caps', function () {
116
- DefaultCapabilities.MYCAP = { KEY: 'VALUE' }
117
- const myCaps = {
118
- MYCAP: '{"KEY1":"VALUE1"}'
119
- }
120
- const driver = new BotDriver(myCaps)
121
- assert.isObject(driver.caps.MYCAP)
122
- assert.equal(driver.caps.MYCAP.KEY, 'VALUE')
123
- assert.equal(driver.caps.MYCAP.KEY1, 'VALUE1')
124
- })
125
- it('should not parse JSON caps', function () {
126
- const myCaps = {
127
- MYJSONCAP: '{"KEY":"VALUE1"}'
128
- }
129
- const driver = new BotDriver(myCaps)
130
- assert.isObject(driver.caps.MYJSONCAP)
131
- assert.equal(driver.caps.MYJSONCAP.KEY, 'VALUE1')
132
- })
133
- it('should override not matching object caps', function () {
134
- DefaultCapabilities.MYCAP = { KEY: 'VALUE' }
135
- const myCaps = {
136
- MYCAP: 'SIMPLESTRING'
137
- }
138
- const driver = new BotDriver(myCaps)
139
- assert.isString(driver.caps.MYCAP)
140
- assert.equal(driver.caps.MYCAP, 'SIMPLESTRING')
141
- })
142
- it('should override not matching array caps', function () {
143
- DefaultCapabilities.MYCAP = ['VAL1', 'VAL2']
144
- const myCaps = {
145
- MYCAP: { VAL1: 'VALUE1' }
146
- }
147
- const driver = new BotDriver(myCaps)
148
- assert.isObject(driver.caps.MYCAP)
149
- assert.equal(driver.caps.MYCAP.VAL1, 'VALUE1')
150
- })
151
- })
152
156
 
153
- describe('driver.constructor', function () {
154
- it('should deep copy caps', function () {
155
- const myCaps = {
156
- ASSERTERS: [{ name: 'ASSERTER1' }]
157
- }
158
- const driver = new BotDriver(myCaps)
159
- assert.isArray(driver.caps.ASSERTERS)
160
- assert.lengthOf(driver.caps.ASSERTERS, 1)
161
- assert.isArray(DefaultCapabilities.ASSERTERS)
162
- assert.lengthOf(DefaultCapabilities.ASSERTERS, 0)
157
+ describe('constructor', function () {
158
+ it('should deep copy caps', function () {
159
+ const myCaps = {
160
+ ASSERTERS: [{ name: 'ASSERTER1' }]
161
+ }
162
+ const driver = new BotDriver(myCaps)
163
+ assert.isArray(driver.caps.ASSERTERS)
164
+ assert.lengthOf(driver.caps.ASSERTERS, 1)
165
+ assert.isArray(DefaultCapabilities.ASSERTERS)
166
+ assert.lengthOf(DefaultCapabilities.ASSERTERS, 0)
167
+ })
163
168
  })
164
169
  })
@@ -6,7 +6,11 @@ const Capabilities = require('../../').Capabilities
6
6
  const echoConnector = ({ queueBotSays }) => {
7
7
  return {
8
8
  UserSays (msg) {
9
- const botMsg = { sender: 'bot', sourceData: msg.sourceData, messageText: msg.messageText }
9
+ const botMsg = {
10
+ sender: 'bot',
11
+ sourceData: msg.sourceData,
12
+ messageText: msg.messageText
13
+ }
10
14
  queueBotSays(botMsg)
11
15
  }
12
16
  }
@@ -26,86 +30,88 @@ const buildDriver = async (mergeCaps) => {
26
30
  }
27
31
 
28
32
  describe('logichooks.hookfromsrc', function () {
29
- it('should succeed with asserter from code', async function () {
30
- const { compiler, container } = await buildDriver({
31
- [Capabilities.ASSERTERS]: [{
32
- ref: 'CUSTOMASSERTER',
33
- src: {
34
- assertConvoStep: 'if (botMsg.messageText === "Hello") result=Promise.resolve(); else result=Promise.reject(new Error("expected Hello"))'
35
- }
36
- }]
33
+ describe('hookfromsrc', function () {
34
+ it('should succeed with asserter from code', async function () {
35
+ const { compiler, container } = await buildDriver({
36
+ [Capabilities.ASSERTERS]: [{
37
+ ref: 'CUSTOMASSERTER',
38
+ src: {
39
+ assertConvoStep: 'if (botMsg.messageText === "Hello") result=Promise.resolve(); else result=Promise.reject(new Error("expected Hello"))'
40
+ }
41
+ }]
42
+ })
43
+ compiler.ReadScript(path.resolve(__dirname, 'convos'), 'HOOKFROMSRC.convo.txt')
44
+ await compiler.convos[0].Run(container)
37
45
  })
38
- compiler.ReadScript(path.resolve(__dirname, 'convos'), 'HOOKFROMSRC.convo.txt')
39
- await compiler.convos[0].Run(container)
40
- })
41
- it('should fail with asserter from code', async function () {
42
- const { compiler, container } = await buildDriver({
43
- [Capabilities.ASSERTERS]: [{
44
- ref: 'CUSTOMASSERTER',
45
- src: {
46
- assertConvoStep: 'if (botMsg.messageText === "Hello1") module.exports=Promise.resolve(); else module.exports=Promise.reject(new Error("expected Hello1"))'
47
- }
48
- }]
46
+ it('should fail with asserter from code', async function () {
47
+ const { compiler, container } = await buildDriver({
48
+ [Capabilities.ASSERTERS]: [{
49
+ ref: 'CUSTOMASSERTER',
50
+ src: {
51
+ assertConvoStep: 'if (botMsg.messageText === "Hello1") module.exports=Promise.resolve(); else module.exports=Promise.reject(new Error("expected Hello1"))'
52
+ }
53
+ }]
54
+ })
55
+ compiler.ReadScript(path.resolve(__dirname, 'convos'), 'HOOKFROMSRC.convo.txt')
56
+ try {
57
+ await compiler.convos[0].Run(container)
58
+ assert.fail('it should have failed')
59
+ } catch (err) {
60
+ assert.isTrue(err.message.includes('Line 6: assertion error - expected Hello1'))
61
+ }
49
62
  })
50
- compiler.ReadScript(path.resolve(__dirname, 'convos'), 'HOOKFROMSRC.convo.txt')
51
- try {
52
- await compiler.convos[0].Run(container)
53
- assert.fail('it should have failed')
54
- } catch (err) {
55
- assert.isTrue(err.message.includes('Line 6: assertion error - expected Hello1'))
56
- }
57
- })
58
- it('should fail with asserter with invalid script', async function () {
59
- const { compiler, container } = await buildDriver({
60
- [Capabilities.ASSERTERS]: [{
61
- ref: 'CUSTOMASSERTER',
62
- src: {
63
- assertConvoStep: '!'
64
- }
65
- }]
63
+ it('should fail with asserter with invalid script', async function () {
64
+ const { compiler, container } = await buildDriver({
65
+ [Capabilities.ASSERTERS]: [{
66
+ ref: 'CUSTOMASSERTER',
67
+ src: {
68
+ assertConvoStep: '!'
69
+ }
70
+ }]
71
+ })
72
+ compiler.ReadScript(path.resolve(__dirname, 'convos'), 'HOOKFROMSRC.convo.txt')
73
+ try {
74
+ await compiler.convos[0].Run(container)
75
+ assert.fail('it should have failed')
76
+ } catch (err) {
77
+ assert.isTrue(err.message.includes('Line 6: assertion error - Script assertConvoStep is not valid'))
78
+ }
66
79
  })
67
- compiler.ReadScript(path.resolve(__dirname, 'convos'), 'HOOKFROMSRC.convo.txt')
68
- try {
69
- await compiler.convos[0].Run(container)
70
- assert.fail('it should have failed')
71
- } catch (err) {
72
- assert.isTrue(err.message.includes('Line 6: assertion error - Unexpected end of input'))
73
- }
74
80
  })
75
- })
76
81
 
77
- const buildDriverFromFile = async (mergeCaps) => {
78
- const myCaps = Object.assign({
79
- [Capabilities.PROJECTNAME]: 'logichooks.hookfromsrc',
80
- [Capabilities.CONTAINERMODE]: path.join(__dirname, 'botium-connector-fromfile')
81
- }, mergeCaps)
82
+ const buildDriverFromFile = async (mergeCaps) => {
83
+ const myCaps = Object.assign({
84
+ [Capabilities.PROJECTNAME]: 'logichooks.hookfromsrc',
85
+ [Capabilities.CONTAINERMODE]: path.join(__dirname, 'botium-connector-fromfile')
86
+ }, mergeCaps)
82
87
 
83
- const result = {}
84
- result.driver = new BotDriver(myCaps)
85
- result.compiler = result.driver.BuildCompiler()
86
- result.container = await result.driver.Build()
87
- return result
88
- }
88
+ const result = {}
89
+ result.driver = new BotDriver(myCaps)
90
+ result.compiler = result.driver.BuildCompiler()
91
+ result.container = await result.driver.Build()
92
+ return result
93
+ }
89
94
 
90
- describe('logichooks.hookfromconnector', function () {
91
- it('should succeed with asserter from connector', async function () {
92
- const { compiler, container } = await buildDriverFromFile({
93
- [Capabilities.ASSERTERS]: [{
94
- ref: 'CUSTOMASSERTER',
95
- src: path.join(__dirname, 'botium-connector-fromfile.js/MyCustomAsserter')
96
- }]
95
+ describe('hookfromconnector', function () {
96
+ it('should succeed with asserter from connector', async function () {
97
+ const { compiler, container } = await buildDriverFromFile({
98
+ [Capabilities.ASSERTERS]: [{
99
+ ref: 'CUSTOMASSERTER',
100
+ src: path.join(__dirname, 'botium-connector-fromfile.js/MyCustomAsserter')
101
+ }]
102
+ })
103
+ compiler.ReadScript(path.resolve(__dirname, 'convos'), 'HOOKFROMSRC.convo.txt')
104
+ await compiler.convos[0].Run(container)
97
105
  })
98
- compiler.ReadScript(path.resolve(__dirname, 'convos'), 'HOOKFROMSRC.convo.txt')
99
- await compiler.convos[0].Run(container)
100
- })
101
- it('should succeed with asserter from asserter module file', async function () {
102
- const { compiler, container } = await buildDriverFromFile({
103
- [Capabilities.ASSERTERS]: [{
104
- ref: 'CUSTOMASSERTER',
105
- src: path.join(__dirname, 'botium-asserter-fromfile.js')
106
- }]
106
+ it('should succeed with asserter from asserter module file', async function () {
107
+ const { compiler, container } = await buildDriverFromFile({
108
+ [Capabilities.ASSERTERS]: [{
109
+ ref: 'CUSTOMASSERTER',
110
+ src: path.join(__dirname, 'botium-asserter-fromfile.js')
111
+ }]
112
+ })
113
+ compiler.ReadScript(path.resolve(__dirname, 'convos'), 'HOOKFROMSRC.convo.txt')
114
+ await compiler.convos[0].Run(container)
107
115
  })
108
- compiler.ReadScript(path.resolve(__dirname, 'convos'), 'HOOKFROMSRC.convo.txt')
109
- await compiler.convos[0].Run(container)
110
116
  })
111
117
  })