botium-core 1.13.16 → 1.13.18
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/README.md +0 -1
- package/dist/botium-cjs.js +283 -172
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +282 -171
- package/dist/botium-es.js.map +1 -1
- package/package.json +23 -23
- package/src/BotDriver.js +2 -4
- package/src/Capabilities.js +7 -3
- package/src/Events.js +1 -0
- package/src/containers/BaseContainer.js +5 -3
- package/src/containers/PluginConnectorContainer.js +0 -4
- package/src/containers/plugins/SimpleRestContainer.js +49 -0
- package/src/scripting/Convo.js +10 -27
- package/src/scripting/ScriptingProvider.js +121 -53
- package/src/scripting/helper.js +9 -2
- package/src/scripting/logichook/asserter/ButtonsAsserter.js +21 -8
- package/src/scripting/logichook/asserter/WerAsserter.js +53 -6
- package/src/scripting/logichook/logichooks/ClearQueueLogicHook.js +0 -1
- package/test/connectors/logicHook.js +0 -1
- package/test/connectors/simplerest.spec.js +79 -4
- package/test/scripting/asserters/buttonsAsserter.spec.js +84 -50
- package/test/scripting/logichooks/convos/custom_embedded_skip.convo.txt +11 -0
- package/test/scripting/logichooks/convos/custom_embedded_skip_followed_by_me.convo.txt +11 -0
- package/test/scripting/logichooks/convos/custom_embedded_skip_followed_by_nothing.convo.txt +8 -0
- package/test/scripting/logichooks/customEmbeddedSkip.json +14 -0
- package/test/scripting/logichooks/customEmbeddedSkip.spec.js +58 -0
- package/test/security/allowUnsafe.spec.js +20 -10
- package/test/security/convos/withscriptingmemoryfunction.convo.txt +1 -0
- package/test/convo/retryconvo.spec.js +0 -134
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// const _ = require('lodash')
|
|
2
2
|
const { BotiumError } = require('../../BotiumError')
|
|
3
|
-
const { calculateWer } = require('../../helper')
|
|
3
|
+
const { calculateWer, toPercent } = require('../../helper')
|
|
4
4
|
|
|
5
5
|
module.exports = class WerAsserter {
|
|
6
6
|
constructor (context, caps = {}) {
|
|
@@ -9,6 +9,55 @@ module.exports = class WerAsserter {
|
|
|
9
9
|
this.name = 'Word Error Rate Asserter'
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
assertNotConvoStep ({ convo, convoStep, args, botMsg }) {
|
|
13
|
+
if (!args || args.length < 1) {
|
|
14
|
+
return Promise.reject(new BotiumError(`${convoStep.stepTag}: ${this.name} - no argument given`,
|
|
15
|
+
{
|
|
16
|
+
type: 'asserter',
|
|
17
|
+
subtype: 'wrong parameters',
|
|
18
|
+
source: this.name,
|
|
19
|
+
cause: { args }
|
|
20
|
+
}
|
|
21
|
+
))
|
|
22
|
+
}
|
|
23
|
+
if (args.length > 2) {
|
|
24
|
+
return Promise.reject(new BotiumError(`${convoStep.stepTag}: ${this.name} - too many arguments "${args}"`,
|
|
25
|
+
{
|
|
26
|
+
type: 'asserter',
|
|
27
|
+
subtype: 'wrong parameters',
|
|
28
|
+
source: this.name,
|
|
29
|
+
cause: { args }
|
|
30
|
+
}
|
|
31
|
+
))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const utterance = args[0]
|
|
35
|
+
const threshold = ([',', '.'].find(p => `${args[1]}`.includes(p)) ? parseFloat(args[1]) : parseInt(args[1]) / 100).toFixed(2)
|
|
36
|
+
|
|
37
|
+
const wer = calculateWer(botMsg.messageText, utterance)
|
|
38
|
+
|
|
39
|
+
if (wer < threshold) {
|
|
40
|
+
return Promise.reject(new BotiumError(
|
|
41
|
+
`${convoStep.stepTag}: Word Error Rate (${toPercent(wer)}) lower than accepted (${toPercent(threshold)})`,
|
|
42
|
+
{
|
|
43
|
+
type: 'asserter',
|
|
44
|
+
source: this.name,
|
|
45
|
+
context: {
|
|
46
|
+
params: {
|
|
47
|
+
args
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
cause: {
|
|
51
|
+
expected: `>=${toPercent(threshold)} (${utterance})`,
|
|
52
|
+
actual: `${toPercent(wer)} (${botMsg.messageText})`
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return Promise.resolve()
|
|
59
|
+
}
|
|
60
|
+
|
|
12
61
|
assertConvoStep ({ convo, convoStep, args, botMsg }) {
|
|
13
62
|
if (!args || args.length < 1) {
|
|
14
63
|
return Promise.reject(new BotiumError(`${convoStep.stepTag}: ${this.name} - no argument given`,
|
|
@@ -37,10 +86,8 @@ module.exports = class WerAsserter {
|
|
|
37
86
|
const wer = calculateWer(botMsg.messageText, utterance)
|
|
38
87
|
|
|
39
88
|
if (wer > threshold) {
|
|
40
|
-
const _toPercent = (s) => `${(s * 100).toFixed(0)}%`
|
|
41
|
-
|
|
42
89
|
return Promise.reject(new BotiumError(
|
|
43
|
-
`${convoStep.stepTag}: Word Error Rate (${
|
|
90
|
+
`${convoStep.stepTag}: Word Error Rate (${toPercent(wer)}) higher than accepted (${toPercent(threshold)})`,
|
|
44
91
|
{
|
|
45
92
|
type: 'asserter',
|
|
46
93
|
source: this.name,
|
|
@@ -50,8 +97,8 @@ module.exports = class WerAsserter {
|
|
|
50
97
|
}
|
|
51
98
|
},
|
|
52
99
|
cause: {
|
|
53
|
-
expected: `<=${
|
|
54
|
-
actual: `${
|
|
100
|
+
expected: `<=${toPercent(threshold)} (${utterance})`,
|
|
101
|
+
actual: `${toPercent(wer)} (${botMsg.messageText})`
|
|
55
102
|
}
|
|
56
103
|
}
|
|
57
104
|
))
|
|
@@ -319,7 +319,6 @@ describe('connectors.simplerest', function () {
|
|
|
319
319
|
scope2.persist(false)
|
|
320
320
|
})
|
|
321
321
|
})
|
|
322
|
-
|
|
323
322
|
describe('build', function () {
|
|
324
323
|
it('should build JSON GET url', async function () {
|
|
325
324
|
const myCaps = Object.assign({}, myCapsGet)
|
|
@@ -997,7 +996,6 @@ describe('connectors.simplerest', function () {
|
|
|
997
996
|
assert.deepEqual(values, ['$.1', '$.2', '$.3', '$.4'])
|
|
998
997
|
})
|
|
999
998
|
})
|
|
1000
|
-
|
|
1001
999
|
describe('useresponse', function () {
|
|
1002
1000
|
beforeEach(async function () {
|
|
1003
1001
|
this.init = async (caps) => {
|
|
@@ -1151,7 +1149,6 @@ describe('connectors.simplerest', function () {
|
|
|
1151
1149
|
}
|
|
1152
1150
|
})
|
|
1153
1151
|
})
|
|
1154
|
-
|
|
1155
1152
|
describe('inbound', function () {
|
|
1156
1153
|
it('should accept inbound message with matching jsonpath', async function () {
|
|
1157
1154
|
const myCaps = Object.assign({}, myCapsGet)
|
|
@@ -1249,7 +1246,6 @@ describe('connectors.simplerest', function () {
|
|
|
1249
1246
|
return result
|
|
1250
1247
|
})
|
|
1251
1248
|
})
|
|
1252
|
-
|
|
1253
1249
|
describe('polling', function () {
|
|
1254
1250
|
it('should poll HTTP url', async function () {
|
|
1255
1251
|
const caps = {
|
|
@@ -1313,4 +1309,83 @@ describe('connectors.simplerest', function () {
|
|
|
1313
1309
|
scope.persist(false)
|
|
1314
1310
|
}).timeout(5000)
|
|
1315
1311
|
})
|
|
1312
|
+
describe('flow', function () {
|
|
1313
|
+
it('should ignore matching message', async function () {
|
|
1314
|
+
const caps = {
|
|
1315
|
+
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
1316
|
+
[Capabilities.WAITFORBOTTIMEOUT]: 1000,
|
|
1317
|
+
[Capabilities.SIMPLEREST_URL]: 'https://mock.com/flowignore',
|
|
1318
|
+
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: ['$.text'],
|
|
1319
|
+
[Capabilities.SIMPLEREST_CONTEXT_IGNORE_JSONPATH]: '$.ignore',
|
|
1320
|
+
[Capabilities.SIMPLEREST_CONTEXT_IGNORE_MATCH]: 'Y'
|
|
1321
|
+
}
|
|
1322
|
+
const scope = nock('https://mock.com')
|
|
1323
|
+
.get('/flowignore').reply(200, { text: 'ignore it', ignore: 'Y' })
|
|
1324
|
+
|
|
1325
|
+
const driver = new BotDriver(caps)
|
|
1326
|
+
const container = await driver.Build()
|
|
1327
|
+
await container.Start()
|
|
1328
|
+
|
|
1329
|
+
await container.UserSays({ text: 'hallo' })
|
|
1330
|
+
try {
|
|
1331
|
+
await container.WaitBotSays()
|
|
1332
|
+
assert.fail('expected response to be ignored')
|
|
1333
|
+
} catch (err) {
|
|
1334
|
+
assert.equal(err.message, 'Bot did not respond within 1s')
|
|
1335
|
+
}
|
|
1336
|
+
await container.Stop()
|
|
1337
|
+
await container.Clean()
|
|
1338
|
+
scope.persist(false)
|
|
1339
|
+
})
|
|
1340
|
+
it('should skip matching message', async function () {
|
|
1341
|
+
const caps = {
|
|
1342
|
+
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
1343
|
+
[Capabilities.SIMPLEREST_URL]: 'https://mock.com/flowskip',
|
|
1344
|
+
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: ['$.text'],
|
|
1345
|
+
[Capabilities.SIMPLEREST_CONTEXT_SKIP_JSONPATH]: '$.skip',
|
|
1346
|
+
[Capabilities.SIMPLEREST_CONTEXT_SKIP_MATCH]: 'Y'
|
|
1347
|
+
}
|
|
1348
|
+
const scope = nock('https://mock.com')
|
|
1349
|
+
.get('/flowskip').reply(200, { text: 'skip it', skip: 'Y' })
|
|
1350
|
+
.get('/flowskip').reply(200, { text: 'not skip it', skip: 'N' })
|
|
1351
|
+
|
|
1352
|
+
const driver = new BotDriver(caps)
|
|
1353
|
+
const container = await driver.Build()
|
|
1354
|
+
await container.Start()
|
|
1355
|
+
|
|
1356
|
+
await container.UserSays({ text: 'hello' })
|
|
1357
|
+
const botMsg = await container.WaitBotSays()
|
|
1358
|
+
assert.equal(botMsg.messageText, 'not skip it')
|
|
1359
|
+
|
|
1360
|
+
await container.Stop()
|
|
1361
|
+
await container.Clean()
|
|
1362
|
+
scope.persist(false)
|
|
1363
|
+
})
|
|
1364
|
+
it('should continue on matching message', async function () {
|
|
1365
|
+
const caps = {
|
|
1366
|
+
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
1367
|
+
[Capabilities.SIMPLEREST_URL]: 'https://mock.com/flowcontinue',
|
|
1368
|
+
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: ['$.text'],
|
|
1369
|
+
[Capabilities.SIMPLEREST_CONTEXT_CONTINUE_JSONPATH]: '$.continue',
|
|
1370
|
+
[Capabilities.SIMPLEREST_CONTEXT_CONTINUE_MATCH]: 'Y'
|
|
1371
|
+
}
|
|
1372
|
+
const scope = nock('https://mock.com')
|
|
1373
|
+
.get('/flowcontinue').reply(200, { text: 'continue it', continue: 'Y' })
|
|
1374
|
+
.get('/flowcontinue').reply(200, { text: 'not continue it', continue: 'N' })
|
|
1375
|
+
|
|
1376
|
+
const driver = new BotDriver(caps)
|
|
1377
|
+
const container = await driver.Build()
|
|
1378
|
+
await container.Start()
|
|
1379
|
+
|
|
1380
|
+
await container.UserSays({ text: 'hello' })
|
|
1381
|
+
const botMsg1 = await container.WaitBotSays()
|
|
1382
|
+
assert.equal(botMsg1.messageText, 'continue it')
|
|
1383
|
+
const botMsg2 = await container.WaitBotSays()
|
|
1384
|
+
assert.equal(botMsg2.messageText, 'not continue it')
|
|
1385
|
+
|
|
1386
|
+
await container.Stop()
|
|
1387
|
+
await container.Clean()
|
|
1388
|
+
scope.persist(false)
|
|
1389
|
+
})
|
|
1390
|
+
})
|
|
1316
1391
|
})
|
|
@@ -12,28 +12,36 @@ describe('scripting.asserters.buttonsAsserter', function () {
|
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
it('should succeed on existing button', async function () {
|
|
15
|
+
const payload = {
|
|
16
|
+
value: 'test'
|
|
17
|
+
}
|
|
15
18
|
await this.buttonsAsserter.assertConvoStep({
|
|
16
19
|
convoStep: { stepTag: 'test' },
|
|
17
|
-
args: ['test'],
|
|
20
|
+
args: ['test', JSON.stringify(payload)],
|
|
18
21
|
botMsg: {
|
|
19
22
|
buttons: [
|
|
20
23
|
{
|
|
21
|
-
text: 'test'
|
|
24
|
+
text: 'test',
|
|
25
|
+
payload
|
|
22
26
|
}
|
|
23
27
|
]
|
|
24
28
|
}
|
|
25
29
|
})
|
|
26
30
|
})
|
|
27
31
|
it('should succeed on existing card button', async function () {
|
|
32
|
+
const payload = {
|
|
33
|
+
value: 'test'
|
|
34
|
+
}
|
|
28
35
|
await this.buttonsAsserter.assertConvoStep({
|
|
29
36
|
convoStep: { stepTag: 'test' },
|
|
30
|
-
args: ['test'],
|
|
37
|
+
args: ['test', JSON.stringify(payload)],
|
|
31
38
|
botMsg: {
|
|
32
39
|
cards: [
|
|
33
40
|
{
|
|
34
41
|
buttons: [
|
|
35
42
|
{
|
|
36
|
-
text: 'test'
|
|
43
|
+
text: 'test',
|
|
44
|
+
payload
|
|
37
45
|
}
|
|
38
46
|
]
|
|
39
47
|
}
|
|
@@ -42,42 +50,28 @@ describe('scripting.asserters.buttonsAsserter', function () {
|
|
|
42
50
|
})
|
|
43
51
|
})
|
|
44
52
|
it('should succeed on existing card buttons', async function () {
|
|
53
|
+
const payload = {
|
|
54
|
+
value: 'test'
|
|
55
|
+
}
|
|
56
|
+
const payloadCard = {
|
|
57
|
+
value: 'card'
|
|
58
|
+
}
|
|
45
59
|
await this.buttonsAsserter.assertConvoStep({
|
|
46
60
|
convoStep: { stepTag: 'test' },
|
|
47
|
-
args: ['test', 'test1'],
|
|
48
|
-
botMsg: {
|
|
49
|
-
buttons: [
|
|
50
|
-
{
|
|
51
|
-
text: 'test'
|
|
52
|
-
}
|
|
53
|
-
],
|
|
54
|
-
cards: [
|
|
55
|
-
{
|
|
56
|
-
buttons: [
|
|
57
|
-
{
|
|
58
|
-
text: 'test1'
|
|
59
|
-
}
|
|
60
|
-
]
|
|
61
|
-
}
|
|
62
|
-
]
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
it('should succeed on existing card buttons 2', async function () {
|
|
67
|
-
await this.buttonsAsserter.assertConvoStep({
|
|
68
|
-
convoStep: { stepTag: 'test' },
|
|
69
|
-
args: ['test', 'test1'],
|
|
61
|
+
args: ['test', 'test1', JSON.stringify(payload), JSON.stringify(payloadCard)],
|
|
70
62
|
botMsg: {
|
|
71
63
|
buttons: [
|
|
72
64
|
{
|
|
73
|
-
text: 'test'
|
|
65
|
+
text: 'test',
|
|
66
|
+
payload
|
|
74
67
|
}
|
|
75
68
|
],
|
|
76
69
|
cards: [
|
|
77
70
|
{
|
|
78
71
|
buttons: [
|
|
79
72
|
{
|
|
80
|
-
text: 'test1'
|
|
73
|
+
text: 'test1',
|
|
74
|
+
payload: payloadCard
|
|
81
75
|
}
|
|
82
76
|
]
|
|
83
77
|
}
|
|
@@ -86,29 +80,36 @@ describe('scripting.asserters.buttonsAsserter', function () {
|
|
|
86
80
|
})
|
|
87
81
|
})
|
|
88
82
|
it('should succeed on not existing button', async function () {
|
|
83
|
+
const notPayload = {
|
|
84
|
+
value: 'test1'
|
|
85
|
+
}
|
|
89
86
|
await this.buttonsAsserter.assertNotConvoStep({
|
|
90
87
|
convoStep: { stepTag: 'test' },
|
|
91
|
-
args: ['test1'],
|
|
88
|
+
args: ['test1', JSON.stringify(notPayload)],
|
|
92
89
|
botMsg: {
|
|
93
90
|
buttons: [
|
|
94
91
|
{
|
|
95
|
-
text: 'test'
|
|
92
|
+
text: 'test',
|
|
93
|
+
payload: {
|
|
94
|
+
value: 'test'
|
|
95
|
+
}
|
|
96
96
|
}
|
|
97
97
|
]
|
|
98
98
|
}
|
|
99
99
|
})
|
|
100
100
|
})
|
|
101
101
|
it('should fail on unexpected button', async function () {
|
|
102
|
+
const buttons = [
|
|
103
|
+
{
|
|
104
|
+
text: 'test'
|
|
105
|
+
}
|
|
106
|
+
]
|
|
102
107
|
try {
|
|
103
108
|
await this.buttonsAsserter.assertNotConvoStep({
|
|
104
109
|
convoStep: { stepTag: 'test' },
|
|
105
110
|
args: ['test', 'test1'],
|
|
106
111
|
botMsg: {
|
|
107
|
-
buttons
|
|
108
|
-
{
|
|
109
|
-
text: 'test'
|
|
110
|
-
}
|
|
111
|
-
]
|
|
112
|
+
buttons
|
|
112
113
|
}
|
|
113
114
|
})
|
|
114
115
|
assert.fail('should have failed')
|
|
@@ -119,10 +120,40 @@ describe('scripting.asserters.buttonsAsserter', function () {
|
|
|
119
120
|
assert.isArray(err.context.cause.expected)
|
|
120
121
|
assert.isTrue(err.context.cause.not)
|
|
121
122
|
assert.deepEqual(err.context.cause.expected, ['test', 'test1'])
|
|
122
|
-
assert.deepEqual(err.context.cause.actual,
|
|
123
|
+
assert.deepEqual(err.context.cause.actual, JSON.stringify(buttons, null, 2))
|
|
123
124
|
assert.deepEqual(err.context.cause.diff, ['test'])
|
|
124
125
|
}
|
|
125
126
|
})
|
|
127
|
+
it('should fail on unexpected button payload', async function () {
|
|
128
|
+
const payload = {
|
|
129
|
+
value: 'test'
|
|
130
|
+
}
|
|
131
|
+
const buttons = [
|
|
132
|
+
{
|
|
133
|
+
text: 'test',
|
|
134
|
+
payload
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
try {
|
|
138
|
+
await this.buttonsAsserter.assertNotConvoStep({
|
|
139
|
+
convoStep: { stepTag: 'test' },
|
|
140
|
+
args: [JSON.stringify(payload)],
|
|
141
|
+
botMsg: {
|
|
142
|
+
buttons
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
assert.fail('should have failed')
|
|
146
|
+
} catch (err) {
|
|
147
|
+
assert.isTrue(err.message.indexOf(`Not expected button(s) with text "${JSON.stringify(payload)}"`) > 0)
|
|
148
|
+
assert.isNotNull(err.context)
|
|
149
|
+
assert.isNotNull(err.context.cause)
|
|
150
|
+
assert.isArray(err.context.cause.expected)
|
|
151
|
+
assert.isTrue(err.context.cause.not)
|
|
152
|
+
assert.deepEqual(err.context.cause.expected, [JSON.stringify(payload)])
|
|
153
|
+
assert.deepEqual(err.context.cause.actual, JSON.stringify(buttons, null, 2))
|
|
154
|
+
assert.deepEqual(err.context.cause.diff, [JSON.stringify(payload)])
|
|
155
|
+
}
|
|
156
|
+
})
|
|
126
157
|
it('should succeed on existing button if has no arg', async function () {
|
|
127
158
|
await this.buttonsAsserter.assertConvoStep({
|
|
128
159
|
convoStep: { stepTag: 'test' },
|
|
@@ -147,23 +178,24 @@ describe('scripting.asserters.buttonsAsserter', function () {
|
|
|
147
178
|
assert.isArray(err.context.cause.expected)
|
|
148
179
|
assert.isNotTrue(err.context.cause.not)
|
|
149
180
|
assert.deepEqual(err.context.cause.expected, [])
|
|
150
|
-
assert.deepEqual(err.context.cause.actual, [])
|
|
181
|
+
assert.deepEqual(err.context.cause.actual, '[]')
|
|
151
182
|
}
|
|
152
183
|
})
|
|
153
184
|
it('should succeed on not existing button if has no arg and negated', async function () {
|
|
154
185
|
await this.buttonsAsserter.assertNotConvoStep({ convoStep: { stepTag: 'test' } })
|
|
155
186
|
})
|
|
156
187
|
it('should fail on button if has no arg and negated', async function () {
|
|
188
|
+
const buttons = [
|
|
189
|
+
{
|
|
190
|
+
text: 'test'
|
|
191
|
+
}
|
|
192
|
+
]
|
|
157
193
|
try {
|
|
158
194
|
await this.buttonsAsserter.assertNotConvoStep({
|
|
159
195
|
convoStep: { stepTag: 'test' },
|
|
160
196
|
args: [],
|
|
161
197
|
botMsg: {
|
|
162
|
-
buttons
|
|
163
|
-
{
|
|
164
|
-
text: 'test'
|
|
165
|
-
}
|
|
166
|
-
]
|
|
198
|
+
buttons
|
|
167
199
|
}
|
|
168
200
|
})
|
|
169
201
|
assert.fail('should have failed')
|
|
@@ -174,7 +206,7 @@ describe('scripting.asserters.buttonsAsserter', function () {
|
|
|
174
206
|
assert.isArray(err.context.cause.expected)
|
|
175
207
|
assert.isTrue(err.context.cause.not)
|
|
176
208
|
assert.deepEqual(err.context.cause.expected, [])
|
|
177
|
-
assert.deepEqual(err.context.cause.actual,
|
|
209
|
+
assert.deepEqual(err.context.cause.actual, JSON.stringify(buttons, null, 2))
|
|
178
210
|
}
|
|
179
211
|
})
|
|
180
212
|
})
|
|
@@ -302,16 +334,17 @@ describe('scripting.asserters.buttonsAsserter', function () {
|
|
|
302
334
|
})
|
|
303
335
|
|
|
304
336
|
it('should fail with normalized text', async function () {
|
|
337
|
+
const buttons = [
|
|
338
|
+
{
|
|
339
|
+
text: '<html><h1>test html header</h1><p>test html text</p>'
|
|
340
|
+
}
|
|
341
|
+
]
|
|
305
342
|
try {
|
|
306
343
|
await this.cardsAsserter.assertConvoStep({
|
|
307
344
|
convoStep: { stepTag: 'test' },
|
|
308
345
|
args: ['Test Html header1 test html text'],
|
|
309
346
|
botMsg: {
|
|
310
|
-
buttons
|
|
311
|
-
{
|
|
312
|
-
text: '<html><h1>test html header</h1><p>test html text</p>'
|
|
313
|
-
}
|
|
314
|
-
]
|
|
347
|
+
buttons
|
|
315
348
|
}
|
|
316
349
|
})
|
|
317
350
|
assert.fail('should have failed')
|
|
@@ -321,7 +354,8 @@ describe('scripting.asserters.buttonsAsserter', function () {
|
|
|
321
354
|
assert.isNotNull(err.context.cause)
|
|
322
355
|
assert.isArray(err.context.cause.expected)
|
|
323
356
|
assert.deepEqual(err.context.cause.expected, ['Test Html header1 test html text'])
|
|
324
|
-
|
|
357
|
+
buttons[0].text = 'test html header test html text'
|
|
358
|
+
assert.deepEqual(err.context.cause.actual, JSON.stringify(buttons, null, 2))
|
|
325
359
|
assert.deepEqual(err.context.cause.diff, ['Test Html header1 test html text'])
|
|
326
360
|
}
|
|
327
361
|
})
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const assert = require('chai').assert
|
|
3
|
+
const BotDriver = require('../../..').BotDriver
|
|
4
|
+
const Capabilities = require('../../..').Capabilities
|
|
5
|
+
const myCaps = require('./customEmbeddedSkip')
|
|
6
|
+
|
|
7
|
+
const echoConnector = () => ({ queueBotSays }) => {
|
|
8
|
+
return {
|
|
9
|
+
UserSays (msg) {
|
|
10
|
+
const botMsg = { sender: 'bot', sourceData: msg.sourceData, messageText: msg.messageText }
|
|
11
|
+
queueBotSays(botMsg)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const buildDriver = async (mergeCaps) => {
|
|
17
|
+
const myCaps = Object.assign({
|
|
18
|
+
[Capabilities.PROJECTNAME]: 'convo.customassertersskip',
|
|
19
|
+
[Capabilities.CONTAINERMODE]: echoConnector()
|
|
20
|
+
}, mergeCaps)
|
|
21
|
+
|
|
22
|
+
const result = {}
|
|
23
|
+
result.driver = new BotDriver(myCaps)
|
|
24
|
+
result.compiler = result.driver.BuildCompiler()
|
|
25
|
+
result.container = await result.driver.Build()
|
|
26
|
+
return result
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe('convo.customasserters skip', function () {
|
|
30
|
+
beforeEach(async function () {
|
|
31
|
+
const { compiler, container } = await buildDriver(myCaps)
|
|
32
|
+
this.compiler = compiler
|
|
33
|
+
this.container = container
|
|
34
|
+
await this.container.Start()
|
|
35
|
+
})
|
|
36
|
+
afterEach(async function () {
|
|
37
|
+
await this.container.Stop()
|
|
38
|
+
await this.container.Clean()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('should success followed by another bot message', async function () {
|
|
42
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'custom_embedded_skip.convo.txt')
|
|
43
|
+
const transript = await this.compiler.convos[0].Run(this.container)
|
|
44
|
+
assert.equal(transript.steps.length, 2)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('should success followed by me message', async function () {
|
|
48
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'custom_embedded_skip_followed_by_me.convo.txt')
|
|
49
|
+
const transript = await this.compiler.convos[0].Run(this.container)
|
|
50
|
+
assert.equal(transript.steps.length, 2)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('should success followed by nothing', async function () {
|
|
54
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'custom_embedded_skip_followed_by_nothing.convo.txt')
|
|
55
|
+
const transript = await this.compiler.convos[0].Run(this.container)
|
|
56
|
+
assert.equal(transript.steps.length, 1)
|
|
57
|
+
})
|
|
58
|
+
})
|
|
@@ -10,13 +10,28 @@ const HookUtils = require('../../src/helpers/HookUtils')
|
|
|
10
10
|
|
|
11
11
|
const myCapsSimpleRest = {
|
|
12
12
|
[Capabilities.CONTAINERMODE]: 'simplerest',
|
|
13
|
-
[Capabilities.SIMPLEREST_URL]: 'http://my-host.com/api/endpoint',
|
|
13
|
+
[Capabilities.SIMPLEREST_URL]: 'http://my-non-existing-botium-host.com/api/endpoint',
|
|
14
14
|
[Capabilities.SIMPLEREST_METHOD]: 'POST',
|
|
15
15
|
[Capabilities.SECURITY_ALLOW_UNSAFE]: false,
|
|
16
16
|
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
|
|
17
17
|
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: ['$']
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
const echoConnector = ({ queueBotSays }) => {
|
|
21
|
+
return {
|
|
22
|
+
UserSays (msg) {
|
|
23
|
+
const botMsg = { sender: 'bot', sourceData: msg.sourceData, messageText: `You said: "${msg.messageText}"` }
|
|
24
|
+
queueBotSays(botMsg)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const myCapsEcho = {
|
|
30
|
+
[Capabilities.CONTAINERMODE]: echoConnector,
|
|
31
|
+
[Capabilities.SECURITY_ALLOW_UNSAFE]: false,
|
|
32
|
+
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
const _getSimpleRestCaps = (caps) => {
|
|
21
36
|
return Object.assign(
|
|
22
37
|
{},
|
|
@@ -83,20 +98,15 @@ describe('security.allowUnsafe', function () {
|
|
|
83
98
|
|
|
84
99
|
describe('scripting memory', function () {
|
|
85
100
|
it('should not throw security error for using inline function', async function () {
|
|
86
|
-
const driver = new BotDriver(
|
|
101
|
+
const driver = new BotDriver(myCapsEcho)
|
|
87
102
|
const compiler = driver.BuildCompiler()
|
|
88
103
|
const container = await driver.Build()
|
|
89
104
|
await container.Start()
|
|
90
105
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
await compiler.convos[0].Run(container)
|
|
94
|
-
assert.fail('should have failed')
|
|
95
|
-
} catch (err) {
|
|
96
|
-
assert.isFalse(err.message.indexOf('Security Error. Using unsafe scripting memory function $func is not allowed') >= 0)
|
|
97
|
-
}
|
|
106
|
+
compiler.ReadScript(path.resolve(__dirname, 'convos'), 'withscriptingmemoryfunction.convo.txt')
|
|
107
|
+
await compiler.convos[0].Run(container)
|
|
98
108
|
await container.Clean()
|
|
99
|
-
})
|
|
109
|
+
}).timeout(50000)
|
|
100
110
|
})
|
|
101
111
|
|
|
102
112
|
describe('simple rest, scripting memory', function () {
|