botium-core 1.14.1 → 1.14.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 (30) hide show
  1. package/dist/botium-cjs.js +268 -77
  2. package/dist/botium-cjs.js.map +1 -1
  3. package/dist/botium-es.js +268 -77
  4. package/dist/botium-es.js.map +1 -1
  5. package/package.json +11 -11
  6. package/src/Capabilities.js +2 -0
  7. package/src/scripting/BotiumError.js +40 -3
  8. package/src/scripting/Convo.js +113 -19
  9. package/src/scripting/ScriptingMemory.js +7 -0
  10. package/src/scripting/ScriptingProvider.js +79 -30
  11. package/src/scripting/logichook/LogicHookConsts.js +5 -2
  12. package/src/scripting/logichook/LogicHookUtils.js +8 -6
  13. package/src/scripting/logichook/logichooks/ConvoStepParametersLogicHook.js +6 -0
  14. package/src/scripting/logichook/logichooks/OrderedListToButtonLogicHook.js +37 -0
  15. package/test/convo/fillAndApplyScriptingMemory.spec.js +11 -0
  16. package/test/logichooks/orderedListToButton.spec.js +35 -0
  17. package/test/scripting/asserters/convoStepParameters.spec.js +140 -0
  18. package/test/scripting/asserters/convos/TEXT_GOOD.convo.txt +6 -0
  19. package/test/scripting/asserters/convos/convo_step_parameter_matchmode_failed.convo.txt +8 -0
  20. package/test/scripting/asserters/convos/convo_step_parameter_retry_asserters_all_good.convo.txt +9 -0
  21. package/test/scripting/asserters/convos/convo_step_parameter_retry_asserters_botium_timeout.convo.txt +9 -0
  22. package/test/scripting/asserters/convos/convo_step_parameter_retry_asserters_good.convo.txt +9 -0
  23. package/test/scripting/asserters/convos/convo_step_parameter_retry_asserters_good_global.convo.txt +9 -0
  24. package/test/scripting/asserters/convos/convo_step_parameter_retry_main_and_asserter.convo.txt +10 -0
  25. package/test/scripting/asserters/convos/convo_step_parameter_retry_main_botium_timeout.convo.txt +9 -0
  26. package/test/scripting/asserters/convos/convo_step_parameter_retry_main_but_no_button.convo.txt +10 -0
  27. package/test/scripting/asserters/convos/convo_step_parameter_retry_main_good.convo.txt +9 -0
  28. package/test/scripting/asserters/convos/convo_step_parameter_retry_main_good_begin.convo.txt +11 -0
  29. package/test/scripting/matching/matchingmode.spec.js +4 -1
  30. package/test/scripting/scriptingProvider.spec.js +38 -12
@@ -0,0 +1,37 @@
1
+ const _ = require('lodash')
2
+ const PATTERN = '^\\s*(\\d+)\\.'
3
+ const debug = require('debug')('botium-core-OrderedListToButtonLogicHook')
4
+
5
+ module.exports = class OrderedListToButtonLogicHook {
6
+ constructor (context, caps = {}, globalArgs = {}) {
7
+ this.context = context
8
+ this.caps = caps
9
+ this.globalArgs = globalArgs
10
+ }
11
+
12
+ onBotPrepare ({ botMsg, args }) {
13
+ const pattern = args?.[0] || this.globalArgs?.pattern || PATTERN
14
+ let regexp
15
+ try {
16
+ regexp = new RegExp(pattern, 'gm')
17
+ } catch (err) {
18
+ throw new Error(`OrderedListToButtonLogicHook: regex is not valid: ${pattern} ${err.messageText}`)
19
+ }
20
+ const buttons = []
21
+ if (botMsg.messageText && _.isString(botMsg.messageText)) {
22
+ const matches = botMsg.messageText.matchAll(regexp)
23
+
24
+ for (const match of matches) {
25
+ if (match && match[1]) {
26
+ buttons.push({ text: match[1], payload: match[1] })
27
+ }
28
+ }
29
+ } else {
30
+ debug(`ConditionalBusinessHoursLogicHook onBotPrepare, msg has no messageText to check ${JSON.stringify(botMsg)}`)
31
+ }
32
+
33
+ if (buttons.length) {
34
+ botMsg.buttons = [...(botMsg.buttons || []), ...buttons]
35
+ }
36
+ }
37
+ }
@@ -817,6 +817,17 @@ describe('convo.fillAndApplyScriptingMemory', function () {
817
817
 
818
818
  assert.equal(result, moment().subtract(1, 'month').format('YYYY.MM.DD'))
819
819
  })
