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.
Files changed (54) hide show
  1. package/.eslintrc.js +6 -3
  2. package/dist/botium-cjs.js +214 -61
  3. package/dist/botium-cjs.js.map +1 -1
  4. package/dist/botium-es.js +213 -61
  5. package/dist/botium-es.js.map +1 -1
  6. package/package.json +3 -1
  7. package/src/Capabilities.js +2 -1
  8. package/src/containers/plugins/SimpleRestContainer.js +20 -16
  9. package/src/grid/inbound/proxy.js +2 -1
  10. package/src/scripting/Convo.js +16 -10
  11. package/src/scripting/MatchFunctions.js +10 -0
  12. package/src/scripting/ScriptingProvider.js +106 -37
  13. package/src/scripting/logichook/LogicHookConsts.js +1 -1
  14. package/src/scripting/logichook/asserter/WerAsserter.js +59 -0
  15. package/src/scripting/logichook/logichooks/UpdateCustomLogicHook.js +3 -2
  16. package/test/compiler/compilercsv.spec.js +104 -3
  17. package/test/compiler/compilerjson.spec.js +0 -2
  18. package/test/compiler/compilerxlsx.spec.js +1 -1
  19. package/test/compiler/convos/csv/utterances_liveperson2.csv +12 -0
  20. package/test/connectors/simplerest.spec.js +1012 -969
  21. package/test/convo/fillAndApplyScriptingMemory.spec.js +804 -785
  22. package/test/convo/partialconvo.spec.js +345 -339
  23. package/test/driver/capabilities.spec.js +156 -151
  24. package/test/logichooks/hookfromsrc.spec.js +79 -73
  25. package/test/plugins/plugins.spec.js +44 -42
  26. package/test/scripting/asserters/buttonsAsserter.spec.js +257 -240
  27. package/test/scripting/asserters/cardsAsserter.spec.js +214 -212
  28. package/test/scripting/asserters/convos/wer_threshold_nok.yml +7 -0
  29. package/test/scripting/asserters/convos/wer_threshold_ok.yml +7 -0
  30. package/test/scripting/asserters/intentConfidenceAsserter.spec.js +34 -35
  31. package/test/scripting/asserters/jsonpathAsserter.spec.js +307 -308
  32. package/test/scripting/asserters/mediaAsserter.spec.js +236 -234
  33. package/test/scripting/asserters/werAsserter.spec.js +51 -0
  34. package/test/scripting/logichooks/setClearScriptingMemory.spec.js +202 -192
  35. package/test/scripting/matching/matchingmode.spec.js +306 -258
  36. package/test/scripting/scriptingProvider.spec.js +666 -633
  37. package/test/scripting/scriptingmemory/fillScriptingMemoryFromFile.spec.js +299 -281
  38. package/test/scripting/scriptingmemory/useScriptingMemoryForAssertion.spec.js +94 -80
  39. package/test/scripting/userinputs/defaultUserInputs.spec.js +233 -127
  40. package/test/scripting/userinputs/mediaInputConvos.spec.js +409 -403
  41. package/test/scripting/utteranceexpansion/associateByIndex.spec.js +259 -0
  42. package/test/scripting/utteranceexpansion/convos/associate_utterances_by_index.json +33 -0
  43. package/test/scripting/utteranceexpansion/convos/media.convo.txt +19 -0
  44. package/test/scripting/utteranceexpansion/files/step0voice0.wav +0 -0
  45. package/test/scripting/utteranceexpansion/files/step0voice1.wav +0 -0
  46. package/test/scripting/utteranceexpansion/files/step0voice2.wav +0 -0
  47. package/test/scripting/utteranceexpansion/files/step1voice0.wav +0 -0
  48. package/test/scripting/utteranceexpansion/files/step2voice0.wav +0 -0
  49. package/test/scripting/utteranceexpansion/files/step2voice1.wav +0 -0
  50. package/test/scripting/utteranceexpansion/files/step2voice2.wav +0 -0
  51. package/test/scripting/utteranceexpansion/files/step2voice4.wav +0 -0
  52. package/test/scripting/utteranceexpansion/files/step2voice5.wav +0 -0
  53. package/test/security/allowUnsafe.spec.js +274 -268
  54. package/test/utils.spec.js +40 -38
