botium-core 1.13.1 → 1.13.4

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 (56) hide show
  1. package/.eslintrc.js +6 -3
  2. package/dist/botium-cjs.js +291 -86
  3. package/dist/botium-cjs.js.map +1 -1
  4. package/dist/botium-es.js +290 -86
  5. package/dist/botium-es.js.map +1 -1
  6. package/package.json +3 -1
  7. package/src/Capabilities.js +4 -1
  8. package/src/Defaults.js +4 -0
  9. package/src/containers/plugins/SimpleRestContainer.js +23 -16
  10. package/src/grid/inbound/proxy.js +2 -1
  11. package/src/mocks/BotiumMockScripting.js +1 -0
  12. package/src/scripting/Convo.js +16 -10
  13. package/src/scripting/MatchFunctions.js +10 -0
  14. package/src/scripting/ScriptingProvider.js +162 -69
  15. package/src/scripting/logichook/LogicHookConsts.js +1 -1
  16. package/src/scripting/logichook/asserter/WerAsserter.js +59 -0
  17. package/src/scripting/logichook/logichooks/UpdateCustomLogicHook.js +3 -2
  18. package/test/compiler/compilercsv.spec.js +104 -3
  19. package/test/compiler/compilerjson.spec.js +0 -2
  20. package/test/compiler/compilerxlsx.spec.js +1 -1
  21. package/test/compiler/convos/csv/utterances_liveperson2.csv +12 -0
  22. package/test/connectors/simplerest.spec.js +1012 -969
  23. package/test/convo/fillAndApplyScriptingMemory.spec.js +804 -785
  24. package/test/convo/partialconvo.spec.js +345 -339
  25. package/test/driver/capabilities.spec.js +156 -151
  26. package/test/logichooks/hookfromsrc.spec.js +79 -73
  27. package/test/plugins/plugins.spec.js +44 -42
  28. package/test/scripting/asserters/buttonsAsserter.spec.js +257 -240
  29. package/test/scripting/asserters/cardsAsserter.spec.js +214 -212
  30. package/test/scripting/asserters/convos/wer_threshold_nok.yml +7 -0
  31. package/test/scripting/asserters/convos/wer_threshold_ok.yml +7 -0
  32. package/test/scripting/asserters/intentConfidenceAsserter.spec.js +34 -35
  33. package/test/scripting/asserters/jsonpathAsserter.spec.js +307 -308
  34. package/test/scripting/asserters/mediaAsserter.spec.js +236 -234
  35. package/test/scripting/asserters/werAsserter.spec.js +51 -0
  36. package/test/scripting/logichooks/setClearScriptingMemory.spec.js +202 -192
  37. package/test/scripting/matching/matchingmode.spec.js +306 -258
  38. package/test/scripting/scriptingProvider.spec.js +720 -630
  39. package/test/scripting/scriptingmemory/fillScriptingMemoryFromFile.spec.js +299 -281
  40. package/test/scripting/scriptingmemory/useScriptingMemoryForAssertion.spec.js +94 -80
  41. package/test/scripting/userinputs/defaultUserInputs.spec.js +233 -127
  42. package/test/scripting/userinputs/mediaInputConvos.spec.js +409 -403
  43. package/test/scripting/utteranceexpansion/associateByIndex.spec.js +259 -0
  44. package/test/scripting/utteranceexpansion/convos/associate_utterances_by_index.json +33 -0
  45. package/test/scripting/utteranceexpansion/convos/media.convo.txt +19 -0
  46. package/test/scripting/utteranceexpansion/files/step0voice0.wav +0 -0
  47. package/test/scripting/utteranceexpansion/files/step0voice1.wav +0 -0
  48. package/test/scripting/utteranceexpansion/files/step0voice2.wav +0 -0
  49. package/test/scripting/utteranceexpansion/files/step1voice0.wav +0 -0
  50. package/test/scripting/utteranceexpansion/files/step2voice0.wav +0 -0
  51. package/test/scripting/utteranceexpansion/files/step2voice1.wav +0 -0
  52. package/test/scripting/utteranceexpansion/files/step2voice2.wav +0 -0
  53. package/test/scripting/utteranceexpansion/files/step2voice4.wav +0 -0
  54. package/test/scripting/utteranceexpansion/files/step2voice5.wav +0 -0
  55. package/test/security/allowUnsafe.spec.js +274 -268
  56. package/test/utils.spec.js +40 -38
@@ -6,730 +6,820 @@ const ScriptingProvider = require('../../src/scripting/ScriptingProvider')
6
6
  const DefaultCapabilities = require('../../src/Defaults').Capabilities
7
7
  const Capabilities = require('../../src/Capabilities')
8
8
 