820
+ it('date_add_dynamic', async function () {
821
+ const result = ScriptingMemory.apply(
822
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
823
+ {
824
+ days: 2
825
+ },
826
+ '$date_add($days, "day", YYYY.MM.DD)'
827
+ )
828
+
829
+ assert.equal(result, moment().add(2, 'day').format('YYYY.MM.DD'))
830
+ })
820
831
 
821
832
  it('random', async function () {
822
833
  const result = ScriptingMemory.apply(
@@ -0,0 +1,35 @@
1
+ const assert = require('chai').assert
2
+
3
+ const OrderedListToButtonLogicHook = require('../../src/scripting/logichook/logichooks/OrderedListToButtonLogicHook')
4
+
5
+ describe('logichooks.orderedListToButton', function () {
6
+ it('should convert ordered list to buttons', async function () {
7
+ const orderedListToButtonLogicHook = new OrderedListToButtonLogicHook()
8
+ const botMsg = {
9
+ messageText: `0. sometext.
10
+ 1.
11
+ 2.
12
+ 3.sdfdsf
13
+ 4. 3 days per week
14
+ 5.2.2
15
+ 6. 2.dfsdf
16
+ 7777.
17
+ 88euro
18
+ `,
19
+
20
+ buttons: [{ payload: 'existingButtonPayload', text: 'existingButtonText' }]
21
+ }
22
+
23
+ orderedListToButtonLogicHook.onBotPrepare({ botMsg })
24
+ assert.equal(botMsg.buttons?.length, 9)
25
+ assert.deepEqual(botMsg.buttons[0], { payload: 'existingButtonPayload', text: 'existingButtonText' })
26
+ assert.deepEqual(botMsg.buttons[1], { payload: '0', text: '0' })
27
+ assert.deepEqual(botMsg.buttons[2], { payload: '1', text: '1' })
28
+ assert.deepEqual(botMsg.buttons[3], { payload: '2', text: '2' })
29
+ assert.deepEqual(botMsg.buttons[4], { payload: '3', text: '3' })
30
+ assert.deepEqual(botMsg.buttons[5], { payload: '4', text: '4' })
31
+ assert.deepEqual(botMsg.buttons[6], { payload: '5', text: '5' })
32
+ assert.deepEqual(botMsg.buttons[7], { payload: '6', text: '6' })
33
+ assert.deepEqual(botMsg.buttons[8], { payload: '7777', text: '7777' })
34
+ })
35
+ })
@@ -0,0 +1,140 @@
1
+ const path = require('path')
2
+ const assert = require('chai').assert
3
+ const BotDriver = require('../../../index').BotDriver
4
+ const Capabilities = require('../../../index').Capabilities
5
+ const debug = require('debug')('botium-test-logichooks-waitforbot')
6
+ const util = require('util')
7
+
8
+ const createEchoConnector = () => ({ queueBotSays, caps }) => {
9
+ return {
10
+ UserSays (msg) {
11
+ const _send = (msg, timeout) => {
12
+ const botMsg = { sender: 'bot', sourceData: msg.sourceData, messageText: `You said ${msg}` }
13
+ if (msg.toLowerCase().indexOf('button') >= 0) {
14
+ botMsg.buttons = [{ text: 'button1' }, { text: 'button2' }]
15
+ }
16
+ if (msg.toLowerCase().indexOf('intent') >= 0) {
17
+ botMsg.nlp = { intent: { name: 'someIntent', confidence: 0.5 } }
18
+ }
19
+ setTimeout(() => {
20
+ debug(`${prefix} Connector is sending message ${util.inspect(botMsg)}`)
21
+ return queueBotSays(botMsg)
22
+ }, timeout)
23
+ }
24
+
25
+ const prefix = `Testcase "${caps[Capabilities.PROJECTNAME]}"`
26
+ debug(`${prefix} Connector got message ${util.inspect(msg)}`)
27
+ if (msg.messageText) {
28
+ msg.messageText.split('\n').forEach((msgPart, i) => {
29
+ if (msgPart) {
30
+ _send(msgPart, i * 50)
31
+ }
32
+ })
33
+ }
34
+ }
35
+ }
36
+ }
37
+ describe('scripting.asserters.convoStepParametersForAssert', function () {
38
+ beforeEach(async function () {
39
+ const myCaps = {
40
+ [Capabilities.PROJECTNAME]: 'asserters.text',
41
+ [Capabilities.CONTAINERMODE]: createEchoConnector(),
42
+ [Capabilities.WAITFORBOTTIMEOUT]: 1000,
43
+ [Capabilities.SCRIPTING_ENABLE_MULTIPLE_ASSERT_ERRORS]: true,
44
+ [Capabilities.SCRIPTING_CONVO_STEP_PARAMETERS]: '{"ignoreNotMatchedBotResponses": {"timeout": 200, "asserters": ["INTENT"]}}'
45
+ }
46
+ const driver = new BotDriver(myCaps)
47
+ this.compiler = driver.BuildCompiler()
48
+ this.container = await driver.Build()
49
+ })
50
+ afterEach(async function () {
51
+ await this.container.Stop()
52
+ await this.container.Clean()
53
+ })
54
+
55
+ describe('scripting.asserters.convoStepParametersForAssert.matchmode', function () {
56
+ it('should not accept bad chatbot response on exact match defined on step', async function () {
57
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convo_step_parameter_matchmode_failed.convo.txt')
58
+ assert.equal(this.compiler.convos.length, 1)
59
+
60
+ try {
61
+ await this.compiler.convos[0].Run(this.container)
62
+ assert.fail('should have failed')
63
+ } catch (err) {
64
+ assert.isTrue(err.message.indexOf('"You said Hello" expected to match "Hello"') >= 0)
65
+ }
66
+ })
67
+ })
68
+
69
+ describe('scripting.asserters.convoStepParametersForAssert.retry', function () {
70
+ it('should retry until succesful main', async function () {
71
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convo_step_parameter_retry_main_good.convo.txt')
72
+ assert.equal(this.compiler.convos.length, 1)
73
+
74
+ await this.compiler.convos[0].Run(this.container)
75
+ })
76
+ it('should retry until succesful asserters', async function () {
77
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convo_step_parameter_retry_asserters_good.convo.txt')
78
+ assert.equal(this.compiler.convos.length, 1)
79
+
80
+ await this.compiler.convos[0].Run(this.container)
81
+ })
82
+ it('should retry until succesful asserters all', async function () {
83
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convo_step_parameter_retry_asserters_all_good.convo.txt')
84
+ assert.equal(this.compiler.convos.length, 1)
85
+
86
+ await this.compiler.convos[0].Run(this.container)
87
+ })
88
+ it('should retry until succesful main, configured in begin', async function () {
89
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convo_step_parameter_retry_main_good_begin.convo.txt')
90
+ assert.equal(this.compiler.convos.length, 1)
91
+
92
+ await this.compiler.convos[0].Run(this.container)
93
+ })
94
+ it('should retry until succesful asserters, configured by cap', async function () {
95
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convo_step_parameter_retry_asserters_good_global.convo.txt')
96
+ assert.equal(this.compiler.convos.length, 1)
97
+
98
+ await this.compiler.convos[0].Run(this.container)
99
+ })
100
+ it('should retry until timeout main', async function () {
101
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convo_step_parameter_retry_main_botium_timeout.convo.txt')
102
+ assert.equal(this.compiler.convos.length, 1)
103
+
104
+ try {
105
+ await this.compiler.convos[0].Run(this.container)
106
+ assert.fail('should have failed')
107
+ } catch (err) {
108
+ assert.isTrue(err.message.indexOf('error waiting for bot - Bot did not respond within 1s') >= 0)
109
+ }
110
+ })
111
+ it('should retry until timeout asserter', async function () {
112
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convo_step_parameter_retry_asserters_botium_timeout.convo.txt')
113
+ assert.equal(this.compiler.convos.length, 1)
114
+
115
+ try {
116
+ await this.compiler.convos[0].Run(this.container)
117
+ assert.fail('should have failed')
118
+ } catch (err) {
119
+ assert.isTrue(err.message.indexOf('error waiting for bot - Bot did not respond within 1s') >= 0)
120
+ }
121
+ })
122
+ it('should not retry on not retriable error', async function () {
123
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convo_step_parameter_retry_main_but_no_button.convo.txt')
124
+ assert.equal(this.compiler.convos.length, 1)
125
+
126
+ try {
127
+ await this.compiler.convos[0].Run(this.container)
128
+ assert.fail('should have failed')
129
+ } catch (err) {
130
+ assert.isTrue(err.message.indexOf('Expected button(s) with text "some not existing button"') >= 0)
131
+ }
132
+ })
133
+ it('should retry until every retriable is succesful', async function () {
134
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'convo_step_parameter_retry_main_and_asserter.convo.txt')
135
+ assert.equal(this.compiler.convos.length, 1)
136
+
137
+ await this.compiler.convos[0].Run(this.container)
138
+ })
139
+ })
140
+ })
@@ -0,0 +1,6 @@
1
+ TEXT_GOOD
2
+ #me
3
+ Hello1
4
+
5
+ #bot
6
+ TEXT You said Hello1
@@ -0,0 +1,8 @@
1
+ convo_step_parameter_matchmode_failed
2
+
3
+ #me
4
+ Hello
5
+
6
+ #bot
7
+ Hello
8
+ CONVO_STEP_PARAMETERS {"matchingMode":"equals"}
@@ -0,0 +1,9 @@
1
+ convo_step_parameter_retry_asserters_good
2
+
3
+ #me
4
+ Hello
5
+ Button
6
+
7
+ #bot
8
+ BUTTONS button1|button2
9
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "allAsserters": true}}
@@ -0,0 +1,9 @@
1
+ convo_step_parameter_retry_asserters_good
2
+
3
+ #me
4
+ Hello
5
+ Button
6
+
7
+ #bot
8
+ BUTTONS button1|buttonXXXXXX
9
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "asserters": ["BUTTONS"]}}
@@ -0,0 +1,9 @@
1
+ convo_step_parameter_retry_asserters_good
2
+
3
+ #me
4
+ Hello
5
+ Button
6
+
7
+ #bot
8
+ BUTTONS button1|button2
9
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "asserters": ["BUTTONS"]}}
@@ -0,0 +1,9 @@
1
+ convo_step_parameter_retry_asserters_good_global
2
+
3
+
4
+ #me
5
+ Hello1
6
+ Intent
7
+
8
+ #bot
9
+ INTENT someIntent
@@ -0,0 +1,10 @@
1
+ convo_step_parameter_retry_main_and_asserter
2
+
3
+ #me
4
+ Butt
5
+ Button
6
+
7
+ #bot
8
+ You said Butt
9
+ BUTTONS button1|button2
10
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "mainAsserter": true, "allAsserters": true}}
@@ -0,0 +1,9 @@
1
+ convo_step_parameter_retry_main_botium_timeout
2
+
3
+ #me
4
+ Hello1
5
+ Hello2
6
+
7
+ #bot
8
+ You said Hello3
9
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "mainAsserter": true}}
@@ -0,0 +1,10 @@
1
+ convo_step_parameter_retry_main_but_no_button
2
+
3
+ #me
4
+ Hello1
5
+ Hello2
6
+
7
+ #bot
8
+ You said Hello2
9
+ BUTTONS some not existing button
10
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "mainAsserter": true}}
@@ -0,0 +1,9 @@
1
+ convo_step_parameter_retry_main_good
2
+
3
+ #me
4
+ Hello1
5
+ Hello2
6
+
7
+ #bot
8
+ You said Hello2
9
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 201, "mainAsserter": true}}
@@ -0,0 +1,11 @@
1
+ convo_step_parameter_retry_main_good_begin
2
+
3
+ #begin
4
+ CONVO_STEP_PARAMETERS {"ignoreNotMatchedBotResponses": {"timeout": 200, "mainAsserter": true}}
5
+
6
+ #me
7
+ Hello1
8
+ Hello2
9
+
10
+ #bot
11
+ You said Hello2
@@ -207,7 +207,10 @@ describe('scripting.matching.matchingmode', function () {
207
207
  'umm',
208
208
  'interesting',
209
209
  'really?'
210
- ], 'test')
210
+ ],
211
+ 'test',
212
+ null,
213
+ {})
211
214
  })
