botium-core 1.13.19 → 1.14.0

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 (32) hide show
  1. package/dist/botium-cjs.js +298 -382
  2. package/dist/botium-cjs.js.map +1 -1
  3. package/dist/botium-es.js +298 -380
  4. package/dist/botium-es.js.map +1 -1
  5. package/package.json +20 -25
  6. package/samples/extensions/asserterHooks/botium.json +1 -0
  7. package/samples/extensions/logichooks/botium.json +1 -0
  8. package/samples/extensions/logichooks/custom/MyAsserter.js +3 -3
  9. package/src/Capabilities.js +2 -1
  10. package/src/containers/PluginConnectorContainer.js +8 -0
  11. package/src/containers/plugins/SimpleRestContainer.js +17 -9
  12. package/src/containers/plugins/index.js +29 -41
  13. package/src/helpers/HookUtils.js +32 -68
  14. package/src/scripting/ScriptingMemory.js +0 -24
  15. package/src/scripting/logichook/LogicHookUtils.js +27 -47
  16. package/test/compiler/precompilerscript.spec.js +24 -26
  17. package/test/connectors/pluginconnectorcontainer.spec.js +60 -0
  18. package/test/connectors/simplerest.spec.js +24 -27
  19. package/test/convo/fillAndApplyScriptingMemory.spec.js +1 -47
  20. package/test/hooks/customhooks.spec.js +3 -25
  21. package/test/logichooks/hookfromsrc.spec.js +13 -3
  22. package/test/plugins/plugins.spec.js +29 -2
  23. package/test/security/allowUnsafe.spec.js +20 -129
  24. package/LICENSES-3RDPARTY.txt +0 -6450
  25. package/test/scripting/asserters/convos/customembeddedasserterwithhugo.convo.txt +0 -7
  26. package/test/scripting/asserters/convos/customembeddedasserterwithouthugo.convo.txt +0 -7
  27. package/test/scripting/asserters/customEmbeddedAsserter.json +0 -14
  28. package/test/scripting/asserters/customEmbeddedAsserter.spec.js +0 -55
  29. package/test/scripting/logichooks/convos/custom_embedded.convo.txt +0 -8
  30. package/test/scripting/logichooks/customEmbedded.json +0 -14
  31. package/test/scripting/logichooks/customEmbedded.spec.js +0 -44
  32. package/test/security/convos/withscriptingmemoryfunction.convo.txt +0 -5