9
- describe('scriptingProvider.ReadScriptsFromDirectory', function () {
10
- it('should read multiple files from dir', async function () {
11
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
12
- await scriptingProvider.Build()
13
- const { convos } = await scriptingProvider.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos'))
14
-
15
- assert.isArray(convos)
16
- assert.equal(convos.length, 2)
17
- })
18
- it('should read multiple files from dir with globFilter', async function () {
19
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
20
- await scriptingProvider.Build()
21
- const { convos } = await scriptingProvider.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos'), '**/*.convo.txt')
22
-
23
- assert.isArray(convos)
24
- assert.equal(convos.length, 2)
25
- })
26
- it('should ignore files from dir with globFilter', async function () {
27
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
28
- await scriptingProvider.Build()
29
- const { convos } = await scriptingProvider.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos'), 'sepp.txt')
9
+ describe('scripting.scriptingProvider', function () {
10
+ describe('ReadScriptsFromDirectory', function () {
11
+ it('should read multiple files from dir', async function () {
12
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
13
+ await scriptingProvider.Build()
14
+ const { convos } = await scriptingProvider.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos'))
30
15
 
31
- assert.isArray(convos)
32
- assert.equal(convos.length, 0)
33
- })
34
- it('should read single file from file path', async function () {
35
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
36
- await scriptingProvider.Build()
37
- const { convos } = await scriptingProvider.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos', 'convo1.convo.txt'))
16
+ assert.isArray(convos)
17
+ assert.equal(convos.length, 2)
18
+ })
19
+ it('should read multiple files from dir with globFilter', async function () {
20
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
21
+ await scriptingProvider.Build()
22
+ const { convos } = await scriptingProvider.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos'), '**/*.convo.txt')
38
23
 
39
- assert.isArray(convos)
40
- assert.equal(convos.length, 1)
41
- })
42
- it('should skip convos', async function () {
43
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
44
- await scriptingProvider.Build()
45
- const { convos } = await scriptingProvider.ReadScriptsFromDirectory(path.resolve(__dirname, 'skipconvos'))
24
+ assert.isArray(convos)
25
+ assert.equal(convos.length, 2)
26
+ })
27
+ it('should ignore files from dir with globFilter', async function () {
28
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
29
+ await scriptingProvider.Build()
30
+ const { convos } = await scriptingProvider.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos'), 'sepp.txt')
46
31
 
47
- assert.isArray(convos)
48
- assert.equal(convos.length, 1)
49
- })
50
- })
32
+ assert.isArray(convos)
33
+ assert.equal(convos.length, 0)
34
+ })
35
+ it('should read single file from file path', async function () {
36
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
37
+ await scriptingProvider.Build()
38
+ const { convos } = await scriptingProvider.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos', 'convo1.convo.txt'))
51
39
 
52
- describe('scriptingProvider._resolveUtterances', function () {
53
- it('should resolve utterance', async function () {
54
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
55
- await scriptingProvider.Build()
56
- const scriptingContext = scriptingProvider._buildScriptContext()
57
- scriptingProvider.AddUtterances({
58
- name: 'utt1',
59
- utterances: ['TEXT1', 'TEXT2']
60
- })
61
-
62
- const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt1' })
63
- assert.isArray(tomatch)
64
- assert.equal(tomatch.length, 2)
65
- assert.equal(tomatch[0], 'TEXT1')
66
- assert.equal(tomatch[1], 'TEXT2')
67
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatch, 'test1')
68
- })
69
- it('should resolve null on invalid utterance', async function () {
70
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
71
- await scriptingProvider.Build()
72
- const scriptingContext = scriptingProvider._buildScriptContext()
73
- scriptingProvider.AddUtterances({
74
- name: 'utt1',
75
- utterances: ['TEXT1', 'TEXT2']
40
+ assert.isArray(convos)
41
+ assert.equal(convos.length, 1)
76
42
  })
43
+ it('should skip convos', async function () {
44
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
45
+ await scriptingProvider.Build()
46
+ const { convos } = await scriptingProvider.ReadScriptsFromDirectory(path.resolve(__dirname, 'skipconvos'))
77
47
 
78
- const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt2', resolveEmptyIfUnknown: true })
79
- assert.isNull(tomatch)
80
- })
81
- it('should fail on invalid utterance', async function () {
82
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
83
- await scriptingProvider.Build()
84
- const scriptingContext = scriptingProvider._buildScriptContext()
85
- scriptingProvider.AddUtterances({
86
- name: 'utt1',
87
- utterances: ['TEXT1', 'TEXT2']
88
- })
89
-
90
- const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt2' })
91
- assert.isArray(tomatch)
92
- assert.equal(tomatch.length, 1)
93
- assert.equal(tomatch[0], 'utt2')
94
- try {
95
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatch, 'test1')
96
- assert.fail('expected error')
97
- } catch (err) {
98
- assert.isTrue(err.message.indexOf('Bot response') > 0)
99
- assert.isNotNull(err.context)
100
- assert.isNotNull(err.context.cause)
101
- assert.isArray(err.context.cause.expected)
102
- assert.deepEqual(err.context.cause.expected, tomatch)
103
- assert.equal(err.context.cause.actual, 'TEXT1')
104
- }
105
- })
106
- it('should fail on unresolved utterance', async function () {
107
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
108
- await scriptingProvider.Build()
109
- const scriptingContext = scriptingProvider._buildScriptContext()
110
- scriptingProvider.AddUtterances({
111
- name: 'utt1',
112
- utterances: ['TEXT1', 'TEXT2']
113
- })
114
- try {
115
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1', 'utt1', 'test1')
116
- assert.fail('expected error')
117
- } catch (err) {
118
- assert.isTrue(err.message.indexOf('Bot response') > 0)
119
- assert.isNotNull(err.context)
120
- assert.isNotNull(err.context.cause)
121
- assert.isArray(err.context.cause.expected)
122
- assert.deepEqual(err.context.cause.expected, ['utt1'])
123
- assert.equal(err.context.cause.actual, 'TEXT1')
124
- }
125
- })
126
- it('should resolve and format utterance args', async function () {
127
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
128
- await scriptingProvider.Build()
129
- const scriptingContext = scriptingProvider._buildScriptContext()
130
- scriptingProvider.AddUtterances({
131
- name: 'utt1',
132
- utterances: ['TEXT1 %s', 'TEXT2 %s']
133
- })
134
-
135
- const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt1 hello' })
136
- assert.isArray(tomatch)
137
- assert.equal(tomatch.length, 2)
138
- assert.equal(tomatch[0], 'TEXT1 hello')
139
- assert.equal(tomatch[1], 'TEXT2 hello')
140
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1 hello', tomatch, 'test1')
141
- })
142
- it('should resolve and append utterance args', async function () {
143
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
144
- await scriptingProvider.Build()
145
- const scriptingContext = scriptingProvider._buildScriptContext()
146
- scriptingProvider.AddUtterances({
147
- name: 'utt1',
148
- utterances: ['TEXT1', 'TEXT2']
149
- })
150
-
151
- const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt1 hello' })
152
- assert.isArray(tomatch)
153
- assert.equal(tomatch.length, 2)
154
- assert.equal(tomatch[0], 'TEXT1 hello')
155
- assert.equal(tomatch[1], 'TEXT2 hello')
156
- scriptingContext.scriptingEvents.assertBotResponse('TEXT1 hello', tomatch, 'test1')
48
+ assert.isArray(convos)
49
+ assert.equal(convos.length, 1)
50
+ })
157
51
  })
158
52
 
159
- describe('should resolve utterance with ambiguous scripting memory variable (with a debug message)', function () {
160
- it('expected none, found $name', async function () {
53
+ describe('_resolveUtterances', function () {
54
+ it('should resolve utterance', async function () {
161
55
  const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
162
56
  await scriptingProvider.Build()
163
57
  const scriptingContext = scriptingProvider._buildScriptContext()
164
58
  scriptingProvider.AddUtterances({
165
59
  name: 'utt1',
166
- utterances: ['Hi!', 'Hi $name']
60
+ utterances: ['TEXT1', 'TEXT2']
167
61
  })
168
62
 
169
63
  const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt1' })
170
64
  assert.isArray(tomatch)
171
65
  assert.equal(tomatch.length, 2)
172
- assert.equal(tomatch[0], 'Hi!')
173
- assert.equal(tomatch[1], 'Hi $name')
66
+ assert.equal(tomatch[0], 'TEXT1')
67
+ assert.equal(tomatch[1], 'TEXT2')
68
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatch, 'test1')
69
+ })
70
+ it('should resolve multiple utterance', async function () {
71
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
72
+ await scriptingProvider.Build()
73
+ const scriptingContext = scriptingProvider._buildScriptContext()
74
+ scriptingProvider.AddUtterances([{
75
+ name: 'utt1',
76
+ utterances: ['TEXT1', 'TEXT2']
77
+ },
78
+ {
79
+ name: 'utt2',
80
+ utterances: ['TEXT3', 'TEXT4']
81
+ }])
82
+
83
+ const tomatchUtt1 = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt1' })
84
+ assert.isArray(tomatchUtt1)
85
+ assert.equal(tomatchUtt1.length, 2)
86
+ assert.equal(tomatchUtt1[0], 'TEXT1')
87
+ assert.equal(tomatchUtt1[1], 'TEXT2')
88
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatchUtt1, 'test1')
89
+ const tomatchUtt2 = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt2' })
90
+ assert.isArray(tomatchUtt2)
91
+ assert.equal(tomatchUtt2.length, 2)
92
+ assert.equal(tomatchUtt2[0], 'TEXT3')
93
+ assert.equal(tomatchUtt2[1], 'TEXT4')
174
94
  })
95
+ it('should resolve null on invalid utterance', async function () {
96
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
97
+ await scriptingProvider.Build()
98
+ const scriptingContext = scriptingProvider._buildScriptContext()
99
+ scriptingProvider.AddUtterances({
100
+ name: 'utt1',
101
+ utterances: ['TEXT1', 'TEXT2']
102
+ })
175
103
 
176
- it('expected none, found $name in different Utterance', async function () {
104
+ const tomatch = scriptingContext.scriptingEvents.resolveUtterance({
105
+ utterance: 'utt2',
106
+ resolveEmptyIfUnknown: true
107
+ })
108
+ assert.isNull(tomatch)
109
+ })
110
+ it('should fail on invalid utterance', async function () {
111
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
112
+ await scriptingProvider.Build()
113
+ const scriptingContext = scriptingProvider._buildScriptContext()
114
+ scriptingProvider.AddUtterances({
115
+ name: 'utt1',
116
+ utterances: ['TEXT1', 'TEXT2']
117
+ })
118
+
119
+ const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt2' })
120
+ assert.isArray(tomatch)
121
+ assert.equal(tomatch.length, 1)
122
+ assert.equal(tomatch[0], 'utt2')
123
+ try {
124
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1', tomatch, 'test1')
125
+ assert.fail('expected error')
126
+ } catch (err) {
127
+ assert.isTrue(err.message.indexOf('Bot response') > 0)
128
+ assert.isNotNull(err.context)
129
+ assert.isNotNull(err.context.cause)
130
+ assert.isArray(err.context.cause.expected)
131
+ assert.deepEqual(err.context.cause.expected, tomatch)
132
+ assert.equal(err.context.cause.actual, 'TEXT1')
133
+ }
134
+ })
135
+ it('should fail on unresolved utterance', async function () {
177
136
  const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
178
137
  await scriptingProvider.Build()
179
138
  const scriptingContext = scriptingProvider._buildScriptContext()
180
139
  scriptingProvider.AddUtterances({
181
140
  name: 'utt1',
182
- utterances: ['Hi!']
141
+ utterances: ['TEXT1', 'TEXT2']
183
142
  })
143
+ try {
144
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1', 'utt1', 'test1')
145
+ assert.fail('expected error')
146
+ } catch (err) {
147
+ assert.isTrue(err.message.indexOf('Bot response') > 0)
148
+ assert.isNotNull(err.context)
149
+ assert.isNotNull(err.context.cause)
150
+ assert.isArray(err.context.cause.expected)
151
+ assert.deepEqual(err.context.cause.expected, ['utt1'])
152
+ assert.equal(err.context.cause.actual, 'TEXT1')
153
+ }
154
+ })
155
+ it('should resolve and format utterance args', async function () {
156
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
157
+ await scriptingProvider.Build()
158
+ const scriptingContext = scriptingProvider._buildScriptContext()
184
159
  scriptingProvider.AddUtterances({
185
160
  name: 'utt1',
186
- utterances: ['Hi $name']
161
+ utterances: ['TEXT1 %s', 'TEXT2 %s']
187
162
  })
188
163
 
189
- const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt1' })
164
+ const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt1 hello' })
190
165
  assert.isArray(tomatch)
191
166
  assert.equal(tomatch.length, 2)
192
- assert.equal(tomatch[0], 'Hi!')
193
- assert.equal(tomatch[1], 'Hi $name')
167
+ assert.equal(tomatch[0], 'TEXT1 hello')
168
+ assert.equal(tomatch[1], 'TEXT2 hello')
169
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1 hello', tomatch, 'test1')
194
170
  })
195
-
196
- it('expected $name, found none', async function () {
171
+ it('should resolve and append utterance args', async function () {
197
172
  const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
198
173
  await scriptingProvider.Build()
199
174
  const scriptingContext = scriptingProvider._buildScriptContext()
200
175
  scriptingProvider.AddUtterances({
201
176
  name: 'utt1',
202
- utterances: ['Hi $name', 'Hi!']
177
+ utterances: ['TEXT1', 'TEXT2']
203
178
  })
204
179
 
205
- const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt1' })
180
+ const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt1 hello' })
206
181
  assert.isArray(tomatch)
207
182
  assert.equal(tomatch.length, 2)
208
- assert.equal(tomatch[0], 'Hi $name')
209
- assert.equal(tomatch[1], 'Hi!')
183
+ assert.equal(tomatch[0], 'TEXT1 hello')
184
+ assert.equal(tomatch[1], 'TEXT2 hello')
185
+ scriptingContext.scriptingEvents.assertBotResponse('TEXT1 hello', tomatch, 'test1')
210
186
  })
211
- })
212
- })
213
187
 
214
- describe('scriptingProvider._isValidAsserterType', function () {
215
- it('valid asserterType', async function () {
216
- const scriptingProvider = new ScriptingProvider()
217
- assert.equal(scriptingProvider._isValidAsserterType('assertConvoStep'), true)
218
- })
219
- it('invalid asserterType', async function () {
220
- const scriptingProvider = new ScriptingProvider()
221
- assert.equal(scriptingProvider._isValidAsserterType('assertStep'), false)
222
- })
223
- })
188
+ describe('should resolve utterance with ambiguous scripting memory variable (with a debug message)', function () {
189
+ it('expected none, found $name', async function () {
190
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
191
+ await scriptingProvider.Build()
192
+ const scriptingContext = scriptingProvider._buildScriptContext()
193
+ scriptingProvider.AddUtterances({
194
+ name: 'utt1',
195
+ utterances: ['Hi!', 'Hi $name']
196
+ })
197
+
198
+ const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt1' })
199
+ assert.isArray(tomatch)
200
+ assert.equal(tomatch.length, 2)
201
+ assert.equal(tomatch[0], 'Hi!')
202
+ assert.equal(tomatch[1], 'Hi $name')
203
+ })
224
204
 
225
- describe('scriptingProvider._tagAndCleanupUtterances', function () {
226
- it('positive case remove empty String from utterances', async function () {
227
- const scriptingProvider = new ScriptingProvider()
228
- const utterances = ['don\'t understand', 'sorry', '']
229
- const fileUtterances = [{ name: 'INCOMPREHENSION', utterances }]
230
- const actualResult = scriptingProvider._tagAndCleanupUtterances(fileUtterances, 'mydir', 'incomprehension.utterances.txt')
231
- expect(actualResult[0].utterances).to.eql(utterances.slice(0, 2))
232
- })
233
- })
205
+ it('expected none, found $name in different Utterance', async function () {
206
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
207
+ await scriptingProvider.Build()
208
+ const scriptingContext = scriptingProvider._buildScriptContext()
209
+ scriptingProvider.AddUtterances({
210
+ name: 'utt1',
211
+ utterances: ['Hi!']
212
+ })
213
+ scriptingProvider.AddUtterances({
214
+ name: 'utt1',
215
+ utterances: ['Hi $name']
216
+ })
217
+
218
+ const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt1' })
219
+ assert.isArray(tomatch)
220
+ assert.equal(tomatch.length, 2)
221
+ assert.equal(tomatch[0], 'Hi!')
222
+ assert.equal(tomatch[1], 'Hi $name')
223
+ })
234
224
 
235
- describe('scriptingProvider.ExpandConvos', function () {
236
- it('should build convos for utterance', async function () {
237
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
238
- await scriptingProvider.Build()
239
- scriptingProvider.AddUtterances({
240
- name: 'utt1',
241
- utterances: ['TEXT1', 'TEXT2']
242
- })
243
- scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), {
244
- header: {
245
- name: 'test convo'
246
- },
247
- conversation: [
248
- {
249
- sender: 'me',
250
- messageText: 'utt1'
251
- }
252
- ]
253
- }))
254
-
255
- scriptingProvider.ExpandConvos()
256
- assert.equal(scriptingProvider.convos.length, 2)
257
- assert.equal(scriptingProvider.convos[0].conversation.length, 1)
258
- assert.equal(scriptingProvider.convos[0].header.name, 'test convo/utt1-L1')
259
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
260
- assert.equal(scriptingProvider.convos[1].conversation.length, 1)
261
- assert.equal(scriptingProvider.convos[1].header.name, 'test convo/utt1-L2')
262
- assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
263
- })
264
- it('should build convos for utterance with parameters', async function () {
265
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
266
- await scriptingProvider.Build()
267
- scriptingProvider.AddUtterances({
268
- name: 'utt1',
269
- utterances: ['TEXT1 %s-%d', 'TEXT2']
270
- })
271
- scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), {
272
- header: {
273
- name: 'test convo'
274
- },
275
- conversation: [
276
- {
277
- sender: 'me',
278
- messageText: 'utt1 arg0 1'
279
- }
280
- ]
281
- }))
282
-
283
- scriptingProvider.ExpandConvos()
284
- assert.equal(scriptingProvider.convos.length, 2)
285
- assert.equal(scriptingProvider.convos[0].conversation.length, 1)
286
- assert.equal(scriptingProvider.convos[0].header.name, 'test convo/utt1-L1')
287
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1 arg0-1')
288
- assert.equal(scriptingProvider.convos[1].conversation.length, 1)
289
- assert.equal(scriptingProvider.convos[1].header.name, 'test convo/utt1-L2')
290
- assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2 arg0 1')
291
- })
292
- it('should build convos for utterance with whitespace', async function () {
293
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
294
- await scriptingProvider.Build()
295
- scriptingProvider.AddUtterances({
296
- name: 'utt with some whitespace',
297
- utterances: ['TEXT1', 'TEXT2']
298
- })
299
- scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), {
300
- header: {
301
- name: 'test convo'
302
- },
303
- conversation: [
304
- {
305
- sender: 'me',
306
- messageText: 'utt with some whitespace'
307
- }
308
- ]
309
- }))
310
-
311
- scriptingProvider.ExpandConvos()
312
- assert.equal(scriptingProvider.convos.length, 2)
313
- assert.equal(scriptingProvider.convos[0].conversation.length, 1)
314
- assert.equal(scriptingProvider.convos[0].header.name, 'test convo/utt with some whitespace-L1')
315
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
316
- assert.equal(scriptingProvider.convos[1].conversation.length, 1)
317
- assert.equal(scriptingProvider.convos[1].header.name, 'test convo/utt with some whitespace-L2')
318
- assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
225
+ it('expected $name, found none', async function () {
226
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
227
+ await scriptingProvider.Build()
228
+ const scriptingContext = scriptingProvider._buildScriptContext()
229
+ scriptingProvider.AddUtterances({
230
+ name: 'utt1',
231
+ utterances: ['Hi $name', 'Hi!']
232
+ })
233
+
234
+ const tomatch = scriptingContext.scriptingEvents.resolveUtterance({ utterance: 'utt1' })
235
+ assert.isArray(tomatch)
236
+ assert.equal(tomatch.length, 2)
237
+ assert.equal(tomatch[0], 'Hi $name')
238
+ assert.equal(tomatch[1], 'Hi!')
239
+ })
240
+ })
319
241
  })
