botium-core 1.13.0 → 1.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +6 -3
- package/dist/botium-cjs.js +305 -123
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +323 -142
- package/dist/botium-es.js.map +1 -1
- package/package.json +17 -15
- package/src/Capabilities.js +2 -1
- package/src/containers/plugins/SimpleRestContainer.js +23 -16
- package/src/grid/inbound/proxy.js +2 -1
- package/src/helpers/RetryHelper.js +13 -7
- package/src/scripting/Convo.js +36 -10
- package/src/scripting/MatchFunctions.js +10 -0
- package/src/scripting/ScriptingProvider.js +106 -37
- package/src/scripting/logichook/LogicHookConsts.js +1 -1
- package/src/scripting/logichook/LogicHookUtils.js +1 -1
- package/src/scripting/logichook/asserter/WerAsserter.js +59 -0
- package/src/scripting/logichook/logichooks/UpdateCustomLogicHook.js +3 -2
- package/test/compiler/compilercsv.spec.js +104 -3
- package/test/compiler/compilerjson.spec.js +0 -2
- package/test/compiler/compilerxlsx.spec.js +1 -1
- package/test/compiler/convos/csv/utterances_liveperson2.csv +12 -0
- package/test/connectors/simplerest.spec.js +1012 -969
- package/test/convo/fillAndApplyScriptingMemory.spec.js +804 -785
- package/test/convo/partialconvo.spec.js +345 -339
- package/test/convo/retryconvo.spec.js +134 -0
- package/test/driver/capabilities.spec.js +156 -151
- package/test/logichooks/hookfromsrc.spec.js +79 -73
- package/test/plugins/plugins.spec.js +44 -42
- package/test/scripting/asserters/buttonsAsserter.spec.js +257 -240
- package/test/scripting/asserters/cardsAsserter.spec.js +214 -212
- package/test/scripting/asserters/convos/wer_threshold_nok.yml +7 -0
- package/test/scripting/asserters/convos/wer_threshold_ok.yml +7 -0
- package/test/scripting/asserters/intentConfidenceAsserter.spec.js +34 -35
- package/test/scripting/asserters/jsonpathAsserter.spec.js +307 -308
- package/test/scripting/asserters/mediaAsserter.spec.js +236 -234
- package/test/scripting/asserters/werAsserter.spec.js +51 -0
- package/test/scripting/logichooks/setClearScriptingMemory.spec.js +202 -192
- package/test/scripting/matching/matchingmode.spec.js +306 -258
- package/test/scripting/scriptingProvider.spec.js +666 -633
- package/test/scripting/scriptingmemory/fillScriptingMemoryFromFile.spec.js +299 -281
- package/test/scripting/scriptingmemory/useScriptingMemoryForAssertion.spec.js +94 -80
- package/test/scripting/userinputs/defaultUserInputs.spec.js +233 -127
- package/test/scripting/userinputs/mediaInputConvos.spec.js +409 -403
- package/test/scripting/utteranceexpansion/associateByIndex.spec.js +259 -0
- package/test/scripting/utteranceexpansion/convos/associate_utterances_by_index.json +33 -0
- package/test/scripting/utteranceexpansion/convos/media.convo.txt +19 -0
- package/test/scripting/utteranceexpansion/files/step0voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step0voice1.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step0voice2.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step1voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice0.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice1.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice2.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice4.wav +0 -0
- package/test/scripting/utteranceexpansion/files/step2voice5.wav +0 -0
- package/test/security/allowUnsafe.spec.js +274 -268
- package/test/utils.spec.js +40 -38
|
@@ -18,866 +18,885 @@ const CAPS_ENABLE_SCRIPTING_MEMORY = {
|
|
|
18
18
|
const echoConnector = ({ queueBotSays }) => {
|
|
19
19
|
return {
|
|
20
20
|
UserSays (msg) {
|
|
21
|
-
const botMsg = {
|
|
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
|
-
|
|
28
|
-
|
|
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]:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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'), '
|
|
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
|
-
|
|
154
|
-
assert.isObject(transcript.scriptingMemory)
|
|
57
|
+
container && await container.Clean()
|
|
155
58
|
})
|
|
156
|
-
})
|
|
157
59
|
|
|
158
|
-
describe('
|
|
159
|
-
describe('convo.scriptingMemory.api.fill', function () {
|
|
60
|
+
describe('convos', function () {
|
|
160
61
|
beforeEach(async function () {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
62
|
+
const myCaps = {
|
|
63
|
+
[Capabilities.PROJECTNAME]: 'convo.scriptingmemory',
|
|
64
|
+
[Capabilities.CONTAINERMODE]: echoConnector,
|
|
65
|
+
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true
|
|
166
66
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
197
|
-
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
assert.equal(
|
|
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
|
|
218
|
-
|
|
219
|
-
assert.
|
|
220
|
-
assert.equal(scriptingMemory.$
|
|
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
|
|
223
|
-
this.
|
|
224
|
-
|
|
225
|
-
|
|
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
|
|
229
|
-
|
|
230
|
-
assert.equal(scriptingMemory.$
|
|
231
|
-
assert.
|
|
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
|
|
234
|
-
|
|
235
|
-
this.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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('
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
)
|
|
365
|
-
|
|
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
|
-
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
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
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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
|
-
|
|
421
|
-
|
|
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
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
'
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
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
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
'
|
|
517
|
-
|
|
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
|
-
|
|
524
|
-
|
|
435
|
+
const year = parseInt(result)
|
|
436
|
+
assert(year >= 2019 && year <= 2219, '$year invalid')
|
|
437
|
+
})
|
|
525
438
|
})
|
|
526
|
-
})
|
|
527
439
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
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
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
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
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
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
|
-
|
|
625
|
-
|
|
626
|
-
|
|
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
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
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
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
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
|
-
|
|
691
|
-
|
|
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
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
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
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
'$
|
|
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
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
698
|
+
it('year', async function () {
|
|
699
|
+
const result = ScriptingMemory.apply(
|
|
700
|
+
{ caps: CAPS_ENABLE_SCRIPTING_MEMORY },
|
|
701
|
+
{},
|
|
702
|
+
'$year'
|
|
703
|
+
)
|
|
719
704
|
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
705
|
+
const year = parseInt(result)
|
|
706
|
+
assert(year >= 2019 && year <= 2219, '$year invalid')
|
|
707
|
+
})
|
|
723
708
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
709
|
+
it('month', async function () {
|
|
710
|
+
const result = ScriptingMemory.apply(
|
|
711
|
+
{ caps: CAPS_ENABLE_SCRIPTING_MEMORY },
|
|
712
|
+
{},
|
|
713
|
+
'$month'
|
|
714
|
+
)
|
|
730
715
|
|
|
731
|
-
|
|
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
|
-
|
|
735
|
-
|
|
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
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
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
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
{ },
|
|
757
|
-
'$uniqid'
|
|
758
|
-
)
|
|
735
|
+
const dayOfMonth = parseInt(result)
|
|
736
|
+
assert(dayOfMonth >= 1 && dayOfMonth <= 35, 'day_of_month invalid')
|
|
737
|
+
})
|
|
759
738
|
|
|
760
|
-
|
|
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
|
-
|
|
764
|
-
|
|
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
|
-
|
|
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
|
-
'$
|
|
752
|
+
{},
|
|
753
|
+
'$random(19)'
|
|
786
754
|
)
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
'$
|
|
798
|
-
)
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
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.
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
)
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
)
|
|
880
|
-
|
|
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
|
})
|