@@ -18,866 +18,885 @@ const CAPS_ENABLE_SCRIPTING_MEMORY = {
18
18
  const echoConnector = ({ queueBotSays }) => {
19
19
  return {
20
20
  UserSays (msg) {
21
- const botMsg = { sender: 'bot', sourceData: msg.sourceData, messageText: msg.messageText }
21
+ const botMsg = {
22
+ sender: 'bot',
23
+ sourceData: msg.sourceData,
24
+ messageText: msg.messageText
25
+ }
22
26
  queueBotSays(botMsg)
23
27
  }
24
28
  }
25
29
  }
26
30
 
27
- it('scripting memory function as asserter', async function () {
28
- const myCaps = {
29
- [Capabilities.PROJECTNAME]: 'convo.scriptingmemory',
30
- [Capabilities.CONTAINERMODE]: ({ queueBotSays }) => {
31
- return {
32
- UserSays (msg) {
33
- const botMsg = { sender: 'bot', sourceData: msg.sourceData, messageText: new Date().toLocaleDateString() }
34
- queueBotSays(botMsg)
35
- }
36
- }
37
- },
38
- [Capabilities.SCRIPTING_ENABLE_MEMORY]: true
39
- }
40
- const driver = new BotDriver(myCaps)
41
- const compiler = driver.BuildCompiler()
42
- const container = await driver.Build()
43
-
44
- compiler.ReadScript(path.resolve(__dirname, 'convos'), 'assert_date.convo.txt')
45
- assert.equal(compiler.convos.length, 1)
46
- await compiler.convos[0].Run(container)
47
-
48
- container && await container.Clean()
49
- })
50
-
51
- describe('convo.scriptingmemory.convos', function () {
52
- beforeEach(async function () {
53
- const myCaps = {
54
- [Capabilities.PROJECTNAME]: 'convo.scriptingmemory',
55
- [Capabilities.CONTAINERMODE]: echoConnector,
56
- [Capabilities.SCRIPTING_ENABLE_MEMORY]: true
57
- }
58
- const driver = new BotDriver(myCaps)
59
- this.compiler = driver.BuildCompiler()
60
- this.container = await driver.Build()
61
- })
62
- afterEach(async function () {
63
- this.container && await this.container.Clean()
64
- })
65
-
66
- it('should fill scripting memory from convo file', async function () {
67
- this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'memory.convo.txt')
68
- assert.equal(this.compiler.convos.length, 1)
69
-
70
- const transcript = await this.compiler.convos[0].Run(this.container)
71
- assert.isObject(transcript.scriptingMemory)
72
- assert.isDefined(transcript.scriptingMemory.$myvar)
73
- assert.equal(transcript.scriptingMemory.$myvar, 'VARVALUE')
74
- })
75
- it('should fill scripting memory from utterances file', async function () {
76
- this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'utt_memory.convo.txt')
77
- assert.equal(this.compiler.convos.length, 1)
78
- this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'utt_memory.utterances.txt')
79
- assert.isDefined(this.compiler.utterances.AGE_UTT)
80
-
81
- const transcript = await this.compiler.convos[0].Run(this.container)
82
- assert.isObject(transcript.scriptingMemory)
83
- assert.equal(transcript.scriptingMemory.$years, '40')
84
- assert.equal(transcript.scriptingMemory.$months, '2')
85
- })
86
- it('should fail on invalid scripting memory', async function () {
87
- this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'memory_fail.convo.txt')
88
- assert.equal(this.compiler.convos.length, 1)
89
-
90
- try {
91
- await this.compiler.convos[0].Run(this.container)
92
- assert.fail('expected convo to fail')
93
- } catch (err) {
94
- assert.isTrue(err.message.indexOf('Bot response (on Line 9: #me - show var $myvar) "show var VARVALUE" expected to match "show var VARVALUEINVALID"') > 0)
95
- }
96
- })
97
- it('should normalize bot response', async function () {
98
- this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'memory_normalize.convo.txt')
99
- assert.equal(this.compiler.convos.length, 1)
100
-
101
- const transcript = await this.compiler.convos[0].Run(this.container)
102
- assert.isObject(transcript.scriptingMemory)
103
- assert.isDefined(transcript.scriptingMemory.$state)
104
- assert.equal(transcript.scriptingMemory.$state, 'Kentucky')
105
- })
106
- it('should normalize bot response', async function () {
107
- this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'memory_dont_override_functions.convo.txt')
108
- assert.equal(this.compiler.convos.length, 1)
109
-
110
- const transcript = await this.compiler.convos[0].Run(this.container)
111
- assert.isObject(transcript.scriptingMemory)
112
- assert.isUndefined(transcript.scriptingMemory.$year)
113
- })
114
- it('should append multiline messages from scripting memory', async function () {
115
- this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'multiline.convo.txt')
116
- assert.equal(this.compiler.convos.length, 1)
117
-
118
- const transcript = await this.compiler.convos[0].Run(this.container)
119
- assert(transcript.steps[0].actual.messageText.split('\n')[1].startsWith('20'))
120
- assert(transcript.steps[1].actual.messageText.split('\n')[1].startsWith('20'))
121
- assert.isObject(transcript.scriptingMemory)
122
- assert.isDefined(transcript.scriptingMemory.$year_captured)
123
- assert.equal(transcript.scriptingMemory.$year_captured.length, 4)
124
- })
125
- })
126
-
127
- describe('convo.scriptingMemory.args', function () {
128
- it('should apply scripting memory to asserter args', async function () {
31
+ describe('convo.fillAndApplyScriptingMemory', function () {
32
+ it('scripting memory function as asserter', async function () {
129
33
  const myCaps = {
130
34
  [Capabilities.PROJECTNAME]: 'convo.scriptingmemory',
131
- [Capabilities.CONTAINERMODE]: echoConnector,
132
- [Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
133
- [Capabilities.ASSERTERS]: [
134
- {
135
- ref: 'CUSTOMASSERTER',
136
- src: {
137
- assertConvoStep: ({ botMsg, args }) => {
138
- assert.lengthOf(args, 2)
139
- assert.equal(args[0], 'question1')
140
- assert.equal(args[1], 'question2')
35
+ [Capabilities.CONTAINERMODE]: ({ queueBotSays }) => {
36
+ return {
37
+ UserSays (msg) {
38
+ const botMsg = {
39
+ sender: 'bot',
40
+ sourceData: msg.sourceData,
41
+ messageText: new Date().toLocaleDateString()
141
42
  }
43
+ queueBotSays(botMsg)
142
44
  }
143
45
  }
144
- ]
46
+ },
47
+ [Capabilities.SCRIPTING_ENABLE_MEMORY]: true
145
48
  }
146
49
  const driver = new BotDriver(myCaps)
147
50
  const compiler = driver.BuildCompiler()
148
51
  const container = await driver.Build()
149
52
 
150
- compiler.ReadScript(path.resolve(__dirname, 'convos'), 'applyscriptingmemorytoasserterargs.convo.txt')
53
+ compiler.ReadScript(path.resolve(__dirname, 'convos'), 'assert_date.convo.txt')
151
54
  assert.equal(compiler.convos.length, 1)
55
+ await compiler.convos[0].Run(container)
152
56
 
153
- const transcript = await compiler.convos[0].Run(container)
154
- assert.isObject(transcript.scriptingMemory)
57
+ container && await container.Clean()
155
58
  })
156
- })
157
59
 
158
- describe('convo.scriptingMemory.api', function () {
159
- describe('convo.scriptingMemory.api.fill', function () {
60
+ describe('convos', function () {
160
61
  beforeEach(async function () {
161
- this.containerStub = {
162
- caps: {
163
- [Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
164
- [Capabilities.SCRIPTING_NORMALIZE_TEXT]: true
165
- }
62
+ const myCaps = {
63
+ [Capabilities.PROJECTNAME]: 'convo.scriptingmemory',
64
+ [Capabilities.CONTAINERMODE]: echoConnector,
65
+ [Capabilities.SCRIPTING_ENABLE_MEMORY]: true
166
66
  }
167
- this.containerStubMatchingModeWord = {
168
- caps: {
169
- [Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
170
- [Capabilities.SCRIPTING_NORMALIZE_TEXT]: true,
171
- [Capabilities.SCRIPTING_MEMORY_MATCHING_MODE]: 'word'
172
- }
173
- }
174
- this.containerStubMatchingModeJoker = {
175
- caps: {
176
- [Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
177
- [Capabilities.SCRIPTING_NORMALIZE_TEXT]: true,
178
- [Capabilities.SCRIPTING_MEMORY_MATCHING_MODE]: 'joker'
179
- }
180
- }
181
- this.scriptingProvider = new ScriptingProvider(DefaultCapabilities)
182
- await this.scriptingProvider.Build()
183
- this.scriptingContext = this.scriptingProvider._buildScriptContext()
184
- this.convo = new Convo(this.scriptingContext, {
185
- header: 'test convo',
186
- conversation: []
187
- })
188
- this.scriptingProvider.AddConvos(this.convo)
189
- })
190
-
191
- it('should fill scripting memory from text', async function () {
192
- const scriptingMemory = {}
193
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence 1', 'test sentence $num', this.convo.scriptingEvents)
194
- assert.equal(scriptingMemory.$num, '1')
67
+ const driver = new BotDriver(myCaps)
68
+ this.compiler = driver.BuildCompiler()
69
+ this.container = await driver.Build()
195
70
  })
196
- it('should not fill scripting memory from invalid text', async function () {
197
- const scriptingMemory = {}
198
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence', 'test sentence $num', this.convo.scriptingEvents)
199
- assert.isUndefined(scriptingMemory.$num)
71
+ afterEach(async function () {
72
+ this.container && await this.container.Clean()
200
73
  })
201
- it('should fill scripting memory from one utterance', async function () {
202
- this.scriptingProvider.AddUtterances({
203
- name: 'utt1',
204
- utterances: ['test sentence $num']
205
- })
206
74
 
207
- const scriptingMemory = {}
208
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence 1', 'utt1', this.convo.scriptingEvents)
209
- assert.equal(scriptingMemory.$num, '1')
210
- })
211
- it('should fill multiple scripting memory from one utterance', async function () {
212
- this.scriptingProvider.AddUtterances({
213
- name: 'utt1',
214
- utterances: ['test sentence $num1 $num2']
215
- })
75
+ it('should fill scripting memory from convo file', async function () {
76
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'memory.convo.txt')
77
+ assert.equal(this.compiler.convos.length, 1)
216
78
 
217
- const scriptingMemory = {}
218
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence 1 2', 'utt1', this.convo.scriptingEvents)
219
- assert.equal(scriptingMemory.$num1, '1')
220
- assert.equal(scriptingMemory.$num2, '2')
79
+ const transcript = await this.compiler.convos[0].Run(this.container)
80
+ assert.isObject(transcript.scriptingMemory)
81
+ assert.isDefined(transcript.scriptingMemory.$myvar)
82
+ assert.equal(transcript.scriptingMemory.$myvar, 'VARVALUE')
221
83
  })
222
- it('should fill scripting memory from two different utterances', async function () {
223
- this.scriptingProvider.AddUtterances({
224
- name: 'utt1',
225
- utterances: ['i am $months months old', 'i am $years years old']
226
- })
84
+ it('should fill scripting memory from utterances file', async function () {
85
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'utt_memory.convo.txt')
86
+ assert.equal(this.compiler.convos.length, 1)
87
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'utt_memory.utterances.txt')
88
+ assert.isDefined(this.compiler.utterances.AGE_UTT)
227
89
 
228
- const scriptingMemory = {}
229
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'i am 2 months old', 'utt1', this.convo.scriptingEvents)
230
- assert.equal(scriptingMemory.$months, '2')
231
- assert.isUndefined(scriptingMemory.$years)
90
+ const transcript = await this.compiler.convos[0].Run(this.container)
91
+ assert.isObject(transcript.scriptingMemory)
92
+ assert.equal(transcript.scriptingMemory.$years, '40')
93
+ assert.equal(transcript.scriptingMemory.$months, '2')
232
94
  })
233
- it('should replace utterances from scripting memory', async function () {
234
- // $Years instead of $years to avoid collision with $year embedded variable
235
- this.scriptingProvider.AddUtterances({
236
- name: 'utt1',
237
- utterances: ['i am $months months old', 'i am $Years years old']
238
- })
239
- const scriptingMemory = {}
240
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'i am 2 months old', 'utt1', this.convo.scriptingEvents)
241
-
242
- const tomatch = this.convo._resolveUtterancesToMatch(this.containerStub, scriptingMemory, 'utt1')
243
- assert.isArray(tomatch)
244
- assert.equal(tomatch[0], 'i am 2 months old')
245
- assert.equal(tomatch[1], 'i am $Years years old')
246
- })
247
- it('should accept special regexp characters in utterance when replace utterances from scripting memory in regexp matching mode', async function () {
248
- this.containerStub.caps[Capabilities.SCRIPTING_MATCHING_MODE] = 'regexp'
249
-
250
- const scriptingMemory = {}
251
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence 1 end', '.* sentence $num', this.convo.scriptingEvents)
252
- assert.equal(scriptingMemory.$num, '1')
253
- const tomatch = this.convo._resolveUtterancesToMatch(this.containerStub, scriptingMemory, '.* sentence $num')
254
- assert.isArray(tomatch)
255
- assert.equal(tomatch[0], '.* sentence 1')
256
- })
257
- it('should accept special regexp characters in utterances when replace utterances from scripting memory in regexp matching mode', async function () {
258
- this.containerStub.caps[Capabilities.SCRIPTING_MATCHING_MODE] = 'regexp'
259
- this.scriptingProvider.AddUtterances({
260
- name: 'utt1',
261
- utterances: ['.* sentence $num']
262
- })
263
-
264
- const scriptingMemory = {}
265
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence 1 end', 'utt1', this.convo.scriptingEvents)
266
- assert.equal(scriptingMemory.$num, '1')
267
- const tomatch = this.convo._resolveUtterancesToMatch(this.containerStub, scriptingMemory, 'utt1')
268
- assert.isArray(tomatch)
269
- assert.equal(tomatch[0], '.* sentence 1')
270
- })
271
- it('should accept special regexp characters in utterance when filling scripting memory', async function () {
272
- const scriptingMemory = {}
273
- ScriptingMemory.fill(this.containerStub, scriptingMemory, '*test sentence 1*', '*test sentence $num*', this.convo.scriptingEvents)
274
- assert.equal(scriptingMemory.$num, '1')
275
-
276
- const scriptingMemory1 = {}
277
- ScriptingMemory.fill(this.containerStub, scriptingMemory1, 'Hier sind deine Erinnerungen: Notiz: 104 | This is a test reminder', 'Hier sind deine Erinnerungen: Notiz: $id | This is a test reminder', this.convo.scriptingEvents)
278
- assert.equal(scriptingMemory1.$id, '104')
279
- })
280
- it('should accept special regexp characters in utterances when filling scripting memory', async function () {
281
- this.scriptingProvider.AddUtterances({
282
- name: 'utt1',
283
- utterances: ['[\'I am $months months old.\']', '[\'I am $years years old.\']']
284
- })
285
- const scriptingMemory = {}
286
- ScriptingMemory.fill(this.containerStub, scriptingMemory, '[\'I am 2 years old.\']', 'utt1', this.convo.scriptingEvents)
287
- assert.equal(scriptingMemory.$years, '2')
288
- })
289
- it('should accept newline characters in utterances when filling scripting memory', async function () {
290
- const scriptingMemory = {}
291
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence header\n\ntest sentence 1', 'test sentence header\n\ntest sentence $num', this.convo.scriptingEvents)
292
- assert.equal(scriptingMemory.$num, '1')
95
+ it('should fail on invalid scripting memory', async function () {
96
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'memory_fail.convo.txt')
97
+ assert.equal(this.compiler.convos.length, 1)
98
+
99
+ try {
100
+ await this.compiler.convos[0].Run(this.container)
101
+ assert.fail('expected convo to fail')
102
+ } catch (err) {
103
+ assert.isTrue(err.message.indexOf('Bot response (on Line 9: #me - show var $myvar) "show var VARVALUE" expected to match "show var VARVALUEINVALID"') > 0)
104
+ }
293
105
  })
294
- it('should accept variable name case sensitive', async function () {
295
- const scriptingMemory = {}
296
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence 1', 'test sentence $Num', this.convo.scriptingEvents)
297
- assert.equal(scriptingMemory.$num, undefined)
298
- assert.equal(scriptingMemory.$Num, '1')
106
+ it('should normalize bot response', async function () {
107
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'memory_normalize.convo.txt')
108
+ assert.equal(this.compiler.convos.length, 1)
109
+
110
+ const transcript = await this.compiler.convos[0].Run(this.container)
111
+ assert.isObject(transcript.scriptingMemory)
112
+ assert.isDefined(transcript.scriptingMemory.$state)
113
+ assert.equal(transcript.scriptingMemory.$state, 'Kentucky')
299
114
  })
300
- it('should accept variable name as postfix', async function () {
301
- const scriptingMemory = {}
302
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence a1', 'test sentence a$Num', this.convo.scriptingEvents)
303
- assert.equal(scriptingMemory.$num, undefined)
304
- assert.equal(scriptingMemory.$Num, '1')
115
+ it('should normalize bot response 2', async function () {
116
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'memory_dont_override_functions.convo.txt')
117
+ assert.equal(this.compiler.convos.length, 1)
118
+
119
+ const transcript = await this.compiler.convos[0].Run(this.container)
120
+ assert.isObject(transcript.scriptingMemory)
121
+ assert.isUndefined(transcript.scriptingMemory.$year)
305
122
  })
306
- it('should not change scripting memory functions', async function () {
307
- const scriptingMemory = {}
308
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence a1', 'test sentence a$now', this.convo.scriptingEvents)
309
- assert.notEqual(scriptingMemory.$now, '1')
123
+ it('should append multiline messages from scripting memory', async function () {
124
+ this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'multiline.convo.txt')
125
+ assert.equal(this.compiler.convos.length, 1)
126
+
127
+ const transcript = await this.compiler.convos[0].Run(this.container)
128
+ assert(transcript.steps[0].actual.messageText.split('\n')[1].startsWith('20'))
129
+ assert(transcript.steps[1].actual.messageText.split('\n')[1].startsWith('20'))
130
+ assert.isObject(transcript.scriptingMemory)
131
+ assert.isDefined(transcript.scriptingMemory.$year_captured)
132
+ assert.equal(transcript.scriptingMemory.$year_captured.length, 4)
310
133
  })
311
- it('should match normalized response', async function () {
312
- let result = "<speak>Kentucky is the 15th state, admitted to the Union in 1792. The capital of Kentucky is Frankfort, and the abbreviation for Kentucky is <break strength='strong'/><say-as interpret-as='spell-out'>KY</say-as>. I've added Kentucky to your Alexa app. Which other state or capital would you like to know about?</speak>"
313
- const expected = "$state is the 15th state, admitted to the Union in 1792. The capital of Kentucky is Frankfort, and the abbreviation for Kentucky is KY. I've added Kentucky to your Alexa app. Which other state or capital would you like to know about?"
134
+ })
314
135
 
315
- result = normalizeText(result, true)
136
+ describe('args', function () {
137
+ it('should apply scripting memory to asserter args', async function () {
138
+ const myCaps = {
139
+ [Capabilities.PROJECTNAME]: 'convo.scriptingmemory',
140
+ [Capabilities.CONTAINERMODE]: echoConnector,
141
+ [Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
142
+ [Capabilities.ASSERTERS]: [
143
+ {
144
+ ref: 'CUSTOMASSERTER',
145
+ src: {
146
+ assertConvoStep: ({ botMsg, args }) => {
147
+ assert.lengthOf(args, 2)
148
+ assert.equal(args[0], 'question1')
149
+ assert.equal(args[1], 'question2')
150
+ }
151
+ }
152
+ }
153
+ ]
154
+ }
155
+ const driver = new BotDriver(myCaps)
156
+ const compiler = driver.BuildCompiler()
157
+ const container = await driver.Build()
316
158
 
317
- const scriptingMemory = {}
318
- ScriptingMemory.fill(this.containerStub, scriptingMemory, result, expected, this.convo.scriptingEvents)
319
- assert.equal(scriptingMemory.$state, 'Kentucky')
320
- })
321
- it('should match not-whitespace (SCRIPTING_MEMORY_MATCHING_MODE == non_whitespace, default)', async function () {
322
- const scriptingMemory = {}
323
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'date: 28.01.2019', 'date: $somedate', this.convo.scriptingEvents)
324
- assert.equal(scriptingMemory.$somedate, '28.01.2019')
325
- })
326
- it('should match not-whitespace (SCRIPTING_MEMORY_MATCHING_MODE == word)', async function () {
327
- const scriptingMemory = {}
328
- ScriptingMemory.fill(this.containerStubMatchingModeWord, scriptingMemory, 'my name is joe.', 'my name is $name', this.convo.scriptingEvents)
329
- assert.equal(scriptingMemory.$name, 'joe')
330
- })
331
- it('should match multi lines (SCRIPTING_MEMORY_MATCHING_MODE == joker)', async function () {
332
- const scriptingMemory = {}
333
- ScriptingMemory.fill(this.containerStubMatchingModeJoker, scriptingMemory, 'test sentence \nline1\r\nline2', 'test sentence $lines', this.convo.scriptingEvents)
334
- assert.equal(scriptingMemory.$lines, '\nline1\r\nline2')
335
- })
336
- it('should match multi words (SCRIPTING_MEMORY_MATCHING_MODE == joker)', async function () {
337
- const scriptingMemory = {}
338
- ScriptingMemory.fill(this.containerStubMatchingModeJoker, scriptingMemory, 'test sentence match1 match2', 'test sentence $words', this.convo.scriptingEvents)
339
- assert.equal(scriptingMemory.$words, 'match1 match2')
340
- })
341
- // this is not an expectation, nothing depends on this behaviour
342
- it('should match $', async function () {
343
- const scriptingMemory = {}
344
- ScriptingMemory.fill(this.containerStub, scriptingMemory, 'text: textwith$', 'text: $sometext', this.convo.scriptingEvents)
345
- assert.equal(scriptingMemory.$sometext, 'textwith$')
159
+ compiler.ReadScript(path.resolve(__dirname, 'convos'), 'applyscriptingmemorytoasserterargs.convo.txt')
160
+ assert.equal(compiler.convos.length, 1)
161
+
162
+ const transcript = await compiler.convos[0].Run(container)
163
+ assert.isObject(transcript.scriptingMemory)
346
164
  })
347
165
  })
348
166
 
349
- describe('convo.scriptingMemory.api.apply', function () {
350
- it('should apply on exact match', async function () {
351
- const result = ScriptingMemory.apply(
352
- { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
353
- { $num: 1 },
354
- 'test sentence $num'
355
- )
356
- assert.equal(result, 'test sentence 1')
357
- })
167
+ describe('api', function () {
168
+ describe('api.fill', function () {
169
+ beforeEach(async function () {
170
+ this.containerStub = {
171
+ caps: {
172
+ [Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
173
+ [Capabilities.SCRIPTING_NORMALIZE_TEXT]: true
174
+ }
175
+ }
176
+ this.containerStubMatchingModeWord = {
177
+ caps: {
178
+ [Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
179
+ [Capabilities.SCRIPTING_NORMALIZE_TEXT]: true,
180
+ [Capabilities.SCRIPTING_MEMORY_MATCHING_MODE]: 'word'
181
+ }
182
+ }
183
+ this.containerStubMatchingModeJoker = {
184
+ caps: {
185
+ [Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
186
+ [Capabilities.SCRIPTING_NORMALIZE_TEXT]: true,
187
+ [Capabilities.SCRIPTING_MEMORY_MATCHING_MODE]: 'joker'
188
+ }
189
+ }
190
+ this.scriptingProvider = new ScriptingProvider(DefaultCapabilities)
191
+ await this.scriptingProvider.Build()
192
+ this.scriptingContext = this.scriptingProvider._buildScriptContext()
193
+ this.convo = new Convo(this.scriptingContext, {
194
+ header: 'test convo',
195
+ conversation: []
196
+ })
197
+ this.scriptingProvider.AddConvos(this.convo)
198
+ })
358
199
 
359
- it('should apply on prefix match', async function () {
360
- const result = ScriptingMemory.apply(
361
- { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
362
- { $num: 1 },
363
- 'test sentence $numPc'
364
- )
365
- assert.equal(result, 'test sentence 1Pc')
366
- })
200
+ it('should fill scripting memory from text', async function () {
201
+ const scriptingMemory = {}
202
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence 1', 'test sentence $num', this.convo.scriptingEvents)
203
+ assert.equal(scriptingMemory.$num, '1')
204
+ })
205
+ it('should not fill scripting memory from invalid text', async function () {
206
+ const scriptingMemory = {}
207
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence', 'test sentence $num', this.convo.scriptingEvents)
208
+ assert.isUndefined(scriptingMemory.$num)
209
+ })
210
+ it('should fill scripting memory from one utterance', async function () {
211
+ this.scriptingProvider.AddUtterances({
212
+ name: 'utt1',
213
+ utterances: ['test sentence $num']
214
+ })
215
+
216
+ const scriptingMemory = {}
217
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence 1', 'utt1', this.convo.scriptingEvents)
218
+ assert.equal(scriptingMemory.$num, '1')
219
+ })
220
+ it('should fill multiple scripting memory from one utterance', async function () {
221
+ this.scriptingProvider.AddUtterances({
222
+ name: 'utt1',
223
+ utterances: ['test sentence $num1 $num2']
224
+ })
225
+
226
+ const scriptingMemory = {}
227
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence 1 2', 'utt1', this.convo.scriptingEvents)
228
+ assert.equal(scriptingMemory.$num1, '1')
229
+ assert.equal(scriptingMemory.$num2, '2')
230
+ })
231
+ it('should fill scripting memory from two different utterances', async function () {
232
+ this.scriptingProvider.AddUtterances({
233
+ name: 'utt1',
234
+ utterances: ['i am $months months old', 'i am $years years old']
235
+ })
236
+
237
+ const scriptingMemory = {}
238
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'i am 2 months old', 'utt1', this.convo.scriptingEvents)
239
+ assert.equal(scriptingMemory.$months, '2')
240
+ assert.isUndefined(scriptingMemory.$years)
241
+ })
242
+ it('should replace utterances from scripting memory', async function () {
243
+ // $Years instead of $years to avoid collision with $year embedded variable
244
+ this.scriptingProvider.AddUtterances({
245
+ name: 'utt1',
246
+ utterances: ['i am $months months old', 'i am $Years years old']
247
+ })
248
+ const scriptingMemory = {}
249
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'i am 2 months old', 'utt1', this.convo.scriptingEvents)
250
+
251
+ const tomatch = this.convo._resolveUtterancesToMatch(this.containerStub, scriptingMemory, 'utt1')
252
+ assert.isArray(tomatch)
253
+ assert.equal(tomatch[0], 'i am 2 months old')
254
+ assert.equal(tomatch[1], 'i am $Years years old')
255
+ })
256
+ it('should accept special regexp characters in utterance when replace utterances from scripting memory in regexp matching mode', async function () {
257
+ this.containerStub.caps[Capabilities.SCRIPTING_MATCHING_MODE] = 'regexp'
258
+
259
+ const scriptingMemory = {}
260
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence 1 end', '.* sentence $num', this.convo.scriptingEvents)
261
+ assert.equal(scriptingMemory.$num, '1')
262
+ const tomatch = this.convo._resolveUtterancesToMatch(this.containerStub, scriptingMemory, '.* sentence $num')
263
+ assert.isArray(tomatch)
264
+ assert.equal(tomatch[0], '.* sentence 1')
265
+ })
266
+ it('should accept special regexp characters in utterances when replace utterances from scripting memory in regexp matching mode', async function () {
267
+ this.containerStub.caps[Capabilities.SCRIPTING_MATCHING_MODE] = 'regexp'
268
+ this.scriptingProvider.AddUtterances({
269
+ name: 'utt1',
270
+ utterances: ['.* sentence $num']
271
+ })
272
+
273
+ const scriptingMemory = {}
274
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence 1 end', 'utt1', this.convo.scriptingEvents)
275
+ assert.equal(scriptingMemory.$num, '1')
276
+ const tomatch = this.convo._resolveUtterancesToMatch(this.containerStub, scriptingMemory, 'utt1')
277
+ assert.isArray(tomatch)
278
+ assert.equal(tomatch[0], '.* sentence 1')
279
+ })
280
+ it('should accept special regexp characters in utterance when filling scripting memory', async function () {
281
+ const scriptingMemory = {}
282
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, '*test sentence 1*', '*test sentence $num*', this.convo.scriptingEvents)
283
+ assert.equal(scriptingMemory.$num, '1')
284
+
285
+ const scriptingMemory1 = {}
286
+ ScriptingMemory.fill(this.containerStub, scriptingMemory1, 'Hier sind deine Erinnerungen: Notiz: 104 | This is a test reminder', 'Hier sind deine Erinnerungen: Notiz: $id | This is a test reminder', this.convo.scriptingEvents)
287
+ assert.equal(scriptingMemory1.$id, '104')
288
+ })
289
+ it('should accept special regexp characters in utterances when filling scripting memory', async function () {
290
+ this.scriptingProvider.AddUtterances({
291
+ name: 'utt1',
292
+ utterances: ['[\'I am $months months old.\']', '[\'I am $years years old.\']']
293
+ })
294
+ const scriptingMemory = {}
295
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, '[\'I am 2 years old.\']', 'utt1', this.convo.scriptingEvents)
296
+ assert.equal(scriptingMemory.$years, '2')
297
+ })
298
+ it('should accept newline characters in utterances when filling scripting memory', async function () {
299
+ const scriptingMemory = {}
300
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence header\n\ntest sentence 1', 'test sentence header\n\ntest sentence $num', this.convo.scriptingEvents)
301
+ assert.equal(scriptingMemory.$num, '1')
302
+ })
303
+ it('should accept variable name case sensitive', async function () {
304
+ const scriptingMemory = {}
305
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence 1', 'test sentence $Num', this.convo.scriptingEvents)
306
+ assert.equal(scriptingMemory.$num, undefined)
307
+ assert.equal(scriptingMemory.$Num, '1')
308
+ })
309
+ it('should accept variable name as postfix', async function () {
310
+ const scriptingMemory = {}
311
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence a1', 'test sentence a$Num', this.convo.scriptingEvents)
312
+ assert.equal(scriptingMemory.$num, undefined)
313
+ assert.equal(scriptingMemory.$Num, '1')
314
+ })
315
+ it('should not change scripting memory functions', async function () {
316
+ const scriptingMemory = {}
317
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'test sentence a1', 'test sentence a$now', this.convo.scriptingEvents)
318
+ assert.notEqual(scriptingMemory.$now, '1')
319
+ })
320
+ it('should match normalized response', async function () {
321
+ let result = '<speak>Kentucky is the 15th state, admitted to the Union in 1792. The capital of Kentucky is Frankfort, and the abbreviation for Kentucky is <break strength=\'strong\'/><say-as interpret-as=\'spell-out\'>KY</say-as>. I\'ve added Kentucky to your Alexa app. Which other state or capital would you like to know about?</speak>'
322
+ const expected = '$state is the 15th state, admitted to the Union in 1792. The capital of Kentucky is Frankfort, and the abbreviation for Kentucky is KY. I\'ve added Kentucky to your Alexa app. Which other state or capital would you like to know about?'
367
323
 
368
- it('should apply on postfix match', async function () {
369
- const result = ScriptingMemory.apply(
370
- { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
371
- { $num: 1 },
372
- 'test sentence Number$num'
373
- )
374
- assert.equal(result, 'test sentence Number1')
375
- })
324
+ result = normalizeText(result, true)
376
325
 
377
- it('should apply on middle match', async function () {
378
- const result = ScriptingMemory.apply(
379
- { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
380
- { $num: 1 },
381
- 'test sentence Number$numPc'
382
- )
383
- assert.equal(result, 'test sentence Number1Pc')
326
+ const scriptingMemory = {}
327
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, result, expected, this.convo.scriptingEvents)
328
+ assert.equal(scriptingMemory.$state, 'Kentucky')
329
+ })
330
+ it('should match not-whitespace (SCRIPTING_MEMORY_MATCHING_MODE == non_whitespace, default)', async function () {
331
+ const scriptingMemory = {}
332
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'date: 28.01.2019', 'date: $somedate', this.convo.scriptingEvents)
333
+ assert.equal(scriptingMemory.$somedate, '28.01.2019')
334
+ })
335
+ it('should match not-whitespace (SCRIPTING_MEMORY_MATCHING_MODE == word)', async function () {
336
+ const scriptingMemory = {}
337
+ ScriptingMemory.fill(this.containerStubMatchingModeWord, scriptingMemory, 'my name is joe.', 'my name is $name', this.convo.scriptingEvents)
338
+ assert.equal(scriptingMemory.$name, 'joe')
339
+ })
340
+ it('should match multi lines (SCRIPTING_MEMORY_MATCHING_MODE == joker)', async function () {
341
+ const scriptingMemory = {}
342
+ ScriptingMemory.fill(this.containerStubMatchingModeJoker, scriptingMemory, 'test sentence \nline1\r\nline2', 'test sentence $lines', this.convo.scriptingEvents)
343
+ assert.equal(scriptingMemory.$lines, '\nline1\r\nline2')
344
+ })
345
+ it('should match multi words (SCRIPTING_MEMORY_MATCHING_MODE == joker)', async function () {
346
+ const scriptingMemory = {}
347
+ ScriptingMemory.fill(this.containerStubMatchingModeJoker, scriptingMemory, 'test sentence match1 match2', 'test sentence $words', this.convo.scriptingEvents)
348
+ assert.equal(scriptingMemory.$words, 'match1 match2')
349
+ })
350
+ // this is not an expectation, nothing depends on this behaviour
351
+ it('should match $', async function () {
352
+ const scriptingMemory = {}
353
+ ScriptingMemory.fill(this.containerStub, scriptingMemory, 'text: textwith$', 'text: $sometext', this.convo.scriptingEvents)
354
+ assert.equal(scriptingMemory.$sometext, 'textwith$')
355
+ })
384
356
  })
385
357
 
386
- it('should not apply if name is wrong', async function () {
387
- const result = ScriptingMemory.apply(
388
- { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
389
- { $um: 1 },
390
- 'test sentence $num'
391
- )
392
- assert.equal(result, 'test sentence $num')
393
- })
358
+ describe('api.apply', function () {
359
+ it('should apply on exact match', async function () {
360
+ const result = ScriptingMemory.apply(
361
+ { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
362
+ { $num: 1 },
363
+ 'test sentence $num'
364
+ )
365
+ assert.equal(result, 'test sentence 1')
366
+ })
394
367
 
395
- it('should not be confused on overlapping names 1', async function () {
396
- const result = ScriptingMemory.apply(
397
- { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
398
- { $num: '1', $number: '2' },
399
- 'test sentence $num $number'
400
- )
401
- assert.equal(result, 'test sentence 1 2')
402
- })
368
+ it('should apply on prefix match', async function () {
369
+ const result = ScriptingMemory.apply(
370
+ { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
371
+ { $num: 1 },
372
+ 'test sentence $numPc'
373
+ )
374
+ assert.equal(result, 'test sentence 1Pc')
375
+ })
403
376
 
404
- it('should not be confused on overlapping names 2', async function () {
405
- const result = ScriptingMemory.apply(
406
- { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
407
- { $number: '2', $num: '1' },
408
- 'test sentence $num $number'
409
- )
410
- assert.equal(result, 'test sentence 1 2')
411
- })
377
+ it('should apply on postfix match', async function () {
378
+ const result = ScriptingMemory.apply(
379
+ { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
380
+ { $num: 1 },
381
+ 'test sentence Number$num'
382
+ )
383
+ assert.equal(result, 'test sentence Number1')
384
+ })
412
385
 
413
- it('scripting memory functions', async function () {
414
- const result = ScriptingMemory.apply(
415
- { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
416
- { },
417
- '$year'
418
- )
386
+ it('should apply on middle match', async function () {
387
+ const result = ScriptingMemory.apply(
388
+ { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
389
+ { $num: 1 },
390
+ 'test sentence Number$numPc'
391
+ )
392
+ assert.equal(result, 'test sentence Number1Pc')
393
+ })
419
394
 
420
- const year = parseInt(result)
421
- assert(year >= 2019 && year <= 2219, '$year invalid')
422
- })
423
- })
395
+ it('should not apply if name is wrong', async function () {
396
+ const result = ScriptingMemory.apply(
397
+ { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
398
+ { $um: 1 },
399
+ 'test sentence $num'
400
+ )
401
+ assert.equal(result, 'test sentence $num')
402
+ })
424
403
 
425
- describe('convo.scriptingMemory.api.applyToArgs', function () {
426
- it('exchange var with real value', async function () {
427
- const asserter = {
428
- name: 'DUMMY',
429
- args: [
430
- 'dbUrl',
431
- '$count',
432
- 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
433
- ]
434
- }
435
- const scriptingMemory = {
436
- $count: '5'
437
- }
438
- assert.equal(ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1], 5)
439
- })
440
- it('typo of reference', async function () {
441
- const asserter = {
442
- name: 'DUMMY',
443
- args: [
444
- 'dbUrl',
445
- '$ount',
446
- 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
447
- ]
448
- }
449
- const scriptingMemory = {
450
- $count: '5'
451
- }
452
- assert.notEqual(ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1], 5)
453
- })
454
- it('as postfix', async function () {
455
- const asserter = {
456
- name: 'DUMMY',
457
- args: [
458
- 'dbUrl',
459
- 'prefix$count',
460
- 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
461
- ]
462
- }
463
- const scriptingMemory = {
464
- $count: '5'
465
- }
466
- assert.equal(ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1], 'prefix5')
467
- })
468
- it('as prefix', async function () {
469
- const asserter = {
470
- name: 'DUMMY',
471
- args: [
472
- 'dbUrl',
473
- '$counter',
474
- 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
475
- ]
476
- }
477
- const scriptingMemory = {
478
- $count: '5'
479
- }
480
- assert.equal(ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1], '5er')
481
- })
482
- it('different value', async function () {
483
- const asserter = {
484
- name: 'DUMMY',
485
- args: [
486
- 'dbUrl',
487
- '$count',
488
- 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
489
- ]
490
- }
491
- const scriptingMemory = {
492
- $count: '4'
493
- }
494
- assert.notEqual(ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1], 5)
495
- })
404
+ it('should not be confused on overlapping names 1', async function () {
405
+ const result = ScriptingMemory.apply(
406
+ { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
407
+ {
408
+ $num: '1',
409
+ $number: '2'
410
+ },
411
+ 'test sentence $num $number'
412
+ )
413
+ assert.equal(result, 'test sentence 1 2')
414
+ })
496
415
 
497
- it('different value', async function () {
498
- const asserter = {
499
- name: 'DUMMY',
500
- args: [
501
- 'dbUrl',
502
- '$count',
503
- 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
504
- ]
505
- }
506
- const scriptingMemory = {
507
- $count: '4'
508
- }
509
- assert.notEqual(ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1], 5)
510
- })
416
+ it('should not be confused on overlapping names 2', async function () {
417
+ const result = ScriptingMemory.apply(
418
+ { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
419
+ {
420
+ $number: '2',
421
+ $num: '1'
422
+ },
423
+ 'test sentence $num $number'
424
+ )
425
+ assert.equal(result, 'test sentence 1 2')
426
+ })
511
427
 
512
- it('scripting memory functions', async function () {
513
- const asserter = {
514
- name: 'DUMMY',
515
- args: [
516
- 'dbUrl',
517
- '$year',
518
- 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
519
- ]
520
- }
521
- const scriptingMemory = {}
428
+ it('scripting memory functions', async function () {
429
+ const result = ScriptingMemory.apply(
430
+ { caps: { [Capabilities.SCRIPTING_ENABLE_MEMORY]: true } },
431
+ {},
432
+ '$year'
433
+ )
522
434
 
523
- const year = ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1]
524
- assert(year >= 2019 && year <= 2219, '$year invalid')
435
+ const year = parseInt(result)
436
+ assert(year >= 2019 && year <= 2219, '$year invalid')
437
+ })
525
438
  })
526
- })
527
439
 
528
- // if a function is working with apply, then it has to work with applyToArgs too
529
- describe('convo.scriptingMemory.api.functions', function () {
530
- it('remove parameters even if the function does not need them', async function () {
531
- const result = ScriptingMemory.apply(
532
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
533
- { },
534
- '$now(asd)'
535
- )
536
- assert.equal(result.indexOf('asd'), -1)
537
- })
440
+ describe('api.applyToArgs', function () {
441
+ it('exchange var with real value', async function () {
442
+ const asserter = {
443
+ name: 'DUMMY',
444
+ args: [
445
+ 'dbUrl',
446
+ '$count',
447
+ 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
448
+ ]
449
+ }
450
+ const scriptingMemory = {
451
+ $count: '5'
452
+ }
453
+ assert.equal(ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1], 5)
454
+ })
455
+ it('typo of reference', async function () {
456
+ const asserter = {
457
+ name: 'DUMMY',
458
+ args: [
459
+ 'dbUrl',
460
+ '$ount',
461
+ 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
462
+ ]
463
+ }
464
+ const scriptingMemory = {
465
+ $count: '5'
466
+ }
467
+ assert.notEqual(ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1], 5)
468
+ })
469
+ it('as postfix', async function () {
470
+ const asserter = {
471
+ name: 'DUMMY',
472
+ args: [
473
+ 'dbUrl',
474
+ 'prefix$count',
475
+ 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
476
+ ]
477
+ }
478
+ const scriptingMemory = {
479
+ $count: '5'
480
+ }
481
+ assert.equal(ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1], 'prefix5')
482
+ })
483
+ it('as prefix', async function () {
484
+ const asserter = {
485
+ name: 'DUMMY',
486
+ args: [
487
+ 'dbUrl',
488
+ '$counter',
489
+ 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
490
+ ]
491
+ }
492
+ const scriptingMemory = {
493
+ $count: '5'
494
+ }
495
+ assert.equal(ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1], '5er')
496
+ })
497
+ it('different value', async function () {
498
+ const asserter = {
499
+ name: 'DUMMY',
500
+ args: [
501
+ 'dbUrl',
502
+ '$count',
503
+ 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
504
+ ]
505
+ }
506
+ const scriptingMemory = {
507
+ $count: '4'
508
+ }
509
+ assert.notEqual(ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1], 5)
510
+ })
538
511
 
539
- it('now', async function () {
540
- const result = ScriptingMemory.apply(
541
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
542
- { },
543
- '$now'
544
- )
545
- assert.equal(result, new Date().toLocaleString())
546
- })
547
- it('now_EN', async function () {
548
- const result = ScriptingMemory.apply(
549
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
550
- { },
551
- '$now_EN'
552
- )
553
- assert(result.indexOf('/') < 3, 'wrong format')
554
- assert(result.lastIndexOf(':') > 10, 'wrong format')
555
- assert(result.lastIndexOf(':') > 10, 'wrong format')
556
- })
557
- it('now_DE', async function () {
558
- const result = ScriptingMemory.apply(
559
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
560
- { },
561
- '$now_DE'
562
- )
563
- assert(result.indexOf('.') === 2)
564
- assert(result.lastIndexOf(':') > 10)
565
- })
566
- it('now_ISO', async function () {
567
- const result = ScriptingMemory.apply(
568
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
569
- { },
570
- '$now_ISO'
571
- )
572
- assert(result.length === 24)
573
- assert.equal(result.indexOf('-'), 4)
574
- assert.equal(result.lastIndexOf('.'), 19)
575
- })
512
+ it('different value 2', async function () {
513
+ const asserter = {
514
+ name: 'DUMMY',
515
+ args: [
516
+ 'dbUrl',
517
+ '$count',
518
+ 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
519
+ ]
520
+ }
521
+ const scriptingMemory = {
522
+ $count: '4'
523
+ }
524
+ assert.notEqual(ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1], 5)
525
+ })
576
526
 
577
- it('date', async function () {
578
- const result = ScriptingMemory.apply(
579
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
580
- { },
581
- '$date'
582
- )
583
- assert.equal(result, new Date().toLocaleDateString())
584
- })
585
- it('date with param', async function () {
586
- const result = ScriptingMemory.apply(
587
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
588
- { },
589
- '$date(YYYY)'
590
- )
591
- assert.equal(result.length, 4)
592
- })
593
- it('date_EN', async function () {
594
- const result = ScriptingMemory.apply(
595
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
596
- { },
597
- '$date_EN'
598
- )
599
- assert(result.length <= 10, 'wrong format')
600
- assert(result.indexOf('/') <= 2, 'wrong format')
601
- assert(result.lastIndexOf('/') <= 5, 'wrong format')
602
- })
603
- it('date_DE', async function () {
604
- const result = ScriptingMemory.apply(
605
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
606
- { },
607
- '$date_DE'
608
- )
609
- assert(result.length <= 10, 'wrong format')
610
- assert(result.indexOf('.') === 4, 'wrong format')
611
- assert(result.lastIndexOf('.') === 7, 'wrong format')
612
- })
613
- it('date_ISO', async function () {
614
- const result = ScriptingMemory.apply(
615
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
616
- { },
617
- '$date_ISO'
618
- )
619
- assert.equal(result.length, 10)
620
- assert.equal(result.indexOf('-'), 4)
621
- assert.equal(result.lastIndexOf('-'), 7)
622
- })
527
+ it('scripting memory functions', async function () {
528
+ const asserter = {
529
+ name: 'DUMMY',
530
+ args: [
531
+ 'dbUrl',
532
+ '$year',
533
+ 'INSERT INTO dummy(name, birthday) VALUES (\'Max Mustermann\', 1991-03-26);'
534
+ ]
535
+ }
536
+ const scriptingMemory = {}
623
537
 
624
- it('time', async function () {
625
- const result = ScriptingMemory.apply(
626
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
627
- { },
628
- '$time'
629
- )
630
- assert(result.indexOf(':') < 3)
631
- })
632
- it('time_EN', async function () {
633
- const result = ScriptingMemory.apply(
634
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
635
- { },
636
- '$time_EN'
637
- )
638
- assert(result.indexOf(':') < 3)
639
- assert(result.lastIndexOf(' ') < 9)
640
- })
641
- it('time_DE', async function () {
642
- const result = ScriptingMemory.apply(
643
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
644
- { },
645
- '$time_DE'
646
- )
647
- assert(result.indexOf(':') !== result.lastIndexOf(':'))
648
- })
649
- it('time_ISO', async function () {
650
- const result = ScriptingMemory.apply(
651
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
652
- { },
653
- '$time_ISO'
654
- )
655
- assert(result.indexOf(':') !== result.lastIndexOf(':'))
656
- })
657
- it('time_HH_MM', async function () {
658
- const result = ScriptingMemory.apply(
659
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
660
- { },
661
- '$time_HH_MM'
662
- )
663
- assert(result.indexOf(':') === 2)
664
- })
665
- it('time_H_A', async function () {
666
- const result = ScriptingMemory.apply(
667
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
668
- { },
669
- '$time_H_A'
670
- )
671
- assert(result.indexOf(' ') > 0)
538
+ const year = ScriptingMemory.applyToArgs(asserter.args, scriptingMemory, CAPS_BASE)[1]
539
+ assert(year >= 2019 && year <= 2219, '$year invalid')
540
+ })
672
541
  })
673
542
 
674
- it('timestamp', async function () {
675
- const result = ScriptingMemory.apply(
676
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
677
- { },
678
- '$timestamp'
679
- )
680
- assert(result.length === 13, '$timestap is invalid')
681
- })
543
+ // if a function is working with apply, then it has to work with applyToArgs too
544
+ describe('api.functions', function () {
545
+ it('remove parameters even if the function does not need them', async function () {
546
+ const result = ScriptingMemory.apply(
547
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
548
+ {},
549
+ '$now(asd)'
550
+ )
551
+ assert.equal(result.indexOf('asd'), -1)
552
+ })
682
553
 
683
- it('year', async function () {
684
- const result = ScriptingMemory.apply(
685
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
686
- { },
687
- '$year'
688
- )
554
+ it('now', async function () {
555
+ const result = ScriptingMemory.apply(
556
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
557
+ {},
558
+ '$now'
559
+ )
560
+ assert.equal(result, new Date().toLocaleString())
561
+ })
562
+ it('now_EN', async function () {
563
+ const result = ScriptingMemory.apply(
564
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
565
+ {},
566
+ '$now_EN'
567
+ )
568
+ assert(result.indexOf('/') < 3, 'wrong format')
569
+ assert(result.lastIndexOf(':') > 10, 'wrong format')
570
+ assert(result.lastIndexOf(':') > 10, 'wrong format')
571
+ })
572
+ it('now_DE', async function () {
573
+ const result = ScriptingMemory.apply(
574
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
575
+ {},
576
+ '$now_DE'
577
+ )
578
+ assert(result.indexOf('.') === 2)
579
+ assert(result.lastIndexOf(':') > 10)
580
+ })
581
+ it('now_ISO', async function () {
582
+ const result = ScriptingMemory.apply(
583
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
584
+ {},
585
+ '$now_ISO'
586
+ )
587
+ assert(result.length === 24)
588
+ assert.equal(result.indexOf('-'), 4)
589
+ assert.equal(result.lastIndexOf('.'), 19)
590
+ })
689
591
 
690
- const year = parseInt(result)
691
- assert(year >= 2019 && year <= 2219, '$year invalid')
692
- })
592
+ it('date', async function () {
593
+ const result = ScriptingMemory.apply(
594
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
595
+ {},
596
+ '$date'
597
+ )
598
+ assert.equal(result, new Date().toLocaleDateString())
599
+ })
600
+ it('date with param', async function () {
601
+ const result = ScriptingMemory.apply(
602
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
603
+ {},
604
+ '$date(YYYY)'
605
+ )
606
+ assert.equal(result.length, 4)
607
+ })
608
+ it('date_EN', async function () {
609
+ const result = ScriptingMemory.apply(
610
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
611
+ {},
612
+ '$date_EN'
613
+ )
614
+ assert(result.length <= 10, 'wrong format')
615
+ assert(result.indexOf('/') <= 2, 'wrong format')
616
+ assert(result.lastIndexOf('/') <= 5, 'wrong format')
617
+ })
618
+ it('date_DE', async function () {
619
+ const result = ScriptingMemory.apply(
620
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
621
+ {},
622
+ '$date_DE'
623
+ )
624
+ assert(result.length <= 10, 'wrong format')
625
+ assert(result.indexOf('.') === 4, 'wrong format')
626
+ assert(result.lastIndexOf('.') === 7, 'wrong format')
627
+ })
628
+ it('date_ISO', async function () {
629
+ const result = ScriptingMemory.apply(
630
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
631
+ {},
632
+ '$date_ISO'
633
+ )
634
+ assert.equal(result.length, 10)
635
+ assert.equal(result.indexOf('-'), 4)
636
+ assert.equal(result.lastIndexOf('-'), 7)
637
+ })
693
638
 
694
- it('month', async function () {
695
- const result = ScriptingMemory.apply(
696
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
697
- { },
698
- '$month'
699
- )
639
+ it('time', async function () {
640
+ const result = ScriptingMemory.apply(
641
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
642
+ {},
643
+ '$time'
644
+ )
645
+ assert(result.indexOf(':') < 3)
646
+ })
647
+ it('time_EN', async function () {
648
+ const result = ScriptingMemory.apply(
649
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
650
+ {},
651
+ '$time_EN'
652
+ )
653
+ assert(result.indexOf(':') < 3)
654
+ assert(result.lastIndexOf(' ') < 9)
655
+ })
656
+ it('time_DE', async function () {
657
+ const result = ScriptingMemory.apply(
658
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
659
+ {},
660
+ '$time_DE'
661
+ )
662
+ assert(result.indexOf(':') !== result.lastIndexOf(':'))
663
+ })
664
+ it('time_ISO', async function () {
665
+ const result = ScriptingMemory.apply(
666
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
667
+ {},
668
+ '$time_ISO'
669
+ )
670
+ assert(result.indexOf(':') !== result.lastIndexOf(':'))
671
+ })
672
+ it('time_HH_MM', async function () {
673
+ const result = ScriptingMemory.apply(
674
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
675
+ {},
676
+ '$time_HH_MM'
677
+ )
678
+ assert(result.indexOf(':') === 2)
679
+ })
680
+ it('time_H_A', async function () {
681
+ const result = ScriptingMemory.apply(
682
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
683
+ {},
684
+ '$time_H_A'
685
+ )
686
+ assert(result.indexOf(' ') > 0)
687
+ })
700
688
 
701
- assert(result.length >= 2 && result.length <= 10, '$month invalid')
702
- })
703
- it('month_MM', async function () {
704
- const result = ScriptingMemory.apply(
705
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
706
- { },
707
- '$month_MM'
708
- )
709
-
710
- assert(result.length > 0 && result.length < 3, '$month invalid')
711
- })
689
+ it('timestamp', async function () {
690
+ const result = ScriptingMemory.apply(
691
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
692
+ {},
693
+ '$timestamp'
694
+ )
695
+ assert(result.length === 13, '$timestap is invalid')
696
+ })
712
697
 
713
- it('day_of_month', async function () {
714
- const result = ScriptingMemory.apply(
715
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
716
- { },
717
- '$day_of_month'
718
- )
698
+ it('year', async function () {
699
+ const result = ScriptingMemory.apply(
700
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
701
+ {},
702
+ '$year'
703
+ )
719
704
 
720
- const dayOfMonth = parseInt(result)
721
- assert(dayOfMonth >= 1 && dayOfMonth <= 35, 'day_of_month invalid')
722
- })
705
+ const year = parseInt(result)
706
+ assert(year >= 2019 && year <= 2219, '$year invalid')
707
+ })
723
708
 
724
- it('day_of_week', async function () {
725
- const result = ScriptingMemory.apply(
726
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
727
- { },
728
- '$day_of_week'
729
- )
709
+ it('month', async function () {
710
+ const result = ScriptingMemory.apply(
711
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
712
+ {},
713
+ '$month'
714
+ )
730
715
 
731
- assert(result.length >= 2 && result.length <= 20, '$day_of_week invalid')
732
- })
716
+ assert(result.length >= 2 && result.length <= 10, '$month invalid')
717
+ })
718
+ it('month_MM', async function () {
719
+ const result = ScriptingMemory.apply(
720
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
721
+ {},
722
+ '$month_MM'
723
+ )
733
724
 
734
- it('random', async function () {
735
- const result = ScriptingMemory.apply(
736
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
737
- { },
738
- '$random(19)'
739
- )
725
+ assert(result.length > 0 && result.length < 3, '$month invalid')
726
+ })
740
727
 
741
- assert(result.length === 19, '$random invalid')
742
- })
743
- it('random10', async function () {
744
- const result = ScriptingMemory.apply(
745
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
746
- { },
747
- '$random10'
748
- )
749
-
750
- assert(result.length === 10, '$random10 invalid')
751
- })
728
+ it('day_of_month', async function () {
729
+ const result = ScriptingMemory.apply(
730
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
731
+ {},
732
+ '$day_of_month'
733
+ )
752
734
 
753
- it('uniqid', async function () {
754
- const result = ScriptingMemory.apply(
755
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
756
- { },
757
- '$uniqid'
758
- )
735
+ const dayOfMonth = parseInt(result)
736
+ assert(dayOfMonth >= 1 && dayOfMonth <= 35, 'day_of_month invalid')
737
+ })
759
738
 
760
- assert(result.length === 36, '$uniqid invalid')
761
- })
739
+ it('day_of_week', async function () {
740
+ const result = ScriptingMemory.apply(
741
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
742
+ {},
743
+ '$day_of_week'
744
+ )
762
745
 
763
- it('func', async function () {
764
- const result = ScriptingMemory.apply(
765
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
766
- { },
767
- '$func(3*5)'
768
- )
746
+ assert(result.length >= 2 && result.length <= 20, '$day_of_week invalid')
747
+ })
769
748
 
770
- assert(result === '15', 'func invalid')
771
- })
772
- it('func with caps', async function () {
773
- const result = ScriptingMemory.apply(
774
- { caps: Object.assign({}, CAPS_ENABLE_SCRIPTING_MEMORY, { mycap: 'botium' }) },
775
- { },
776
- '$func(caps.mycap)'
777
- )
778
- assert.equal(result, 'botium')
779
- })
780
- it('func invalid code', async function () {
781
- try {
782
- ScriptingMemory.apply(
749
+ it('random', async function () {
750
+ const result = ScriptingMemory.apply(
783
751
  { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
784
- { },
785
- '$func(hugo123)'
752
+ {},
753
+ '$random(19)'
786
754
  )
787
- assert.fail('should have failed')
788
- } catch (err) {
789
- assert.isTrue(err.message.indexOf('func function execution failed') >= 0)
790
- }
791
- })
792
- it('func environment variable', async function () {
793
- process.env.MY_VAR_VALUE = 'botium'
794
- const result = ScriptingMemory.apply(
795
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
796
- { },
797
- '$func(process.env.MY_VAR_VALUE)'
798
- )
799
- assert.equal(result, 'botium')
800
- })
801
- it('environment variable', async function () {
802
- process.env.MY_VAR_VALUE = 'botium'
803
- const result = ScriptingMemory.apply(
804
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
805
- { },
806
- '$env(MY_VAR_VALUE)'
807
- )
808
- assert.equal(result, 'botium')
809
- })
810
- it('environment variable reject', async function () {
811
- process.env.MY_VAR_VALUE = 'botium'
812
- try {
813
- ScriptingMemory.apply(
814
- { caps: Object.assign({}, CAPS_ENABLE_SCRIPTING_MEMORY, { SECURITY_ALLOW_UNSAFE: false }) },
815
- { },
755
+
756
+ assert(result.length === 19, '$random invalid')
757
+ })
758
+ it('random10', async function () {
759
+ const result = ScriptingMemory.apply(
760
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
761
+ {},
762
+ '$random10'
763
+ )
764
+
765
+ assert(result.length === 10, '$random10 invalid')
766
+ })
767
+
768
+ it('uniqid', async function () {
769
+ const result = ScriptingMemory.apply(
770
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
771
+ {},
772
+ '$uniqid'
773
+ )
774
+
775
+ assert(result.length === 36, '$uniqid invalid')
776
+ })
777
+
778
+ it('func', async function () {
779
+ const result = ScriptingMemory.apply(
780
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
781
+ {},
782
+ '$func(3*5)'
783
+ )
784
+
785
+ assert(result === '15', 'func invalid')
786
+ })
787
+ it('func with caps', async function () {
788
+ const result = ScriptingMemory.apply(
789
+ { caps: Object.assign({}, CAPS_ENABLE_SCRIPTING_MEMORY, { mycap: 'botium' }) },
790
+ {},
791
+ '$func(caps.mycap)'
792
+ )
793
+ assert.equal(result, 'botium')
794
+ })
795
+ it('func invalid code', async function () {
796
+ try {
797
+ ScriptingMemory.apply(
798
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
799
+ {},
800
+ '$func(hugo123)'
801
+ )
802
+ assert.fail('should have failed')
803
+ } catch (err) {
804
+ assert.isTrue(err.message.indexOf('func function execution failed') >= 0)
805
+ }
806
+ })
807
+ it('func environment variable', async function () {
808
+ process.env.MY_VAR_VALUE = 'botium'
809
+ const result = ScriptingMemory.apply(
810
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
811
+ {},
812
+ '$func(process.env.MY_VAR_VALUE)'
813
+ )
814
+ assert.equal(result, 'botium')
815
+ })
816
+ it('environment variable', async function () {
817
+ process.env.MY_VAR_VALUE = 'botium'
818
+ const result = ScriptingMemory.apply(
819
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
820
+ {},
816
821
  '$env(MY_VAR_VALUE)'
817
822
  )
818
- assert.fail('should have failed')
819
- } catch (err) {
820
- assert.isTrue(err.message.indexOf('Using unsafe scripting memory function $env is not allowed') >= 0)
821
- }
822
- })
823
- it('cap', async function () {
824
- const result = ScriptingMemory.apply(
825
- { caps: Object.assign({}, CAPS_ENABLE_SCRIPTING_MEMORY, { mycap: 'botium' }) },
826
- { },
827
- '$cap(mycap)'
828
- )
829
- assert.equal(result, 'botium')
830
- })
831
- it('msg with messageText', async function () {
832
- const result = ScriptingMemory.apply(
833
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
834
- { },
835
- '$msg($.messageText)',
836
- { messageText: 'botium' }
837
- )
838
- assert.equal(result, 'botium')
839
- })
840
- it('msg with messageText twice', async function () {
841
- const result = ScriptingMemory.apply(
842
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
843
- { },
844
- '$msg($.messageText) $msg($.messageText)',
845
- { messageText: 'botium' }
846
- )
847
- assert.equal(result, 'botium botium')
848
- })
849
- it('msg with sourceData', async function () {
850
- const result = ScriptingMemory.apply(
851
- { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
852
- { },
853
- '$msg($.sourceData.opt1)',
854
- { messageText: 'botium', sourceData: { opt1: 'botium' } }
855
- )
856
- assert.equal(result, 'botium')
857
- })
858
- it('projectname', async function () {
859
- const result = ScriptingMemory.apply(
860
- { caps: Object.assign({}, CAPS_ENABLE_SCRIPTING_MEMORY, { PROJECTNAME: 'botium' }) },
861
- { },
862
- '$projectname'
863
- )
864
- assert.equal(result, 'botium')
865
- })
866
- it('testsessionname', async function () {
867
- const result = ScriptingMemory.apply(
868
- { caps: Object.assign({}, CAPS_ENABLE_SCRIPTING_MEMORY, { TESTSESSIONNAME: 'botium' }) },
869
- { },
870
- '$testsessionname'
871
- )
872
- assert.equal(result, 'botium')
873
- })
874
- it('testcasename', async function () {
875
- const result = ScriptingMemory.apply(
876
- { caps: Object.assign({}, CAPS_ENABLE_SCRIPTING_MEMORY, { TESTCASENAME: 'botium' }) },
877
- { },
878
- '$testcasename'
879
- )
880
- assert.equal(result, 'botium')
823
+ assert.equal(result, 'botium')
824
+ })
825
+ it('environment variable reject', async function () {
826
+ process.env.MY_VAR_VALUE = 'botium'
827
+ try {
828
+ ScriptingMemory.apply(
829
+ { caps: Object.assign({}, CAPS_ENABLE_SCRIPTING_MEMORY, { SECURITY_ALLOW_UNSAFE: false }) },
830
+ {},
831
+ '$env(MY_VAR_VALUE)'
832
+ )
833
+ assert.fail('should have failed')
834
+ } catch (err) {
835
+ assert.isTrue(err.message.indexOf('Using unsafe scripting memory function $env is not allowed') >= 0)
836
+ }
837
+ })
838
+ it('cap', async function () {
839
+ const result = ScriptingMemory.apply(
840
+ { caps: Object.assign({}, CAPS_ENABLE_SCRIPTING_MEMORY, { mycap: 'botium' }) },
841
+ {},
842
+ '$cap(mycap)'
843
+ )
844
+ assert.equal(result, 'botium')
845
+ })
846
+ it('msg with messageText', async function () {
847
+ const result = ScriptingMemory.apply(
848
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
849
+ {},
850
+ '$msg($.messageText)',
851
+ { messageText: 'botium' }
852
+ )
853
+ assert.equal(result, 'botium')
854
+ })
855
+ it('msg with messageText twice', async function () {
856
+ const result = ScriptingMemory.apply(
857
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
858
+ {},
859
+ '$msg($.messageText) $msg($.messageText)',
860
+ { messageText: 'botium' }
861
+ )
862
+ assert.equal(result, 'botium botium')
863
+ })
864
+ it('msg with sourceData', async function () {
865
+ const result = ScriptingMemory.apply(
866
+ { caps: CAPS_ENABLE_SCRIPTING_MEMORY },
867
+ {},
868
+ '$msg($.sourceData.opt1)',
869
+ {
870
+ messageText: 'botium',
871
+ sourceData: { opt1: 'botium' }
872
+ }
873
+ )
874
+ assert.equal(result, 'botium')
875
+ })
876
+ it('projectname', async function () {
877
+ const result = ScriptingMemory.apply(
878
+ { caps: Object.assign({}, CAPS_ENABLE_SCRIPTING_MEMORY, { PROJECTNAME: 'botium' }) },
879
+ {},
880
+ '$projectname'
881
+ )
882
+ assert.equal(result, 'botium')
883
+ })
884
+ it('testsessionname', async function () {
885
+ const result = ScriptingMemory.apply(
886
+ { caps: Object.assign({}, CAPS_ENABLE_SCRIPTING_MEMORY, { TESTSESSIONNAME: 'botium' }) },
887
+ {},
888
+ '$testsessionname'
889
+ )
890
+ assert.equal(result, 'botium')
891
+ })
892
+ it('testcasename', async function () {
893
+ const result = ScriptingMemory.apply(
894
+ { caps: Object.assign({}, CAPS_ENABLE_SCRIPTING_MEMORY, { TESTCASENAME: 'botium' }) },
895
+ {},
896
+ '$testcasename'
897
+ )
898
+ assert.equal(result, 'botium')
899
+ })
881
900
  })
882
901
  })
883
902
  })