320
- describe('should build convos for SCRIPTING_UTTEXPANSION_NAMING_MODE', function () {
321
- const utterances = {
322
- name: 'uttText',
323
- utterances: ['TEXT1 01234567890123456789', 'TEXT2 01234567890123456789']
324
- }
325
- const convoUtterances = {
326
- header: {
327
- name: 'test convo'
328
- },
329
- conversation: [
330
- {
331
- sender: 'me',
332
- messageText: 'uttText'
333
- }
334
- ]
335
- }
336
-
337
- it('SCRIPTING_UTTEXPANSION_NAMING_MODE=justLineNumber', async function () {
338
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
339
- await scriptingProvider.Build()
340
- scriptingProvider.AddUtterances(utterances)
341
- scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), convoUtterances))
342
242
 
343
- scriptingProvider.ExpandConvos()
344
- assert.equal(scriptingProvider.convos.length, 2)
345
- assert.equal(scriptingProvider.convos[0].conversation.length, 1)
346
- assert.equal(scriptingProvider.convos[0].header.name, 'test convo/uttText-L1')
347
- assert.equal(scriptingProvider.convos[1].header.name, 'test convo/uttText-L2')
243
+ describe('_isValidAsserterType', function () {
244
+ it('valid asserterType', async function () {
245
+ const scriptingProvider = new ScriptingProvider()
246
+ assert.equal(scriptingProvider._isValidAsserterType('assertConvoStep'), true)
348
247
  })
248
+ it('invalid asserterType', async function () {
249
+ const scriptingProvider = new ScriptingProvider()
250
+ assert.equal(scriptingProvider._isValidAsserterType('assertStep'), false)
251
+ })
252
+ })
349
253
 
350
- it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance', async function () {
351
- const scriptingProvider = new ScriptingProvider(Object.assign(
352
- {},
353
- DefaultCapabilities,
354
- {
355
- [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'utterance'
356
- }
357
- ))
358
- await scriptingProvider.Build()
359
- scriptingProvider.AddUtterances(utterances)
360
- scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), convoUtterances))
361
-
362
- scriptingProvider.ExpandConvos()
363
- assert.equal(scriptingProvider.convos.length, 2)
364
- assert.equal(scriptingProvider.convos[0].conversation.length, 1)
365
- assert.equal(scriptingProvider.convos[0].header.name, 'test convo/uttText-L1-TEXT1 0123456...')
366
- assert.equal(scriptingProvider.convos[1].header.name, 'test convo/uttText-L2-TEXT2 0123456...')
254
+ describe('_tagAndCleanupUtterances', function () {
255
+ it('positive case remove empty String from utterances', async function () {
256
+ const scriptingProvider = new ScriptingProvider()
257
+ const utterances = ['don\'t understand', 'sorry', '']
258
+ const fileUtterances = [{
259
+ name: 'INCOMPREHENSION',
260
+ utterances
261
+ }]
262
+ const actualResult = scriptingProvider._tagAndCleanupUtterances(fileUtterances, 'mydir', 'incomprehension.utterances.txt')
263
+ expect(actualResult[0].utterances).to.eql(utterances.slice(0, 2))
367
264
  })
265
+ })
368
266
 