@@ -33,13 +33,13 @@ const afterCustom = async (thisParam) => {
33
33
 
34
34
  describe('compiler.precompiler.script', function () {
35
35
  it('should execute non-standard json', async function () {
36
- await beforeCustom(this, `
36
+ await beforeCustom(this, ({ scriptData }) => {
37
37
  const utterances = {}
38
38
  for (const entry of scriptData) {
39
39
  utterances[entry.intent] = entry.sentences
40
40
  }
41
- module.exports = {utterances}
42
- `)
41
+ return { utterances }
42
+ })
43
43
  this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convos_precompiler_script.json')
44
44
  this.compiler.ExpandUtterancesToConvos()
45
45
  this.compiler.ExpandConvos()
@@ -54,15 +54,15 @@ describe('compiler.precompiler.script', function () {
54
54
  })
55
55
 
56
56
  it('should filter by extension, accepted', async function () {
57
- await beforeCustom(this, `
58
- if (filename.endsWith('.json')) {
57
+ await beforeCustom(this, ({ filename, scriptData }) => {
58
+ if (filename.endsWith('.json')) {
59
59
  const utterances = {}
60
60
  for (const entry of scriptData) {
61
61
  utterances[entry.intent] = entry.sentences
62
62
  }
63
- module.exports = {utterances}
63
+ return { utterances }
64
64
  }
65
- `)
65
+ })
66
66
  this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convos_precompiler_script.json')
67
67
  this.compiler.ExpandUtterancesToConvos()
68
68
  this.compiler.ExpandConvos()
@@ -71,15 +71,15 @@ describe('compiler.precompiler.script', function () {
71
71
  })
72
72
 
73
73
  it('should filter by extension, rejected', async function () {
74
- await beforeCustom(this, `
75
- if (filename.endsWith('.xxx')) {
74
+ await beforeCustom(this, ({ filename, scriptData }) => {
75
+ if (filename.endsWith('.xxx')) {
76
76
  const utterances = {}
77
77
  for (const entry of scriptData) {
78
78
  utterances[entry.intent] = entry.sentences
79
79
  }
80
- module.exports = {utterances}
80
+ return { utterances }
81
81
  }
82
- `)
82
+ })
83
83
  this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convos_precompiler_script.json')
84
84
  this.compiler.ExpandUtterancesToConvos()
85
85
  this.compiler.ExpandConvos()
@@ -88,15 +88,15 @@ describe('compiler.precompiler.script', function () {
88
88
  })
89
89
 
90
90
  it('should filter by content, accepted', async function () {
91
- await beforeCustom(this, `
91
+ await beforeCustom(this, ({ scriptData }) => {
92
92
  if (scriptData) {
93
93
  const utterances = {}
94
94
  for (const entry of scriptData) {
95
95
  utterances[entry.intent] = entry.sentences
96
96
  }
97
- module.exports = {utterances}
97
+ return { utterances }
98
98
  }
99
- `)
99
+ })
100
100
  this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convos_precompiler_script.json')
101
101
  this.compiler.ExpandUtterancesToConvos()
102
102
  this.compiler.ExpandConvos()
@@ -105,15 +105,15 @@ describe('compiler.precompiler.script', function () {
105
105
  })
106
106
 
107
107
  it('should filter by content, rejected', async function () {
108
- await beforeCustom(this, `
108
+ await beforeCustom(this, ({ scriptData }) => {
109
109
  if (scriptData.utterances) {
110
110
  const utterances = {}
111
111
  for (const entry of scriptData.utterances) {
112
112
  utterances[entry.intent] = entry.sentences
113
113
  }
114
- module.exports = {utterances}
114
+ return { utterances }
115
115
  }
116
- `)
116
+ })
117
117
  this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convos_precompiler_script.json')
118
118
  this.compiler.ExpandUtterancesToConvos()
119
119
  this.compiler.ExpandConvos()
@@ -122,13 +122,13 @@ describe('compiler.precompiler.script', function () {
122
122
  })
123
123
 
124
124
  it('should change extension', async function () {
125
- await beforeCustom(this, `
125
+ await beforeCustom(this, ({ filename, scriptData }) => {
126
126
  const utterances = {}
127
127
  for (const entry of scriptData) {
128
128
  utterances[entry.intent] = entry.sentences
129
129
  }
130
- module.exports = { scriptBuffer:{utterances}, filename: filename + ".json" }
131
- `)
130
+ return { scriptBuffer: { utterances }, filename: filename + '.json' }
131
+ })
132
132
  this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convos_precompiler_script.json.txt')
133
133
  this.compiler.ExpandUtterancesToConvos()
134
134
  this.compiler.ExpandConvos()
@@ -137,13 +137,13 @@ describe('compiler.precompiler.script', function () {
137
137
  })
138
138
 
139
139
  it('should not read anything without extension change', async function () {
140
- await beforeCustom(this, `
140
+ await beforeCustom(this, ({ scriptData }) => {
141
141
  const utterances = {}
142
142
  for (const entry of scriptData) {
143
143
  utterances[entry.intent] = entry.sentences
144
144
  }
145
- module.exports = { scriptBuffer:{utterances} }
146
- `)
145
+ return { scriptBuffer: { utterances } }
146
+ })
147
147
  this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convos_precompiler_script.json.txt')
148
148
  this.compiler.ExpandUtterancesToConvos()
149
149
  this.compiler.ExpandConvos()
@@ -152,9 +152,7 @@ describe('compiler.precompiler.script', function () {
152
152
  })
153
153
 
154
154
  it('should be able to precompile text to text', async function () {
155
- await beforeCustom(this, `
156
- module.exports = scriptData.replace("Hi!", "Hi Bot!")
157
- `)
155
+ await beforeCustom(this, ({ scriptData }) => scriptData.replace('Hi!', 'Hi Bot!'))
158
156
  this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convos_precompiler_script_text_to_text.convo.txt')
159
157
  this.compiler.ExpandUtterancesToConvos()
160
158
  this.compiler.ExpandConvos()
@@ -0,0 +1,60 @@
1
+ const assert = require('chai').assert
2
+ const BotDriver = require('../../').BotDriver
3
+ const Capabilities = require('../../').Capabilities
4
+
5
+ const echoConnectorWithMetadata = ({ queueBotSays }) => {
6
+ return {
7
+ UserSays (msg) {
8
+ const botMsg = {
9
+ sender: 'bot',
10
+ sourceData: msg.sourceData,
11
+ messageText: `Response of ${msg.messageText}`
12
+ }
13
+ queueBotSays(botMsg)
14
+ },
15
+ GetMetaData () {
16
+ return Promise.resolve('Sample response from GetMetaData')
17
+ }
18
+ }
19
+ }
20
+ const echoConnectorWithoutMetadata = ({ queueBotSays }) => {
21
+ return {
22
+ UserSays (msg) {
23
+ const botMsg = {
24
+ sender: 'bot',
25
+ sourceData: msg.sourceData,
26
+ messageText: `Response of ${msg.messageText}`
27
+ }
28
+ queueBotSays(botMsg)
29
+ }
30
+ }
31
+ }
32
+
33
+ describe('compiler.precompiler.json', function () {
34
+ beforeEach(async function () {
35
+ this.init = async (withGetMetaData) => {
36
+ const myCaps = {
37
+ [Capabilities.PROJECTNAME]: 'connector.basecontainer',
38
+ [Capabilities.CONTAINERMODE]: withGetMetaData ? echoConnectorWithMetadata : echoConnectorWithoutMetadata
39
+ }
40
+ const driver = new BotDriver(myCaps)
41
+ this.compiler = driver.BuildCompiler()
42
+ this.container = await driver.Build()
43
+ }
44
+ })
45
+ afterEach(async function () {
46
+ this.container && await this.container.Clean()
47
+ })
48
+
49
+ it('should get metadata if its available', async function () {
50
+ await this.init(true)
51
+ const result = await this.container.GetMetaData()
52
+ assert.equal(result, 'Sample response from GetMetaData')
53
+ })
54
+
55
+ it('should get undefined if metadata is not available', async function () {
56
+ await this.init(false)
57
+ const result = await this.container.GetMetaData()
58
+ assert.equal(result, undefined)
59
+ })
60
+ })
@@ -50,7 +50,6 @@ const myCapsScriptingMemory = {
50
50
  FUNCTION_WITHOUT_PARAM: '{{fnc.year}}',
51
51
  FUNCTION_WITH_PARAM: '{{#fnc.random}}5{{/fnc.random}}',
52
52
  FUNCTION_WITH_PARAM_FROM_SCRIPTING_MEMORY: '{{#fnc.random}}{{msg.scriptingMemory.functionArgument}}{{/fnc.random}}',
53
- USING_CODE: '{{#fnc.func}}1 + 2{{/fnc.func}}',
54
53
  SAMPLE_ENV: '{{#fnc.env}}SAMPLE_ENV{{/fnc.env}}',
55
54
  VARIABLE: '{{msg.scriptingMemory.variable}}',
56
55
  PROJECTNAME: '{{fnc.projectname}}',
@@ -91,11 +90,11 @@ const myCapsHookBase = {
91
90
  [Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: ['$']
92
91
  }
93
92
  const myCapsRequestHookFromString = Object.assign({
94
- [Capabilities.SIMPLEREST_REQUEST_HOOK]: `
93
+ [Capabilities.SIMPLEREST_REQUEST_HOOK]: ({ requestOptions, context }) => {
95
94
  let counter = 1
96
- requestOptions.body = {bodyFieldRequestHook: counter++}
95
+ requestOptions.body = { bodyFieldRequestHook: counter++ }
97
96
  context.contextFieldRequestHook = counter
98
- `
97
+ }
99
98
  }, myCapsHookBase)
100
99
  const myCapsRequestHookFromStringInvalid = Object.assign({
101
100
  [Capabilities.SIMPLEREST_REQUEST_HOOK]: '!'
@@ -108,12 +107,13 @@ const myCapsRequestHookFromFunction = Object.assign({
108
107
  }
109
108
  }, myCapsHookBase)
110
109
  const myCapsRequestHookFromModule = Object.assign({
111
- [Capabilities.SIMPLEREST_REQUEST_HOOK]: 'test/connectors/logicHook.js'
110
+ [Capabilities.SAFEDIR]: './test/connectors/',
111
+ [Capabilities.SIMPLEREST_REQUEST_HOOK]: 'logicHook.js'
112
112
  }, myCapsHookBase)
113
113
  const myCapsResponseHook = Object.assign({
114
- [Capabilities.SIMPLEREST_RESPONSE_HOOK]: `
115
- botMsg.messageText = 'message text from hook'
116
- `
114
+ [Capabilities.SIMPLEREST_RESPONSE_HOOK]: ({ botMsg }) => {
115
+ botMsg.messageText = 'message text from hook'
116
+ }
117
117
  }, myCapsHookBase)
118
118
 
119
119
  const msg = {
@@ -460,9 +460,6 @@ describe('connectors.simplerest', function () {
460
460
  assert.exists(request.body.SAMPLE_ENV)
461
461
  assert.equal(request.body.SAMPLE_ENV, 'SAMPLE_ENV')
462
462
 
463
- assert.exists(request.body.USING_CODE)
464
- assert.equal(request.body.USING_CODE, 3)
465
-
466
463
  assert.exists(request.body.VARIABLE)
467
464
  assert.equal(request.body.VARIABLE, 'varvalue')
468
465
 
@@ -519,13 +516,13 @@ describe('connectors.simplerest', function () {
519
516
  it('should use request hook, from module', async function () {
520
517
  await _assertHook(Object.assign({}, myCapsRequestHookFromModule))
521
518
  })
522
- it('should use request hook, from invalid string', async function () {
519
+ it('should reject request hook, from invalid string', async function () {
523
520
  const driver = new BotDriver(myCapsRequestHookFromStringInvalid)
524
521
  try {
525
522
  await driver.Build()
526
523
  assert.fail('it should have failed')
527
524
  } catch (err) {
528
- assert.isTrue(err.message.includes('Cant load hook, syntax is not valid'))
525
+ assert.isTrue(err.message.includes('Hook specification "\'!\'" invalid'))
529
526
  }
530
527
  })
531
528
  it('should add query params from UPDATE_CUSTOM (without "?")', async function () {
@@ -741,9 +738,9 @@ describe('connectors.simplerest', function () {
741
738
  const myCaps = Object.assign({}, myCapsGet, {
742
739
  [Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: '$.text',
743
740
  [Capabilities.SIMPLEREST_MEDIA_JSONPATH]: '$.media',
744
- [Capabilities.SIMPLEREST_RESPONSE_HOOK]: `
745
- botMsg.nlp = { intent: { name: 'hugo' } }
746
- `,
741
+ [Capabilities.SIMPLEREST_RESPONSE_HOOK]: ({ botMsg }) => {
742
+ botMsg.nlp = { intent: { name: 'hugo' } }
743
+ },
747
744
  [Capabilities.SIMPLEREST_IGNORE_EMPTY]: true
748
745
  })
749
746
  const driver = new BotDriver(myCaps)
@@ -764,9 +761,9 @@ describe('connectors.simplerest', function () {
764
761
  const myCaps = Object.assign({}, myCapsGet, {
765
762
  [Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: '$.text',
766
763
  [Capabilities.SIMPLEREST_MEDIA_JSONPATH]: '$.media',
767
- [Capabilities.SIMPLEREST_RESPONSE_HOOK]: `
768
- botMsg.someextradata = 'message text from hook'
769
- `,
764
+ [Capabilities.SIMPLEREST_RESPONSE_HOOK]: ({ botMsg }) => {
765
+ botMsg.someextradata = 'message text from hook'
766
+ },
770
767
  [Capabilities.SIMPLEREST_IGNORE_EMPTY]: true
771
768
  })
772
769
  const driver = new BotDriver(myCaps)
@@ -787,9 +784,9 @@ describe('connectors.simplerest', function () {
787
784
  const myCaps = Object.assign({}, myCapsGet, {
788
785
  [Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: '$.text',
789
786
  [Capabilities.SIMPLEREST_MEDIA_JSONPATH]: '$.media',
790
- [Capabilities.SIMPLEREST_RESPONSE_HOOK]: `
791
- botMsg.messageText = 'message text from hook'
792
- `,
787
+ [Capabilities.SIMPLEREST_RESPONSE_HOOK]: ({ botMsg }) => {
788
+ botMsg.messageText = 'message text from hook'
789
+ },
793
790
  [Capabilities.SIMPLEREST_IGNORE_EMPTY]: true
794
791
  })
795
792
  const driver = new BotDriver(myCaps)
@@ -1061,7 +1058,7 @@ describe('connectors.simplerest', function () {
1061
1058
  await this.init({
1062
1059
  [Capabilities.SIMPLEREST_PING_URL]: 'https://mock.com/pingencoded',
1063
1060
  [Capabilities.SIMPLEREST_PING_PROCESS_RESPONSE]: true,
1064
- [Capabilities.SIMPLEREST_PARSER_HOOK]: 'body.text = JSON.parse(body.text).prop'
1061
+ [Capabilities.SIMPLEREST_PARSER_HOOK]: ({ body }) => { body.text = JSON.parse(body.text).prop }
1065
1062
  })
1066
1063
 
1067
1064
  this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'responsefromping.convo.txt')
@@ -1074,7 +1071,7 @@ describe('connectors.simplerest', function () {
1074
1071
  await this.init({
1075
1072
  [Capabilities.SIMPLEREST_PING_URL]: 'https://mock.com/pingstring',
1076
1073
  [Capabilities.SIMPLEREST_PING_PROCESS_RESPONSE]: true,
1077
- [Capabilities.SIMPLEREST_PARSER_HOOK]: 'changeBody({ text: body })'
1074
+ [Capabilities.SIMPLEREST_PARSER_HOOK]: ({ changeBody, body }) => changeBody({ text: body })
1078
1075
  })
1079
1076
 
1080
1077
  this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'responsefromping.convo.txt')
@@ -1114,7 +1111,7 @@ describe('connectors.simplerest', function () {
1114
1111
  await this.init({
1115
1112
  [Capabilities.SIMPLEREST_START_URL]: 'https://mock.com/startencoded',
1116
1113
  [Capabilities.SIMPLEREST_START_PROCESS_RESPONSE]: true,
1117
- [Capabilities.SIMPLEREST_PARSER_HOOK]: 'body.text = JSON.parse(body.text).prop'
1114
+ [Capabilities.SIMPLEREST_PARSER_HOOK]: ({ body }) => { body.text = JSON.parse(body.text).prop }
1118
1115
  })
1119
1116
 
1120
1117
  this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'responsefromstart.convo.txt')
@@ -1127,7 +1124,7 @@ describe('connectors.simplerest', function () {
1127
1124
  await this.init({
1128
1125
  [Capabilities.SIMPLEREST_START_URL]: 'https://mock.com/startstring',
1129
1126
  [Capabilities.SIMPLEREST_START_PROCESS_RESPONSE]: true,
1130
- [Capabilities.SIMPLEREST_PARSER_HOOK]: 'changeBody({ text: body })'
1127
+ [Capabilities.SIMPLEREST_PARSER_HOOK]: ({ changeBody, body }) => changeBody({ text: body })
1131
1128
  })
1132
1129
 
1133
1130
  this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'responsefromstart.convo.txt')
@@ -1283,7 +1280,7 @@ describe('connectors.simplerest', function () {
1283
1280
  [Capabilities.SIMPLEREST_URL]: () => 'https://mock.com/endpoint',
1284
1281
  [Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: () => ['$.text'],
1285
1282
  [Capabilities.SIMPLEREST_POLL_URL]: () => 'https://mock.com/poll',
1286
- [Capabilities.SIMPLEREST_POLL_REQUEST_HOOK]: 'requestOptions.uri = "https://mock.com/_from_hook"'
1283
+ [Capabilities.SIMPLEREST_POLL_REQUEST_HOOK]: ({ requestOptions }) => { requestOptions.uri = 'https://mock.com/_from_hook' }
1287
1284
  }
1288
1285
  const scope = nock('https://mock.com')
1289
1286
  .get('/endpoint')
@@ -168,7 +168,7 @@ describe('convo.fillAndApplyScriptingMemory', function () {
168
168
  [Capabilities.PROJECTNAME]: 'convo.scriptingmemory',
169
169
  [Capabilities.CONTAINERMODE]: echoConnector,
170
170
  [Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
171
- [Capabilities.CUSTOMHOOK_ONBUILD]: 'module.exports = ({ container }) => { console.log("customhooks called"); container.caps.MYTOKEN = "test1234" }'
171
+ [Capabilities.CUSTOMHOOK_ONBUILD]: ({ container }) => { console.log('customhooks called'); container.caps.MYTOKEN = 'test1234' }
172
172
  }
173
173
  const driver = new BotDriver(myCaps)
174
174
  const compiler = driver.BuildCompiler()
@@ -847,52 +847,6 @@ describe('convo.fillAndApplyScriptingMemory', function () {
847
847
  assert(result.length === 36, '$uniqid invalid')
848
848
  })
849
849
 
850
- it('func', async function () {
851
- const result = ScriptingMemory.apply(
852
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
853
- {},
854
- '$func(3*5)'
855
- )
856
-
857
- assert(result === '15', 'func invalid')
858
- })
859
- it('func with caps', async function () {
860
- const result = ScriptingMemory.apply(
861
- { caps: Object.assign({}, CAPS_ENABLE_SCRIPTING_MEMORY, { mycap: 'botium' }) },
862
- {},
863
- '$func(caps.mycap)'
864
- )
865
- assert.equal(result, 'botium')
866
- })
867
- it('func invalid code', async function () {
868
- try {
869
- ScriptingMemory.apply(
870
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
871
- {},
872
- '$func(hugo123)'
873
- )
874
- assert.fail('should have failed')
875
- } catch (err) {
876
- assert.isTrue(err.message.indexOf('func function execution failed') >= 0)
877
- }
878
- })
879
- it('func environment variable', async function () {
880
- process.env.MY_VAR_VALUE = 'botium'
881
- const result = ScriptingMemory.apply(
882
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
883
- {},
884
- '$func(process.env.MY_VAR_VALUE)'
885
- )
886
- assert.equal(result, 'botium')
887
- })
888
- it('func with moment', async function () {
889
- const result = ScriptingMemory.apply(
890
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
891
- {},
892
- '$func(moment(\\).subtract(1, "month"\\).startOf("month"\\).format("DD.MM.YYYY"\\))'
893
- )
894
- assert.equal(result, moment().subtract(1, 'month').startOf('month').format('DD.MM.YYYY'))
895
- })
896
850
  it('environment variable', async function () {
897
851
  process.env.MY_VAR_VALUE = 'botium'
898
852
  const result = ScriptingMemory.apply(
@@ -65,28 +65,6 @@ describe('customhooks.hookfromsrc', function () {
65
65
  assert.isTrue(onStopCalled)
66
66
  assert.isTrue(onCleanCalled)
67
67
  })
68
- it('should call hooks from string function', async function () {
69
- const { container } = await buildDriver({
70
- [Capabilities.CUSTOMHOOK_ONBUILD]: 'module.exports = ({ container }) => { container.onBuildCalled = true }',
71
- [Capabilities.CUSTOMHOOK_ONSTART]: 'module.exports = ({ container }) => { container.onStartCalled = true }',
72
- [Capabilities.CUSTOMHOOK_ONUSERSAYS]: 'module.exports = ({ container }) => { container.onUserSaysCalled = true }',
73
- [Capabilities.CUSTOMHOOK_ONBOTRESPONSE]: 'module.exports = ({ container }) => { container.onBotResponseCalled = true }',
74
- [Capabilities.CUSTOMHOOK_ONSTOP]: 'module.exports = ({ container }) => { container.onStopCalled = true }',
75
- [Capabilities.CUSTOMHOOK_ONCLEAN]: 'module.exports = ({ container }) => { container.onCleanCalled = true }'
76
- })
77
- await container.Start()
78
- await container.UserSaysText('hallo')
79
- await container.WaitBotSays()
80
- await container.Stop()
81
- await container.Clean()
82
-
83
- assert.isTrue(container.onBuildCalled)
84
- assert.isTrue(container.onStartCalled)
85
- assert.isTrue(container.onUserSaysCalled)
86
- assert.isTrue(container.onBotResponseCalled)
87
- assert.isTrue(container.onStopCalled)
88
- assert.isTrue(container.onCleanCalled)
89
- })
90
68
  it('should change meMsg from hook', async function () {
91
69
  const { container } = await buildDriver({
92
70
  [Capabilities.CUSTOMHOOK_ONUSERSAYS]: ({ meMsg }) => {
@@ -115,7 +93,7 @@ describe('customhooks.hookfromsrc', function () {
115
93
 
116
94
  assert.equal(botMsg.fromHook, 1)
117
95
  })
118
- it('should call http api from string function', async function () {
96
+ it('should call http api from function', async function () {
119
97
  const scope = nock('https://gettoken.com')
120
98
  .get('/get')
121
99
  .reply(200, {
@@ -124,7 +102,7 @@ describe('customhooks.hookfromsrc', function () {
124
102
  .persist()
125
103
 
126
104
  const { container } = await buildDriver({
127
- [Capabilities.CUSTOMHOOK_ONSTART]: `module.exports = async ({ container, request }) => {
105
+ [Capabilities.CUSTOMHOOK_ONSTART]: async ({ container, request }) => {
128
106
  return new Promise((resolve, reject) => {
129
107
  request({ method: 'get', uri: 'https://gettoken.com/get', json: true }, (err, response, body) => {
130
108
  if (err) return reject(err)
@@ -132,7 +110,7 @@ describe('customhooks.hookfromsrc', function () {
132
110
  resolve()
133
111
  })
134
112
  })
135
- }`
113
+ }
136
114
  })
137
115
  await container.Start()
138
116
  assert.equal(container.caps.MYTOKEN, 'thisisausertoken')
@@ -36,7 +36,13 @@ describe('logichooks.hookfromsrc', function () {
36
36
  [Capabilities.ASSERTERS]: [{
37
37
  ref: 'CUSTOMASSERTER',
38
38
  src: {
39
- assertConvoStep: 'if (botMsg.messageText === "Hello") result=Promise.resolve(); else result=Promise.reject(new Error("expected Hello"))'
39
+ assertConvoStep: ({ botMsg }) => {
40
+ if (botMsg.messageText === 'Hello') {
41
+ return Promise.resolve()
42
+ } else {
43
+ return Promise.reject(new Error('expected Hello'))
44
+ }
45
+ }
40
46
  }
41
47
  }]
42
48
  })
@@ -48,7 +54,10 @@ describe('logichooks.hookfromsrc', function () {
48
54
  [Capabilities.ASSERTERS]: [{
49
55
  ref: 'CUSTOMASSERTER',
50
56
  src: {
51
- assertConvoStep: 'if (botMsg.messageText === "Hello1") module.exports=Promise.resolve(); else module.exports=Promise.reject(new Error("expected Hello1"))'
57
+ assertConvoStep: ({ botMsg }) => {
58
+ if (botMsg.messageText === 'Hello1') return Promise.resolve()
59
+ else return Promise.reject(new Error('expected Hello1'))
60
+ }
52
61
  }
53
62
  }]
54
63
  })
@@ -74,7 +83,8 @@ describe('logichooks.hookfromsrc', function () {
74
83
  await compiler.convos[0].Run(container)
75
84
  assert.fail('it should have failed')
76
85
  } catch (err) {
77
- assert.isTrue(err.message.includes('Line 6: assertion error - Script assertConvoStep is not valid'))
86
+ console.log(err.message)
87
+ assert.isTrue(err.message.includes('Line 6: assertion error - Script assertConvoStep is not valid - only functions accepted'))
78
88
  }
79
89
  })
80
90
  })
@@ -27,7 +27,7 @@ describe('plugins.plugins', function () {
27
27
  })
28
28
 
29
29
  describe('load', function () {
30
- it('should map simple function to class', async function () {
30
+ it('should map simple function from module to class', async function () {
31
31
  const myCaps = {
32
32
  [Capabilities.PROJECTNAME]: 'plugins.load',
33
33
  [Capabilities.CONTAINERMODE]: 'fromfile1'
@@ -39,7 +39,20 @@ describe('plugins.plugins', function () {
39
39
  const response = await container.WaitBotSays()
40
40
  assert.equal(response.messageText, 'TEST')
41
41
  })
42
- it('should use UserSays function as class', async function () {
42
+ it('should map simple function from file to class', async function () {
43
+ const myCaps = {
44
+ [Capabilities.PROJECTNAME]: 'plugins.load',
45
+ [Capabilities.SAFEDIR]: './test/plugins/plugindir',
46
+ [Capabilities.CONTAINERMODE]: 'fromfile/botium-connector-fromfile1.js'
47
+ }
48
+ const driver = new BotDriver(myCaps)
49
+ const container = await driver.Build()
50
+
51
+ await container.UserSays({ messageText: 'TEST' })
52
+ const response = await container.WaitBotSays()
53
+ assert.equal(response.messageText, 'TEST')
54
+ })
55
+ it('should use UserSays function from module as class', async function () {
43
56
  const myCaps = {
44
57
  [Capabilities.PROJECTNAME]: 'plugins.load',
45
58
  [Capabilities.CONTAINERMODE]: 'fromfile2',
@@ -48,6 +61,20 @@ describe('plugins.plugins', function () {
48
61
  const driver = new BotDriver(myCaps)
49
62
  const container = await driver.Build()
50
63
 
64
+ await container.UserSays({ messageText: 'TEST' })
65
+ const response = await container.WaitBotSays()
66
+ assert.equal(response.messageText, 'MYPREFIX:TEST')
67
+ })
68
+ it('should use UserSays function from file as class', async function () {
69
+ const myCaps = {
70
+ [Capabilities.PROJECTNAME]: 'plugins.load',
71
+ [Capabilities.SAFEDIR]: './test/plugins/plugindir',
72
+ [Capabilities.CONTAINERMODE]: 'fromfile/botium-connector-fromfile2.js',
73
+ cap1: 'MYPREFIX'
74
+ }
75
+ const driver = new BotDriver(myCaps)
76
+ const container = await driver.Build()
77
+
51
78
  await container.UserSays({ messageText: 'TEST' })
52
79
  const response = await container.WaitBotSays()
53
80
  assert.equal(response.messageText, 'MYPREFIX:TEST')