botium-core 1.13.2 → 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.
- package/.eslintrc.js +6 -3
- package/dist/botium-cjs.js +214 -61
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +213 -61
- package/dist/botium-es.js.map +1 -1
- package/package.json +3 -1
- package/src/Capabilities.js +2 -1
- package/src/containers/plugins/SimpleRestContainer.js +20 -16
- package/src/grid/inbound/proxy.js +2 -1
- package/src/scripting/Convo.js +16 -10
- package/src/scripting/MatchFunctions.js +10 -0
- package/src/scripting/ScriptingProvider.js +106 -37
- package/src/scripting/logichook/LogicHookConsts.js +1 -1
- package/src/scripting/logichook/asserter/WerAsserter.js +59 -0
- package/src/scripting/logichook/logichooks/UpdateCustomLogicHook.js +3 -2
- package/test/compiler/compilercsv.spec.js +104 -3
- package/test/compiler/compilerjson.spec.js +0 -2
- package/test/compiler/compilerxlsx.spec.js +1 -1
- package/test/compiler/convos/csv/utterances_liveperson2.csv +12 -0
- package/test/connectors/simplerest.spec.js +1012 -969
- package/test/convo/fillAndApplyScriptingMemory.spec.js +804 -785
- package/test/convo/partialconvo.spec.js +345 -339
- package/test/driver/capabilities.spec.js +156 -151
- package/test/logichooks/hookfromsrc.spec.js +79 -73
- package/test/plugins/plugins.spec.js +44 -42
- package/test/scripting/asserters/buttonsAsserter.spec.js +257 -240
- package/test/scripting/asserters/cardsAsserter.spec.js +214 -212
- package/test/scripting/asserters/convos/wer_threshold_nok.yml +7 -0
- package/test/scripting/asserters/convos/wer_threshold_ok.yml +7 -0
- package/test/scripting/asserters/intentConfidenceAsserter.spec.js +34 -35
- package/test/scripting/asserters/jsonpathAsserter.spec.js +307 -308
- package/test/scripting/asserters/mediaAsserter.spec.js +236 -234
- package/test/scripting/asserters/werAsserter.spec.js +51 -0
- package/test/scripting/logichooks/setClearScriptingMemory.spec.js +202 -192
- package/test/scripting/matching/matchingmode.spec.js +306 -258
- package/test/scripting/scriptingProvider.spec.js +666 -633
- package/test/scripting/scriptingmemory/fillScriptingMemoryFromFile.spec.js +299 -281
- package/test/scripting/scriptingmemory/useScriptingMemoryForAssertion.spec.js +94 -80
- package/test/scripting/userinputs/defaultUserInputs.spec.js +233 -127
- package/test/scripting/userinputs/mediaInputConvos.spec.js +409 -403
- package/test/scripting/utteranceexpansion/associateByIndex.spec.js +259 -0
- package/test/scripting/utteranceexpansion/convos/associate_utterances_by_index.json +33 -0
- package/test/scripting/utteranceexpansion/convos/media.convo.txt +19 -0
- package/test/scripting/utteranceexpansion/files/step0voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step0voice1.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step0voice2.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step1voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice1.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice2.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice4.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice5.wav +0 -0
- package/test/security/allowUnsafe.spec.js +274 -268
- package/test/utils.spec.js +40 -38
|
@@ -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.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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('
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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('
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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('
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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 = {
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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 - Script assertConvoStep is not valid'))
|
|
73
|
-
}
|
|
74
80
|
})
|
|
75
|
-
})
|
|
76
81
|
|
|
77
|
-
const buildDriverFromFile = async (mergeCaps) => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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('
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
})
|
|
@@ -2,53 +2,55 @@ const path = require('path')
|
|
|
2
2
|
const assert = require('chai').assert
|
|
3
3
|
const { BotDriver, Capabilities, Plugins } = require('../../')
|
|
4
4
|
|
|
5
|
-
describe('plugins.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
describe('plugins.plugins', function () {
|
|
6
|
+
describe('find', function () {
|
|
7
|
+
it('should return empty list on invalid folder', async function () {
|
|
8
|
+
const plugins = await Plugins.getPlugins(Plugins.PLUGIN_TYPE_ASSERTER, 'abcd')
|
|
9
|
+
assert.isEmpty(plugins)
|
|
10
|
+
})
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
it('should load connector from folder', async function () {
|
|
13
|
+
const plugins = await Plugins.getPlugins(Plugins.PLUGIN_TYPE_CONNECTOR, path.join(__dirname, 'plugindir', 'fromfolder'))
|
|
14
|
+
assert.lengthOf(plugins, 1)
|
|
15
|
+
assert.equal(plugins[0].PluginDesc.name, 'Test Connector FromDir')
|
|
16
|
+
assert.equal(plugins[0].PluginDesc.src, 'fromdir1')
|
|
17
|
+
})
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
it('should load connector from file', async function () {
|
|
20
|
+
const plugins = await Plugins.getPlugins(Plugins.PLUGIN_TYPE_CONNECTOR, path.join(__dirname, 'plugindir', 'fromfile'))
|
|
21
|
+
assert.lengthOf(plugins, 2)
|
|
22
|
+
assert.equal(plugins[0].PluginDesc.name, 'Test Connector FromFile 1')
|
|
23
|
+
assert.equal(plugins[0].PluginDesc.src, 'fromfile1')
|
|
24
|
+
assert.equal(plugins[1].PluginDesc.name, 'Test Connector FromFile 2')
|
|
25
|
+
assert.equal(plugins[1].PluginDesc.src, 'fromfile2')
|
|
26
|
+
})
|
|
25
27
|
})
|
|
26
|
-
})
|
|
27
28
|
|
|
28
|
-
describe('
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
describe('load', function () {
|
|
30
|
+
it('should map simple function to class', async function () {
|
|
31
|
+
const myCaps = {
|
|
32
|
+
[Capabilities.PROJECTNAME]: 'plugins.load',
|
|
33
|
+
[Capabilities.CONTAINERMODE]: 'fromfile1'
|
|
34
|
+
}
|
|
35
|
+
const driver = new BotDriver(myCaps)
|
|
36
|
+
const container = await driver.Build()
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
await container.UserSays({ messageText: 'TEST' })
|
|
39
|
+
const response = await container.WaitBotSays()
|
|
40
|
+
assert.equal(response.messageText, 'TEST')
|
|
41
|
+
})
|
|
42
|
+
it('should use UserSays function as class', async function () {
|
|
43
|
+
const myCaps = {
|
|
44
|
+
[Capabilities.PROJECTNAME]: 'plugins.load',
|
|
45
|
+
[Capabilities.CONTAINERMODE]: 'fromfile2',
|
|
46
|
+
cap1: 'MYPREFIX'
|
|
47
|
+
}
|
|
48
|
+
const driver = new BotDriver(myCaps)
|
|
49
|
+
const container = await driver.Build()
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
await container.UserSays({ messageText: 'TEST' })
|
|
52
|
+
const response = await container.WaitBotSays()
|
|
53
|
+
assert.equal(response.messageText, 'MYPREFIX:TEST')
|
|
54
|
+
})
|
|
53
55
|
})
|
|
54
56
|
})
|