369
- it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance, turn length off', async function () {
370
- const scriptingProvider = new ScriptingProvider(Object.assign(
371
- {},
372
- DefaultCapabilities,
373
- {
374
- [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'utterance',
375
- [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_UTTERANCE_MAX]: null
376
- }
377
- ))
267
+ describe('ExpandConvos', function () {
268
+ it('should build convos for utterance', async function () {
269
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
378
270
  await scriptingProvider.Build()
379
- scriptingProvider.AddUtterances(utterances)
380
- scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), convoUtterances))
271
+ scriptingProvider.AddUtterances({
272
+ name: 'utt1',
273
+ utterances: ['TEXT1', 'TEXT2']
274
+ })
275
+ scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), {
276
+ header: {
277
+ name: 'test convo'
278
+ },
279
+ conversation: [
280
+ {
281
+ sender: 'me',
282
+ messageText: 'utt1'
283
+ }
284
+ ]
285
+ }))
381
286
 
382
287
  scriptingProvider.ExpandConvos()
383
288
  assert.equal(scriptingProvider.convos.length, 2)
384
289
  assert.equal(scriptingProvider.convos[0].conversation.length, 1)
385
- assert.equal(scriptingProvider.convos[0].header.name, 'test convo/uttText-L1-TEXT1 01234567890123456789')
386
- assert.equal(scriptingProvider.convos[1].header.name, 'test convo/uttText-L2-TEXT2 01234567890123456789')
290
+ assert.equal(scriptingProvider.convos[0].header.name, 'test convo/utt1-L1')
291
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
292
+ assert.equal(scriptingProvider.convos[1].conversation.length, 1)
293
+ assert.equal(scriptingProvider.convos[1].header.name, 'test convo/utt1-L2')
294
+ assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
387
295
  })
388
-
389
- it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance len=10', async function () {
390
- const scriptingProvider = new ScriptingProvider(Object.assign(
391
- {},
392
- DefaultCapabilities,
393
- {
394
- [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'utterance',
395
- [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_UTTERANCE_MAX]: 10
396
- }
397
- ))
296
+ it('should build convos for utterance with parameters', async function () {
297
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
398
298
  await scriptingProvider.Build()
399
- scriptingProvider.AddUtterances(utterances)
400
- scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), convoUtterances))
299
+ scriptingProvider.AddUtterances({
300
+ name: 'utt1',
301
+ utterances: ['TEXT1 %s-%d', 'TEXT2']
302
+ })
303
+ scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), {
304
+ header: {
305
+ name: 'test convo'
306
+ },
307
+ conversation: [
308
+ {
309
+ sender: 'me',
310
+ messageText: 'utt1 arg0 1'
311
+ }
312
+ ]
313
+ }))
401
314
 
402
315
  scriptingProvider.ExpandConvos()
403
316
  assert.equal(scriptingProvider.convos.length, 2)
404
317
  assert.equal(scriptingProvider.convos[0].conversation.length, 1)
405
- assert.equal(scriptingProvider.convos[0].header.name, 'test convo/uttText-L1-TEXT1 0...')
406
- assert.equal(scriptingProvider.convos[1].header.name, 'test convo/uttText-L2-TEXT2 0...')
407
- })
408
- it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance userinputs', async function () {
409
- const scriptingProvider = new ScriptingProvider(Object.assign(
410
- {},
411
- DefaultCapabilities,
412
- {
413
- [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'utterance'
414
- }
415
- ))
318
+ assert.equal(scriptingProvider.convos[0].header.name, 'test convo/utt1-L1')
319
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1 arg0-1')
320
+ assert.equal(scriptingProvider.convos[1].conversation.length, 1)
321
+ assert.equal(scriptingProvider.convos[1].header.name, 'test convo/utt1-L2')
322
+ assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2 arg0 1')
323
+ })
324
+ it('should build convos for utterance with whitespace', async function () {
325
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
416
326
  await scriptingProvider.Build()
327
+ scriptingProvider.AddUtterances({
328
+ name: 'utt with some whitespace',
329
+ utterances: ['TEXT1', 'TEXT2']
330
+ })
417
331
  scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), {
418
332
  header: {
419
333
  name: 'test convo'
420
334
  },
421
- sourceTag: {},
422
335
  conversation: [
423
336
  {
424
337
  sender: 'me',
425
- userInputs: [
426
- {
427
- name: 'BUTTON',
428
- args: ['button1']
429
- },
430
- {
431
- name: 'MEDIA',
432
- args: ['test1.jpg', 'test2 01234567890123456789.jpg', 'test3.jpg']
433
- }
434
- ]
338
+ messageText: 'utt with some whitespace'
435
339
  }
436
340
  ]
437
341
  }))
438
342
 
439
343
  scriptingProvider.ExpandConvos()
440
- assert.equal(scriptingProvider.convos.length, 3)
344
+ assert.equal(scriptingProvider.convos.length, 2)
441
345
  assert.equal(scriptingProvider.convos[0].conversation.length, 1)
442
- assert.equal(scriptingProvider.convos[0].header.name, 'test convo/MEDIA-L1-test1.jpg')
443
- assert.equal(scriptingProvider.convos[1].header.name, 'test convo/MEDIA-L2-test2 0123456...')
444
- assert.equal(scriptingProvider.convos[2].header.name, 'test convo/MEDIA-L3-test3.jpg')
445
- })
446
- it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance userinputs and utterances', async function () {
447
- const scriptingProvider = new ScriptingProvider(Object.assign(
448
- {},
449
- DefaultCapabilities,
450
- {
451
- [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'utterance'
452
- }
453
- ))
454
- await scriptingProvider.Build()
455
- scriptingProvider.AddUtterances(utterances)
456
- scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), {
346
+ assert.equal(scriptingProvider.convos[0].header.name, 'test convo/utt with some whitespace-L1')
347
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
348
+ assert.equal(scriptingProvider.convos[1].conversation.length, 1)
349
+ assert.equal(scriptingProvider.convos[1].header.name, 'test convo/utt with some whitespace-L2')
350
+ assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
351
+ })
352
+ describe('should build convos for SCRIPTING_UTTEXPANSION_NAMING_MODE', function () {
353
+ const utterances = {
354
+ name: 'uttText',
355
+ utterances: ['TEXT1 01234567890123456789', 'TEXT2 01234567890123456789']
356
+ }
357
+ const convoUtterances = {
457
358
  header: {
458
359
  name: 'test convo'
459
360
  },
460
- sourceTag: {},
461
361
  conversation: [
462
362
  {
463
363
  sender: 'me',
464
- messageText: 'uttText',
465
- userInputs: [
466
- {
467
- name: 'BUTTON',
468
- args: ['button1']
469
- },
470
- {
471
- name: 'MEDIA',
472
- args: ['test1.jpg', 'test2 01234567890123456789.jpg', 'test3.jpg']
473
- }
474
- ]
364
+ messageText: 'uttText'
475
365
  }
476
366
  ]
477
- }))
367
+ }
368
+
369
+ it('SCRIPTING_UTTEXPANSION_NAMING_MODE=justLineNumber', async function () {
370
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
371
+ await scriptingProvider.Build()
372
+ scriptingProvider.AddUtterances(utterances)
373
+ scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), convoUtterances))
374
+
375
+ scriptingProvider.ExpandConvos()
376
+ assert.equal(scriptingProvider.convos.length, 2)
377
+ assert.equal(scriptingProvider.convos[0].conversation.length, 1)
378
+ assert.equal(scriptingProvider.convos[0].header.name, 'test convo/uttText-L1')
379
+ assert.equal(scriptingProvider.convos[1].header.name, 'test convo/uttText-L2')
380
+ })
478
381
 