212
215
  })
213
216
 
@@ -5,6 +5,7 @@ const { Convo } = require('../../src/scripting/Convo')
5
5
  const ScriptingProvider = require('../../src/scripting/ScriptingProvider')
6
6
  const DefaultCapabilities = require('../../src/Defaults').Capabilities
7
7
  const Capabilities = require('../../src/Capabilities')
8
+ const { LOGIC_HOOK_EVENTS } = require('../../src/scripting/logichook/LogicHookConsts')
8
9
 
9
10
  describe('scripting.scriptingProvider', function () {
10
11
  describe('ReadScriptsFromDirectory', function () {
@@ -65,7 +66,7 @@ describe('scripting.scriptingProvider', function () {
65
66
  assert.equal(tomatch.length, 2)
66
67
  assert.equal(tomatch[0], 'TEXT1')
67
68
  assert.equal(tomatch[1], 'TEXT2')
68
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatch, 'test1')
69
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatch, 'test1', null, {})
69
70
  })
70
71
  it('should resolve multiple utterance', async function () {
71
72
  const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
@@ -85,7 +86,7 @@ describe('scripting.scriptingProvider', function () {
85
86
  assert.equal(tomatchUtt1.length, 2)
86
87
  assert.equal(tomatchUtt1[0], 'TEXT1')
87
88
  assert.equal(tomatchUtt1[1], 'TEXT2')
88
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatchUtt1, 'test1')
89
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatchUtt1, 'test1', null, {})
89
90
  const tomatchUtt2 = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt2' })
90
91
  assert.isArray(tomatchUtt2)
91
92
  assert.equal(tomatchUtt2.length, 2)
@@ -121,7 +122,7 @@ describe('scripting.scriptingProvider', function () {
121
122
  assert.equal(tomatch.length, 1)
122
123
  assert.equal(tomatch[0], 'utt2')
123
124
  try {
124
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatch, 'test1')
125
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatch, 'test1', null, {})
125
126
  assert.fail('expected error')
126
127
  } catch (err) {
127
128
  assert.isTrue(err.message.indexOf('Bot response') > 0)
@@ -141,7 +142,7 @@ describe('scripting.scriptingProvider', function () {
141
142
  utterances: ['TEXT1', 'TEXT2']
142
143
  })
143
144
  try {
144
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1', 'utt1', 'test1')
145
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1', 'utt1', 'test1', null, {})
145
146
  assert.fail('expected error')
146
147
  } catch (err) {
147
148
  assert.isTrue(err.message.indexOf('Bot response') > 0)
@@ -166,7 +167,7 @@ describe('scripting.scriptingProvider', function () {
166
167
  assert.equal(tomatch.length, 2)
167
168
  assert.equal(tomatch[0], 'TEXT1 hello')
168
169
  assert.equal(tomatch[1], 'TEXT2 hello')
169
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1 hello', tomatch, 'test1')
170
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1 hello', tomatch, 'test1', null, {})
170
171
  })
171
172
  it('should resolve and append utterance args', async function () {
172
173
  const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
@@ -182,7 +183,7 @@ describe('scripting.scriptingProvider', function () {
182
183
  assert.equal(tomatch.length, 2)
183
184
  assert.equal(tomatch[0], 'TEXT1 hello')
184
185
  assert.equal(tomatch[1], 'TEXT2 hello')
185
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1 hello', tomatch, 'test1')
186
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1 hello', tomatch, 'test1', null, {})
186
187
  })
187
188
 
188
189
  describe('should resolve utterance with ambiguous scripting memory variable (with a debug message)', function () {
@@ -909,7 +910,7 @@ describe('scripting.scriptingProvider', function () {
909
910
  await scriptingProvider.Build()
910
911
  const scriptingContext = scriptingProvider._buildScriptContext()
911
912
  try {
912
- scriptingContext.scriptingEvents.assertBotResponse('actual', 'expected', 'test1')
913
+ scriptingContext.scriptingEvents.assertBotResponse('actual', 'expected', 'test1', null, {})
913
914
  assert.fail('expected error')
914
915
  } catch (err) {
915
916
  assert.equal(err.message, 'test1: Bot response "actual" expected to match "expected"')
@@ -920,7 +921,7 @@ describe('scripting.scriptingProvider', function () {
920
921
  await scriptingProvider.Build()
921
922
  const scriptingContext = scriptingProvider._buildScriptContext()
922
923
  try {
923
- scriptingContext.scriptingEvents.assertBotResponse(null, 'expected', 'test1')
924
+ scriptingContext.scriptingEvents.assertBotResponse(null, 'expected', 'test1', null, {})
924
925
  assert.fail('expected error')
925
926
  } catch (err) {
926
927
  assert.equal(err.message, 'test1: Bot response <no response> expected to match "expected"')
@@ -931,7 +932,7 @@ describe('scripting.scriptingProvider', function () {
931
932
  await scriptingProvider.Build()
932
933
  const scriptingContext = scriptingProvider._buildScriptContext()
933
934
  try {
934
- scriptingContext.scriptingEvents.assertBotResponse('actual', ['expected1', 'expected2'], 'test1')
935
+ scriptingContext.scriptingEvents.assertBotResponse('actual', ['expected1', 'expected2'], 'test1', null, {})
935
936
  assert.fail('expected error')
936
937
  } catch (err) {
937
938
  assert.equal(err.message, 'test1: Bot response "actual" expected to match one of "expected1", "expected2"')
@@ -945,7 +946,7 @@ describe('scripting.scriptingProvider', function () {
945
946
  await scriptingProvider.Build()
946
947
  const scriptingContext = scriptingProvider._buildScriptContext()
947
948
  try {
948
- scriptingContext.scriptingEvents.assertBotNotResponse('Keine Antwort gefunden!', ['Keine Antwort gefunden'], 'test1')
949
+ scriptingContext.scriptingEvents.assertBotNotResponse('Keine Antwort gefunden!', ['Keine Antwort gefunden'], 'test1', null, {})
949
950
  assert.fail('expected error')
950
951
  } catch (err) {
951
952
  assert.equal(err.message, 'test1: Bot response "Keine Antwort gefunden!" expected NOT to match "Keine Antwort gefunden"')
@@ -956,7 +957,7 @@ describe('scripting.scriptingProvider', function () {
956
957
  await scriptingProvider.Build()
957
958
  const scriptingContext = scriptingProvider._buildScriptContext()
958
959
  try {
959
- scriptingContext.scriptingEvents.assertBotNotResponse('Keine Antwort gefunden!', [''], 'test1')
960
+ scriptingContext.scriptingEvents.assertBotNotResponse('Keine Antwort gefunden!', [''], 'test1', null, {})
960
961
  assert.fail('expected error')
961
962
  } catch (err) {
962
963
  assert.equal(err.message, 'test1: Bot response "Keine Antwort gefunden!" expected NOT to match <any response>')
@@ -967,11 +968,36 @@ describe('scripting.scriptingProvider', function () {
967
968
  await scriptingProvider.Build()
968
969
  const scriptingContext = scriptingProvider._buildScriptContext()
969
970
  try {
970
- scriptingContext.scriptingEvents.assertBotNotResponse('', [''], 'test1')
971
+ scriptingContext.scriptingEvents.assertBotNotResponse('', [''], 'test1', null, {})
971
972
  assert.fail('expected error')
972
973
  } catch (err) {
973
974
  assert.equal(err.message, 'test1: Bot response <no response> expected NOT to match <any response>')
974
975
  }
975
976
  })
976
977
  })
978
+
979
+ describe('should call logichooks and userinputs even if there is no convo (logichook from livechat, and crawler)', function () {
980
+ LOGIC_HOOK_EVENTS.forEach(async (eventName) => {
981
+ it(`Logichook, event: ${eventName}`, async function () {
982
+ const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities, {
983
+ [Capabilities.LOGIC_HOOKS]: [{
984
+ ref: 'SET_TEXT_FROM_HOOK',
985
+ src: {
986
+ [eventName]: ({ someobject, args }) => {
987
+ someobject.testAttribute = 'testAttributeValue'
988
+ }
989
+ },
990
+ global: true
991
+ }]
992
+ }))
993
+ await scriptingProvider.Build()
994
+ const scriptingContext = scriptingProvider._buildScriptContext()
995
+ const someobject = {}
996
+ await scriptingContext.scriptingEvents[eventName]({
997
+ someobject
998
+ })
999
+ assert.equal(someobject.testAttribute, 'testAttributeValue')
1000
+ })
1001
+ })
1002
+ })
977
1003
  })