479
- scriptingProvider.ExpandConvos()
480
- assert.equal(scriptingProvider.convos.length, 5)
481
- assert.equal(scriptingProvider.convos[0].conversation.length, 1)
482
- assert.equal(scriptingProvider.convos[0].header.name, 'test convo/MEDIA-L1-test1.jpg')
483
- assert.equal(scriptingProvider.convos[1].header.name, 'test convo/MEDIA-L2-test2 0123456...')
484
- assert.equal(scriptingProvider.convos[2].header.name, 'test convo/MEDIA-L3-test3.jpg')
485
- assert.equal(scriptingProvider.convos[3].header.name, 'test convo/uttText-L1-TEXT1 0123456...')
486
- assert.equal(scriptingProvider.convos[4].header.name, 'test convo/uttText-L2-TEXT2 0123456...')
382
+ it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance', async function () {
383
+ const scriptingProvider = new ScriptingProvider(Object.assign(
384
+ {},
385
+ DefaultCapabilities,
386
+ {
387
+ [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'utterance'
388
+ }
389
+ ))
390
+ await scriptingProvider.Build()
391
+ scriptingProvider.AddUtterances(utterances)
392
+ scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), convoUtterances))
393
+
394
+ scriptingProvider.ExpandConvos()
395
+ assert.equal(scriptingProvider.convos.length, 2)
396
+ assert.equal(scriptingProvider.convos[0].conversation.length, 1)
397
+ assert.equal(scriptingProvider.convos[0].header.name, 'test convo/uttText-L1-TEXT1 0123456...')
398
+ assert.equal(scriptingProvider.convos[1].header.name, 'test convo/uttText-L2-TEXT2 0123456...')
399
+ })
400
+
401
+ it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance, turn length off', async function () {
402
+ const scriptingProvider = new ScriptingProvider(Object.assign(
403
+ {},
404
+ DefaultCapabilities,
405
+ {
406
+ [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'utterance',
407
+ [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_UTTERANCE_MAX]: null
408
+ }
409
+ ))
410
+ await scriptingProvider.Build()
411
+ scriptingProvider.AddUtterances(utterances)
412
+ scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), convoUtterances))
413
+
414
+ scriptingProvider.ExpandConvos()
415
+ assert.equal(scriptingProvider.convos.length, 2)
416
+ assert.equal(scriptingProvider.convos[0].conversation.length, 1)
417
+ assert.equal(scriptingProvider.convos[0].header.name, 'test convo/uttText-L1-TEXT1 01234567890123456789')
418
+ assert.equal(scriptingProvider.convos[1].header.name, 'test convo/uttText-L2-TEXT2 01234567890123456789')
419
+ })
420
+
421
+ it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance len=10', async function () {
422
+ const scriptingProvider = new ScriptingProvider(Object.assign(
423
+ {},
424
+ DefaultCapabilities,
425
+ {
426
+ [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'utterance',
427
+ [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_UTTERANCE_MAX]: 10
428
+ }
429
+ ))
430
+ await scriptingProvider.Build()
431
+ scriptingProvider.AddUtterances(utterances)
432
+ scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), convoUtterances))
433
+
434
+ scriptingProvider.ExpandConvos()
435
+ assert.equal(scriptingProvider.convos.length, 2)
436
+ assert.equal(scriptingProvider.convos[0].conversation.length, 1)
437
+ assert.equal(scriptingProvider.convos[0].header.name, 'test convo/uttText-L1-TEXT1 0...')
438
+ assert.equal(scriptingProvider.convos[1].header.name, 'test convo/uttText-L2-TEXT2 0...')
439
+ })
440
+ it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance userinputs', async function () {
441
+ const scriptingProvider = new ScriptingProvider(Object.assign(
442
+ {},
443
+ DefaultCapabilities,
444
+ {
445
+ [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'utterance'
446
+ }
447
+ ))
448
+ await scriptingProvider.Build()
449
+ scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), {
450
+ header: {
451
+ name: 'test convo'
452
+ },
453
+ sourceTag: {},
454
+ conversation: [
455
+ {
456
+ sender: 'me',
457
+ userInputs: [
458
+ {
459
+ name: 'BUTTON',
460
+ args: ['button1']
461
+ },
462
+ {
463
+ name: 'MEDIA',
464
+ args: ['test1.jpg', 'test2 01234567890123456789.jpg', 'test3.jpg']
465
+ }
466
+ ]
467
+ }
468
+ ]
469
+ }))
470
+
471
+ scriptingProvider.ExpandConvos()
472
+ assert.equal(scriptingProvider.convos.length, 3)
473
+ assert.equal(scriptingProvider.convos[0].conversation.length, 1)
474
+ assert.equal(scriptingProvider.convos[0].header.name, 'test convo/MEDIA-L1-test1.jpg')
475
+ assert.equal(scriptingProvider.convos[1].header.name, 'test convo/MEDIA-L2-test2 0123456...')
476
+ assert.equal(scriptingProvider.convos[2].header.name, 'test convo/MEDIA-L3-test3.jpg')
477
+ })
478
+ it('SCRIPTING_UTTEXPANSION_NAMING_MODE=utterance userinputs and utterances', async function () {
479
+ const scriptingProvider = new ScriptingProvider(Object.assign(
480
+ {},
481
+ DefaultCapabilities,
482
+ {
483
+ [Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'utterance'
484
+ }
485
+ ))
486
+ await scriptingProvider.Build()
487
+ scriptingProvider.AddUtterances(utterances)
488
+ scriptingProvider.AddConvos(new Convo(scriptingProvider._buildScriptContext(), {
489
+ header: {
490
+ name: 'test convo'
491
+ },
492
+ sourceTag: {},
493
+ conversation: [
494
+ {
495
+ sender: 'me',
496
+ messageText: 'uttText',
497
+ userInputs: [
498
+ {
499
+ name: 'BUTTON',
500
+ args: ['button1']
501
+ },
502
+ {
503
+ name: 'MEDIA',
504
+ args: ['test1.jpg', 'test2 01234567890123456789.jpg', 'test3.jpg']
505
+ }
506
+ ]
507
+ }
508
+ ]
509
+ }))
510
+
511
+ scriptingProvider.ExpandConvos()
512
+ assert.equal(scriptingProvider.convos.length, 5)
513
+ assert.equal(scriptingProvider.convos[0].conversation.length, 1)
514
+ assert.equal(scriptingProvider.convos[0].header.name, 'test convo/MEDIA-L1-test1.jpg')
515
+ assert.equal(scriptingProvider.convos[1].header.name, 'test convo/MEDIA-L2-test2 0123456...')
516
+ assert.equal(scriptingProvider.convos[2].header.name, 'test convo/MEDIA-L3-test3.jpg')
517
+ assert.equal(scriptingProvider.convos[3].header.name, 'test convo/uttText-L1-TEXT1 0123456...')
518
+ assert.equal(scriptingProvider.convos[4].header.name, 'test convo/uttText-L2-TEXT2 0123456...')
519
+ })
487
520
  })
488
521
  })
489
- })
490
522
 
491
- describe('scriptingProvider.ExpandUtterancesToConvos', function () {
492
- it('should build plain convos for utterance', async function () {
493
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
494
- await scriptingProvider.Build()
495
- scriptingProvider.AddUtterances({
496
- name: 'utt1',
497
- utterances: ['TEXT1', 'TEXT2']
498
- })
499
-
500
- scriptingProvider.ExpandUtterancesToConvos()
501
- assert.equal(scriptingProvider.convos.length, 1)
502
- assert.equal(scriptingProvider.convos[0].conversation.length, 2)
503
- assert.equal(scriptingProvider.convos[0].header.name, 'utt1')
504
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'utt1')
505
-
506
- scriptingProvider.ExpandConvos()
507
- assert.equal(scriptingProvider.convos.length, 2)
508
- assert.equal(scriptingProvider.convos[0].conversation.length, 2)
509
- assert.equal(scriptingProvider.convos[0].header.name, 'utt1/utt1-L1')
510
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
511
- assert.equal(scriptingProvider.convos[0].toString(), '1 utt1/utt1-L1 (Expanded Utterances - utt1) ({ origUttName: \'utt1\', origConvoName: \'utt1\' }): Step 1 - tell utterance: #me - TEXT1 SKIP_BOT_UNCONSUMED(no args) | Step 2 - check bot response: #bot - ')
512
- assert.equal(scriptingProvider.convos[1].conversation.length, 2)
513
- assert.equal(scriptingProvider.convos[1].header.name, 'utt1/utt1-L2')
514
- assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
515
- assert.equal(scriptingProvider.convos[1].toString(), '2 utt1/utt1-L2 (Expanded Utterances - utt1) ({ origUttName: \'utt1\', origConvoName: \'utt1\' }): Step 1 - tell utterance: #me - TEXT2 SKIP_BOT_UNCONSUMED(no args) | Step 2 - check bot response: #bot - ')
516
- })
517
- it('should add leading zeros for utterance tags', async function () {
518
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
519
- await scriptingProvider.Build()
520
- scriptingProvider.AddUtterances({
521
- name: 'utt1',
522
- utterances: Array.from(Array(10000).keys()).map(i => `TEXT${i + 1}`)
523
- })
524
-
525
- scriptingProvider.ExpandUtterancesToConvos()
526
- scriptingProvider.ExpandConvos()
527
-
528
- assert.equal(scriptingProvider.convos.length, 10000)
529
- assert.equal(scriptingProvider.convos[0].conversation.length, 2)
530
- assert.equal(scriptingProvider.convos[0].header.name, 'utt1/utt1-L00001')
531
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
532
- assert.equal(scriptingProvider.convos[0].toString(), '1 utt1/utt1-L00001 (Expanded Utterances - utt1) ({ origUttName: \'utt1\', origConvoName: \'utt1\' }): Step 1 - tell utterance: #me - TEXT1 SKIP_BOT_UNCONSUMED(no args) | Step 2 - check bot response: #bot - ')
533
- assert.equal(scriptingProvider.convos[1].conversation.length, 2)
534
- assert.equal(scriptingProvider.convos[1].header.name, 'utt1/utt1-L00002')
535
- assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
536
- assert.equal(scriptingProvider.convos[1].toString(), '2 utt1/utt1-L00002 (Expanded Utterances - utt1) ({ origUttName: \'utt1\', origConvoName: \'utt1\' }): Step 1 - tell utterance: #me - TEXT2 SKIP_BOT_UNCONSUMED(no args) | Step 2 - check bot response: #bot - ')
537
- })
538
- it('should build incomprehension convos for utterance', async function () {
539
- const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities, { SCRIPTING_UTTEXPANSION_INCOMPREHENSION: 'INCOMPREHENSION' }))
540
- await scriptingProvider.Build()
541
- scriptingProvider.AddUtterances({
542
- name: 'utt1',
543
- utterances: ['TEXT1', 'TEXT2']
544
- })
545
- scriptingProvider.AddUtterances({
546
- name: 'INCOMPREHENSION',
547
- utterances: ['INCOMPREHENSION1', 'INCOMPREHENSION2']
548
- })
549
-
550
- scriptingProvider.ExpandUtterancesToConvos()
551
- assert.equal(scriptingProvider.convos.length, 1)
552
- assert.equal(scriptingProvider.convos[0].conversation.length, 2)
553
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'utt1')
554
- assert.equal(scriptingProvider.convos[0].conversation[1].messageText, 'INCOMPREHENSION')
555
- assert.equal(scriptingProvider.convos[0].conversation[1].not, true)
556
-
557
- scriptingProvider.ExpandConvos()
558
- assert.equal(scriptingProvider.convos.length, 2)
559
- assert.equal(scriptingProvider.convos[0].conversation.length, 2)
560
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
561
- assert.equal(scriptingProvider.convos[0].conversation[1].messageText, 'INCOMPREHENSION')
562
- assert.equal(scriptingProvider.convos[0].conversation[1].not, true)
563
- assert.equal(scriptingProvider.convos[1].conversation.length, 2)
564
- assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
565
- assert.equal(scriptingProvider.convos[1].conversation[1].messageText, 'INCOMPREHENSION')
566
- assert.equal(scriptingProvider.convos[1].conversation[1].not, true)
567
- })
568
- it('should build intent check convos for utterance', async function () {
569
- const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities, { SCRIPTING_UTTEXPANSION_USENAMEASINTENT: true }))
570
- await scriptingProvider.Build()
571
- scriptingProvider.AddUtterances({
572
- name: 'utt1',
573
- utterances: ['TEXT1', 'TEXT2']
574
- })
575
-
576
- scriptingProvider.ExpandUtterancesToConvos()
577
- assert.equal(scriptingProvider.convos.length, 1)
578
- assert.equal(scriptingProvider.convos[0].conversation.length, 2)
579
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'utt1')
580
- assert.equal(scriptingProvider.convos[0].conversation[1].asserters.length, 1)
581
- assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].name, 'INTENT')
582
- assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].args[0], 'utt1')
583
-
584
- scriptingProvider.ExpandConvos()
585
- assert.equal(scriptingProvider.convos.length, 2)
586
- assert.equal(scriptingProvider.convos[0].conversation.length, 2)
587
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
588
- assert.equal(scriptingProvider.convos[0].conversation[1].asserters.length, 1)
589
- assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].name, 'INTENT')
590
- assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].args[0], 'utt1')
591
- assert.equal(scriptingProvider.convos[1].conversation.length, 2)
592
- assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
593
- assert.equal(scriptingProvider.convos[1].conversation[1].asserters.length, 1)
594
- assert.equal(scriptingProvider.convos[1].conversation[1].asserters[0].name, 'INTENT')
595
- assert.equal(scriptingProvider.convos[1].conversation[1].asserters[0].args[0], 'utt1')
596
- })
597
- it('should build intent check convos for utterance (with arg)', async function () {
598
- const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
599
- await scriptingProvider.Build()
600
- scriptingProvider.AddUtterances({
601
- name: 'utt1',
602
- utterances: ['TEXT1', 'TEXT2']
603
- })
604
-
605
- scriptingProvider.ExpandUtterancesToConvos({ useNameAsIntent: true })
606
- assert.equal(scriptingProvider.convos.length, 1)
607
- assert.equal(scriptingProvider.convos[0].conversation.length, 2)
608
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'utt1')
609
- assert.equal(scriptingProvider.convos[0].conversation[1].asserters.length, 1)
610
- assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].name, 'INTENT')
611
- assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].args[0], 'utt1')
612
-
613
- scriptingProvider.ExpandConvos()
614
- assert.equal(scriptingProvider.convos.length, 2)
615
- assert.equal(scriptingProvider.convos[0].conversation.length, 2)
616
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
617
- assert.equal(scriptingProvider.convos[0].conversation[1].asserters.length, 1)
618
- assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].name, 'INTENT')
619
- assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].args[0], 'utt1')
620
- assert.equal(scriptingProvider.convos[1].conversation.length, 2)
621
- assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
622
- assert.equal(scriptingProvider.convos[1].conversation[1].asserters.length, 1)
623
- assert.equal(scriptingProvider.convos[1].conversation[1].asserters[0].name, 'INTENT')
624
- assert.equal(scriptingProvider.convos[1].conversation[1].asserters[0].args[0], 'utt1')
625
- })
626
- it('should build check-only convos for utterance', async function () {
627
- const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
628
- await scriptingProvider.Build()
629
- scriptingProvider.AddUtterances({
630
- name: 'utt1',
631
- utterances: ['TEXT1', 'TEXT2']
632
- })
633
-
634
- scriptingProvider.ExpandUtterancesToConvos()
635
- assert.lengthOf(scriptingProvider.convos, 1)
636
- assert.lengthOf(scriptingProvider.convos[0].conversation, 2)
637
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'utt1')
638
- assert.equal(scriptingProvider.convos[0].conversation[1].messageText, '')
639
- assert.isFalse(scriptingProvider.convos[0].conversation[1].not)
640
-
641
- scriptingProvider.ExpandConvos()
642
- assert.lengthOf(scriptingProvider.convos, 2)
643
- assert.lengthOf(scriptingProvider.convos[0].conversation, 2)
644
- assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
645
- assert.equal(scriptingProvider.convos[0].conversation[1].messageText, '')
646
- assert.isFalse(scriptingProvider.convos[0].conversation[1].not)
647
- assert.lengthOf(scriptingProvider.convos[1].conversation, 2)
648
- assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
649
- assert.equal(scriptingProvider.convos[1].conversation[1].messageText, '')
650
- assert.isFalse(scriptingProvider.convos[1].conversation[1].not)
651
- })
652
- it('should fail incomprehension convos for utterance without incomprehension utt', async function () {
653
- const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities, { SCRIPTING_UTTEXPANSION_INCOMPREHENSION: 'INCOMPREHENSION' }))
654
- await scriptingProvider.Build()
523
+ describe('ExpandUtterancesToConvos', function () {
524
+ it('should build plain convos for utterance', async function () {
525
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
526
+ await scriptingProvider.Build()
527
+ scriptingProvider.AddUtterances({
528
+ name: 'utt1',
529
+ utterances: ['TEXT1', 'TEXT2']
530
+ })
655
531
 
656
- try {
657
532
  scriptingProvider.ExpandUtterancesToConvos()
658
- assert.fail('should have failed')
659
- } catch (err) {
660
- assert.isTrue(err.message.indexOf('incomprehension utterance \'INCOMPREHENSION\' undefined') > 0)
661
- }
662
- })
663
- })
533
+ assert.equal(scriptingProvider.convos.length, 1)
534
+ assert.equal(scriptingProvider.convos[0].conversation.length, 2)
535
+ assert.equal(scriptingProvider.convos[0].header.name, 'utt1')
536
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'utt1')
664
537
 
665
- describe('scriptingProvider.assertBotResponse', function () {
666
- it('should fail with correct error message on single tomatch', async function () {
667
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
668
- await scriptingProvider.Build()
669
- const scriptingContext = scriptingProvider._buildScriptContext()
670
- try {
671
- scriptingContext.scriptingEvents.assertBotResponse('actual', 'expected', 'test1')
672
- assert.fail('expected error')
673
- } catch (err) {
674
- assert.equal(err.message, 'test1: Bot response "actual" expected to match "expected"')
675
- }
676
- })
677
- it('should fail with correct error message on empty bot message', async function () {
678
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
679
- await scriptingProvider.Build()
680
- const scriptingContext = scriptingProvider._buildScriptContext()
681
- try {
682
- scriptingContext.scriptingEvents.assertBotResponse(null, 'expected', 'test1')
683
- assert.fail('expected error')
684
- } catch (err) {
685
- assert.equal(err.message, 'test1: Bot response <no response> expected to match "expected"')
686
- }
687
- })
688
- it('should fail with correct error message on multiple tomatch', async function () {
689
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
690
- await scriptingProvider.Build()
691
- const scriptingContext = scriptingProvider._buildScriptContext()
692
- try {
693
- scriptingContext.scriptingEvents.assertBotResponse('actual', ['expected1', 'expected2'], 'test1')
694
- assert.fail('expected error')
695
- } catch (err) {
696
- assert.equal(err.message, 'test1: Bot response "actual" expected to match one of "expected1", "expected2"')
697
- }
698
- })
699
- })
538
+ scriptingProvider.ExpandConvos()
539
+ assert.equal(scriptingProvider.convos.length, 2)
540
+ assert.equal(scriptingProvider.convos[0].conversation.length, 2)
541
+ assert.equal(scriptingProvider.convos[0].header.name, 'utt1/utt1-L1')
542
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
543
+ assert.equal(scriptingProvider.convos[0].toString(), '1 utt1/utt1-L1 (Expanded Utterances - utt1) ({ origUttName: \'utt1\', origConvoName: \'utt1\' }): Step 1 - tell utterance: #me - TEXT1 SKIP_BOT_UNCONSUMED(no args) | Step 2 - check bot response: #bot - ')
544
+ assert.equal(scriptingProvider.convos[1].conversation.length, 2)
545
+ assert.equal(scriptingProvider.convos[1].header.name, 'utt1/utt1-L2')
546
+ assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
547
+ assert.equal(scriptingProvider.convos[1].toString(), '2 utt1/utt1-L2 (Expanded Utterances - utt1) ({ origUttName: \'utt1\', origConvoName: \'utt1\' }): Step 1 - tell utterance: #me - TEXT2 SKIP_BOT_UNCONSUMED(no args) | Step 2 - check bot response: #bot - ')
548
+ })
549
+ it('should add leading zeros for utterance tags', async function () {
550
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
551
+ await scriptingProvider.Build()
552
+ scriptingProvider.AddUtterances({
553
+ name: 'utt1',
554
+ utterances: Array.from(Array(10000).keys()).map(i => `TEXT${i + 1}`)
555
+ })
556
+
557
+ scriptingProvider.ExpandUtterancesToConvos()
558
+ scriptingProvider.ExpandConvos()
559
+
560
+ assert.equal(scriptingProvider.convos.length, 10000)
561
+ assert.equal(scriptingProvider.convos[0].conversation.length, 2)
562
+ assert.equal(scriptingProvider.convos[0].header.name, 'utt1/utt1-L00001')
563
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
564
+ assert.equal(scriptingProvider.convos[0].toString(), '1 utt1/utt1-L00001 (Expanded Utterances - utt1) ({ origUttName: \'utt1\', origConvoName: \'utt1\' }): Step 1 - tell utterance: #me - TEXT1 SKIP_BOT_UNCONSUMED(no args) | Step 2 - check bot response: #bot - ')
565
+ assert.equal(scriptingProvider.convos[1].conversation.length, 2)
566
+ assert.equal(scriptingProvider.convos[1].header.name, 'utt1/utt1-L00002')
567
+ assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
568
+ assert.equal(scriptingProvider.convos[1].toString(), '2 utt1/utt1-L00002 (Expanded Utterances - utt1) ({ origUttName: \'utt1\', origConvoName: \'utt1\' }): Step 1 - tell utterance: #me - TEXT2 SKIP_BOT_UNCONSUMED(no args) | Step 2 - check bot response: #bot - ')
569
+ })
570
+ it('should build incomprehension convos for utterance', async function () {
571
+ const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities, { SCRIPTING_UTTEXPANSION_INCOMPREHENSION: 'INCOMPREHENSION' }))
572
+ await scriptingProvider.Build()
573
+ scriptingProvider.AddUtterances({
574
+ name: 'utt1',
575
+ utterances: ['TEXT1', 'TEXT2']
576
+ })
577
+ scriptingProvider.AddUtterances({
578
+ name: 'INCOMPREHENSION',
579
+ utterances: ['INCOMPREHENSION1', 'INCOMPREHENSION2']
580
+ })
581
+
582
+ scriptingProvider.ExpandUtterancesToConvos()
583
+ assert.equal(scriptingProvider.convos.length, 1)
584
+ assert.equal(scriptingProvider.convos[0].conversation.length, 2)
585
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'utt1')
586
+ assert.equal(scriptingProvider.convos[0].conversation[1].messageText, 'INCOMPREHENSION')
587
+ assert.equal(scriptingProvider.convos[0].conversation[1].not, true)
588
+
589
+ scriptingProvider.ExpandConvos()
590
+ assert.equal(scriptingProvider.convos.length, 2)
591
+ assert.equal(scriptingProvider.convos[0].conversation.length, 2)
592
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
593
+ assert.equal(scriptingProvider.convos[0].conversation[1].messageText, 'INCOMPREHENSION')
594
+ assert.equal(scriptingProvider.convos[0].conversation[1].not, true)
595
+ assert.equal(scriptingProvider.convos[1].conversation.length, 2)
596
+ assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
597
+ assert.equal(scriptingProvider.convos[1].conversation[1].messageText, 'INCOMPREHENSION')
598
+ assert.equal(scriptingProvider.convos[1].conversation[1].not, true)
599
+ })
600
+ it('should build intent check convos for utterance', async function () {
601
+ const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities, { SCRIPTING_UTTEXPANSION_USENAMEASINTENT: true }))
602
+ await scriptingProvider.Build()
603
+ scriptingProvider.AddUtterances({
604
+ name: 'utt1',
605
+ utterances: ['TEXT1', 'TEXT2']
606
+ })
607
+
608
+ scriptingProvider.ExpandUtterancesToConvos()
609
+ assert.equal(scriptingProvider.convos.length, 1)
610
+ assert.equal(scriptingProvider.convos[0].conversation.length, 2)
611
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'utt1')
612
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters.length, 1)
613
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].name, 'INTENT')
614
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].args[0], 'utt1')
615
+
616
+ scriptingProvider.ExpandConvos()
617
+ assert.equal(scriptingProvider.convos.length, 2)
618
+ assert.equal(scriptingProvider.convos[0].conversation.length, 2)
619
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
620
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters.length, 1)
621
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].name, 'INTENT')
622
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].args[0], 'utt1')
623
+ assert.equal(scriptingProvider.convos[1].conversation.length, 2)
624
+ assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
625
+ assert.equal(scriptingProvider.convos[1].conversation[1].asserters.length, 1)
626
+ assert.equal(scriptingProvider.convos[1].conversation[1].asserters[0].name, 'INTENT')
627
+ assert.equal(scriptingProvider.convos[1].conversation[1].asserters[0].args[0], 'utt1')
628
+ })
629
+ it('should build intent check convos for utterance (with arg)', async function () {
630
+ const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
631
+ await scriptingProvider.Build()
632
+ scriptingProvider.AddUtterances({
633
+ name: 'utt1',
634
+ utterances: ['TEXT1', 'TEXT2']
635
+ })
636
+
637
+ scriptingProvider.ExpandUtterancesToConvos({ useNameAsIntent: true })
638
+ assert.equal(scriptingProvider.convos.length, 1)
639
+ assert.equal(scriptingProvider.convos[0].conversation.length, 2)
640
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'utt1')
641
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters.length, 1)
642
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].name, 'INTENT')
643
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].args[0], 'utt1')
700
644
 
701
- describe('scriptingProvider.assertBotNotResponse', function () {
702
- it('should fail with correct error message on match', async function () {
703
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
704
- await scriptingProvider.Build()
705
- const scriptingContext = scriptingProvider._buildScriptContext()
706
- try {
707
- scriptingContext.scriptingEvents.assertBotNotResponse('Keine Antwort gefunden!', ['Keine Antwort gefunden'], 'test1')
708
- assert.fail('expected error')
709
- } catch (err) {
710
- assert.equal(err.message, 'test1: Bot response "Keine Antwort gefunden!" expected NOT to match "Keine Antwort gefunden"')
711
- }
645
+ scriptingProvider.ExpandConvos()
646
+ assert.equal(scriptingProvider.convos.length, 2)
647
+ assert.equal(scriptingProvider.convos[0].conversation.length, 2)
648
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
649
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters.length, 1)
650
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].name, 'INTENT')
651
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].args[0], 'utt1')
652
+ assert.equal(scriptingProvider.convos[1].conversation.length, 2)
653
+ assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
654
+ assert.equal(scriptingProvider.convos[1].conversation[1].asserters.length, 1)
655
+ assert.equal(scriptingProvider.convos[1].conversation[1].asserters[0].name, 'INTENT')
656
+ assert.equal(scriptingProvider.convos[1].conversation[1].asserters[0].args[0], 'utt1')
657
+ })
658
+ it('should build check-only convos for utterance', async function () {
659
+ const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
660
+ await scriptingProvider.Build()
661
+ scriptingProvider.AddUtterances({
662
+ name: 'utt1',
663
+ utterances: ['TEXT1', 'TEXT2']
664
+ })
665
+
666
+ scriptingProvider.ExpandUtterancesToConvos()
667
+ assert.lengthOf(scriptingProvider.convos, 1)
668
+ assert.lengthOf(scriptingProvider.convos[0].conversation, 2)
669
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'utt1')
670
+ assert.equal(scriptingProvider.convos[0].conversation[1].messageText, '')
671
+ assert.isFalse(scriptingProvider.convos[0].conversation[1].not)
672
+
673
+ scriptingProvider.ExpandConvos()
674
+ assert.lengthOf(scriptingProvider.convos, 2)
675
+ assert.lengthOf(scriptingProvider.convos[0].conversation, 2)
676
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'TEXT1')
677
+ assert.equal(scriptingProvider.convos[0].conversation[1].messageText, '')
678
+ assert.isFalse(scriptingProvider.convos[0].conversation[1].not)
679
+ assert.lengthOf(scriptingProvider.convos[1].conversation, 2)
680
+ assert.equal(scriptingProvider.convos[1].conversation[0].messageText, 'TEXT2')
681
+ assert.equal(scriptingProvider.convos[1].conversation[1].messageText, '')
682
+ assert.isFalse(scriptingProvider.convos[1].conversation[1].not)
683
+ })
684
+ it('should fail incomprehension convos for utterance without incomprehension utt', async function () {
685
+ const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities, { SCRIPTING_UTTEXPANSION_INCOMPREHENSION: 'INCOMPREHENSION' }))
686
+ await scriptingProvider.Build()
687
+
688
+ try {
689
+ scriptingProvider.ExpandUtterancesToConvos()
690
+ assert.fail('should have failed')
691
+ } catch (err) {
692
+ assert.isTrue(err.message.indexOf('incomprehension utterance \'INCOMPREHENSION\' undefined') > 0)
693
+ }
694
+ })
695
+ it('should add incomprehension utterances to new utterance list', async function () {
696
+ const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
697
+ await scriptingProvider.Build()
698
+ scriptingProvider.AddUtterances({
699
+ name: 'utt1',
700
+ utterances: ['TEXT1', 'TEXT2']
701
+ })
702
+
703
+ scriptingProvider.ExpandUtterancesToConvos({ incomprehensionUtt: 'INCOMPREHENSION', incomprehensionUtts: ['INCOMPREHENSION3', 'INCOMPREHENSION4'] })
704
+ assert.lengthOf(scriptingProvider.utterances.INCOMPREHENSION.utterances, 2)
705
+ })
706
+ it('should add incomprehension utterances to new default utterance list', async function () {
707
+ const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
708
+ await scriptingProvider.Build()
709
+ scriptingProvider.AddUtterances({
710
+ name: 'utt1',
711
+ utterances: ['TEXT1', 'TEXT2']
712
+ })
713
+
714
+ scriptingProvider.ExpandUtterancesToConvos({ incomprehensionUtts: ['INCOMPREHENSION3', 'INCOMPREHENSION4'] })
715
+ assert.lengthOf(scriptingProvider.utterances.UTT_INCOMPREHENSION.utterances, 2)
716
+ })
717
+ it('should add incomprehension utterances to existing utterance list', async function () {
718
+ const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
719
+ await scriptingProvider.Build()
720
+ scriptingProvider.AddUtterances({
721
+ name: 'utt1',
722
+ utterances: ['TEXT1', 'TEXT2']
723
+ })
724
+ scriptingProvider.AddUtterances({
725
+ name: 'INCOMPREHENSION',
726
+ utterances: ['INCOMPREHENSION1', 'INCOMPREHENSION2']
727
+ })
728
+
729
+ scriptingProvider.ExpandUtterancesToConvos({ incomprehensionUtt: 'INCOMPREHENSION', incomprehensionUtts: ['INCOMPREHENSION3', 'INCOMPREHENSION4'] })
730
+ assert.lengthOf(scriptingProvider.utterances.INCOMPREHENSION.utterances, 4)
731
+ })
732
+ it('should add incomprehension intent to asserter list', async function () {
733
+ const scriptingProvider = new ScriptingProvider(Object.assign({}, DefaultCapabilities))
734
+ await scriptingProvider.Build()
735
+ scriptingProvider.AddUtterances({
736
+ name: 'utt1',
737
+ utterances: ['TEXT1', 'TEXT2']
738
+ })
739
+
740
+ scriptingProvider.ExpandUtterancesToConvos({ incomprehensionIntents: ['FALLBACK1', 'FALLBACK2'] })
741
+ assert.equal(scriptingProvider.convos.length, 1)
742
+ assert.equal(scriptingProvider.convos[0].conversation.length, 2)
743
+ assert.equal(scriptingProvider.convos[0].conversation[0].messageText, 'utt1')
744
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters.length, 2)
745
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].name, 'INTENT')
746
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].args[0], 'FALLBACK1')
747
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[0].not, true)
748
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[1].name, 'INTENT')
749
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[1].args[0], 'FALLBACK2')
750
+ assert.equal(scriptingProvider.convos[0].conversation[1].asserters[1].not, true)
751
+ })
712
752
  })
713
- it('should fail with correct error message on by empty asserter', async function () {
714
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
715
- await scriptingProvider.Build()
716
- const scriptingContext = scriptingProvider._buildScriptContext()
717
- try {
718
- scriptingContext.scriptingEvents.assertBotNotResponse('Keine Antwort gefunden!', [''], 'test1')
719
- assert.fail('expected error')
720
- } catch (err) {
721
- assert.equal(err.message, 'test1: Bot response "Keine Antwort gefunden!" expected NOT to match <any response>')
722
- }
753
+
754
+ describe('assertBotResponse', function () {
755
+ it('should fail with correct error message on single tomatch', async function () {
756
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
757
+ await scriptingProvider.Build()
758
+ const scriptingContext = scriptingProvider._buildScriptContext()
759
+ try {
760
+ scriptingContext.scriptingEvents.assertBotResponse('actual', 'expected', 'test1')
761
+ assert.fail('expected error')
762
+ } catch (err) {
763
+ assert.equal(err.message, 'test1: Bot response "actual" expected to match "expected"')
764
+ }
765
+ })
766
+ it('should fail with correct error message on empty bot message', async function () {
767
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
768
+ await scriptingProvider.Build()
769
+ const scriptingContext = scriptingProvider._buildScriptContext()
770
+ try {
771
+ scriptingContext.scriptingEvents.assertBotResponse(null, 'expected', 'test1')
772
+ assert.fail('expected error')
773
+ } catch (err) {
774
+ assert.equal(err.message, 'test1: Bot response <no response> expected to match "expected"')
775
+ }
776
+ })
777
+ it('should fail with correct error message on multiple tomatch', async function () {
778
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
779
+ await scriptingProvider.Build()
780
+ const scriptingContext = scriptingProvider._buildScriptContext()
781
+ try {
782
+ scriptingContext.scriptingEvents.assertBotResponse('actual', ['expected1', 'expected2'], 'test1')
783
+ assert.fail('expected error')
784
+ } catch (err) {
785
+ assert.equal(err.message, 'test1: Bot response "actual" expected to match one of "expected1", "expected2"')
786
+ }
787
+ })
723
788
  })
724
- it('should fail with correct error message on by empty asserter, and empty bot response', async function () {
725
- const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
726
- await scriptingProvider.Build()
727
- const scriptingContext = scriptingProvider._buildScriptContext()
728
- try {
729
- scriptingContext.scriptingEvents.assertBotNotResponse('', [''], 'test1')
730
- assert.fail('expected error')
731
- } catch (err) {
732
- assert.equal(err.message, 'test1: Bot response <no response> expected NOT to match <any response>')
733
- }
789
+
790
+ describe('assertBotNotResponse', function () {
791
+ it('should fail with correct error message on match', async function () {
792
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
793
+ await scriptingProvider.Build()
794
+ const scriptingContext = scriptingProvider._buildScriptContext()
795
+ try {
796
+ scriptingContext.scriptingEvents.assertBotNotResponse('Keine Antwort gefunden!', ['Keine Antwort gefunden'], 'test1')
797
+ assert.fail('expected error')
798
+ } catch (err) {
799
+ assert.equal(err.message, 'test1: Bot response "Keine Antwort gefunden!" expected NOT to match "Keine Antwort gefunden"')
800
+ }
801
+ })
802
+ it('should fail with correct error message on by empty asserter', async function () {
803
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
804
+ await scriptingProvider.Build()
805
+ const scriptingContext = scriptingProvider._buildScriptContext()
806
+ try {
807
+ scriptingContext.scriptingEvents.assertBotNotResponse('Keine Antwort gefunden!', [''], 'test1')
808
+ assert.fail('expected error')
809
+ } catch (err) {
810
+ assert.equal(err.message, 'test1: Bot response "Keine Antwort gefunden!" expected NOT to match <any response>')
811
+ }
812
+ })
813
+ it('should fail with correct error message on by empty asserter, and empty bot response', async function () {
814
+ const scriptingProvider = new ScriptingProvider(DefaultCapabilities)
815
+ await scriptingProvider.Build()
816
+ const scriptingContext = scriptingProvider._buildScriptContext()
817
+ try {
818
+ scriptingContext.scriptingEvents.assertBotNotResponse('', [''], 'test1')
819
+ assert.fail('expected error')
820
+ } catch (err) {
821
+ assert.equal(err.message, 'test1: Bot response <no response> expected NOT to match <any response>')
822
+ }
823
+ })
734
824
  })
735
825
  })