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.
Files changed (57) hide show
  1. package/.eslintrc.js +6 -3
  2. package/dist/botium-cjs.js +305 -123
  3. package/dist/botium-cjs.js.map +1 -1
  4. package/dist/botium-es.js +323 -142
  5. package/dist/botium-es.js.map +1 -1
  6. package/package.json +17 -15
  7. package/src/Capabilities.js +2 -1
  8. package/src/containers/plugins/SimpleRestContainer.js +23 -16
  9. package/src/grid/inbound/proxy.js +2 -1
  10. package/src/helpers/RetryHelper.js +13 -7
  11. package/src/scripting/Convo.js +36 -10
  12. package/src/scripting/MatchFunctions.js +10 -0
  13. package/src/scripting/ScriptingProvider.js +106 -37
  14. package/src/scripting/logichook/LogicHookConsts.js +1 -1
  15. package/src/scripting/logichook/LogicHookUtils.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/convo/retryconvo.spec.js +134 -0
  26. package/test/driver/capabilities.spec.js +156 -151
  27. package/test/logichooks/hookfromsrc.spec.js +79 -73
  28. package/test/plugins/plugins.spec.js +44 -42
  29. package/test/scripting/asserters/buttonsAsserter.spec.js +257 -240
  30. package/test/scripting/asserters/cardsAsserter.spec.js +214 -212
  31. package/test/scripting/asserters/convos/wer_threshold_nok.yml +7 -0
  32. package/test/scripting/asserters/convos/wer_threshold_ok.yml +7 -0
  33. package/test/scripting/asserters/intentConfidenceAsserter.spec.js +34 -35
  34. package/test/scripting/asserters/jsonpathAsserter.spec.js +307 -308
  35. package/test/scripting/asserters/mediaAsserter.spec.js +236 -234
  36. package/test/scripting/asserters/werAsserter.spec.js +51 -0
  37. package/test/scripting/logichooks/setClearScriptingMemory.spec.js +202 -192
  38. package/test/scripting/matching/matchingmode.spec.js +306 -258
  39. package/test/scripting/scriptingProvider.spec.js +666 -633
  40. package/test/scripting/scriptingmemory/fillScriptingMemoryFromFile.spec.js +299 -281
  41. package/test/scripting/scriptingmemory/useScriptingMemoryForAssertion.spec.js +94 -80
  42. package/test/scripting/userinputs/defaultUserInputs.spec.js +233 -127
  43. package/test/scripting/userinputs/mediaInputConvos.spec.js +409 -403
  44. package/test/scripting/utteranceexpansion/associateByIndex.spec.js +259 -0
  45. package/test/scripting/utteranceexpansion/convos/associate_utterances_by_index.json +33 -0
  46. package/test/scripting/utteranceexpansion/convos/media.convo.txt +19 -0
  47. package/test/scripting/utteranceexpansion/files/step0voice0.wav +0 -0
  48. package/test/scripting/utteranceexpansion/files/step0voice1.wav +0 -0
  49. package/test/scripting/utteranceexpansion/files/step0voice2.wav +0 -0
  50. package/test/scripting/utteranceexpansion/files/step1voice0.wav +0 -0
  51. package/test/scripting/utteranceexpansion/files/step2voice0.wav +0 -0
  52. package/test/scripting/utteranceexpansion/files/step2voice1.wav +0 -0
  53. package/test/scripting/utteranceexpansion/files/step2voice2.wav +0 -0
  54. package/test/scripting/utteranceexpansion/files/step2voice4.wav +0 -0
  55. package/test/scripting/utteranceexpansion/files/step2voice5.wav +0 -0
  56. package/test/security/allowUnsafe.spec.js +274 -268
  57. package/test/utils.spec.js +40 -38
@@ -4,52 +4,37 @@ const JsonPathCountAsserter = require('../../../src/scripting/logichook/asserter
4
4
  const { getMatchFunction } = require('../../../src/scripting/MatchFunctions')
5
5
 
6
6
  describe('scripting.asserters.jsonPathAsserter', function () {
7
- beforeEach(async function () {
8
- this.jsonPathAsserter = new JsonPathAsserter({
9
- Match: (botresponse, utterance) => botresponse.toLowerCase().indexOf(utterance.toLowerCase()) >= 0
10
- }, {})
11
- this.jsonPathAsserterWildcard = new JsonPathAsserter({
12
- Match: getMatchFunction('wildcardIgnoreCase')
13
- }, {})
14
- this.jsonPathAsserterGlobalArgs = new JsonPathAsserter({
15
- Match: (botresponse, utterance) => botresponse.toLowerCase().indexOf(utterance.toLowerCase()) >= 0
16
- }, {}, { path: '$.test' })
17
- })
7
+ describe('jsonPathAsserter', function () {
8
+ beforeEach(async function () {
9
+ this.jsonPathAsserter = new JsonPathAsserter({
10
+ Match: (botresponse, utterance) => botresponse.toLowerCase().indexOf(utterance.toLowerCase()) >= 0
11
+ }, {})
12
+ this.jsonPathAsserterWildcard = new JsonPathAsserter({
13
+ Match: getMatchFunction('wildcardIgnoreCase')
14
+ }, {})
15
+ this.jsonPathAsserterGlobalArgs = new JsonPathAsserter({
16
+ Match: (botresponse, utterance) => botresponse.toLowerCase().indexOf(utterance.toLowerCase()) >= 0
17
+ }, {}, { path: '$.test' })
18
+ })
18
19
 
19
- it('should do nothing on no arg', async function () {
20
- await this.jsonPathAsserter.assertConvoStep({ })
21
- })
22
- it('should succeed on existing jsonpath', async function () {
23
- await this.jsonPathAsserter.assertConvoStep({
24
- convoStep: { stepTag: 'test' },
25
- args: ['$.test'],
26
- botMsg: {
27
- sourceData: {
28
- test: true
29
- }
30
- }
20
+ it('should do nothing on no arg', async function () {
21
+ await this.jsonPathAsserter.assertConvoStep({})
31
22
  })
32
- })
33
- it('should succeed on any existing jsonpath', async function () {
34
- await this.jsonPathAsserter.assertConvoStep({
35
- convoStep: { stepTag: 'test' },
36
- args: ['$.messages[*].label', 'message3'],
37
- botMsg: {
38
- sourceData: {
39
- messages: [
40
- { label: 'message1' },
41
- { label: 'message2' },
42
- { label: 'message3' }
43
- ]
23
+ it('should succeed on existing jsonpath', async function () {
24
+ await this.jsonPathAsserter.assertConvoStep({
25
+ convoStep: { stepTag: 'test' },
26
+ args: ['$.test'],
27
+ botMsg: {
28
+ sourceData: {
29
+ test: true
30
+ }
44
31
  }
45
- }
32
+ })
46
33
  })
47
- })
48
- it('should fail on not any existing jsonpath', async function () {
49
- try {
34
+ it('should succeed on any existing jsonpath', async function () {
50
35
  await this.jsonPathAsserter.assertConvoStep({
51
36
  convoStep: { stepTag: 'test' },
52
- args: ['$.messages[*].label', 'message4'],
37
+ args: ['$.messages[*].label', 'message3'],
53
38
  botMsg: {
54
39
  sourceData: {
55
40
  messages: [
@@ -60,68 +45,67 @@ describe('scripting.asserters.jsonPathAsserter', function () {
60
45
  }
61
46
  }
62
47
  })
63
- } catch (err) {
64
- console.log(err.message)
65
- assert.isTrue(err.message.includes('Expected: message4 in jsonPath $.messages[*].label: Actual: message1,message2,message3'))
66
- }
67
- })
68
- it('should fail on not existing jsonpath', async function () {
69
- try {
48
+ })
49
+ it('should fail on not any existing jsonpath', async function () {
50
+ try {
51
+ await this.jsonPathAsserter.assertConvoStep({
52
+ convoStep: { stepTag: 'test' },
53
+ args: ['$.messages[*].label', 'message4'],
54
+ botMsg: {
55
+ sourceData: {
56
+ messages: [
57
+ { label: 'message1' },
58
+ { label: 'message2' },
59
+ { label: 'message3' }
60
+ ]
61
+ }
62
+ }
63
+ })
64
+ } catch (err) {
65
+ console.log(err.message)
66
+ assert.isTrue(err.message.includes('Expected: message4 in jsonPath $.messages[*].label: Actual: message1,message2,message3'))
67
+ }
68
+ })
69
+ it('should fail on not existing jsonpath', async function () {
70
+ try {
71
+ await this.jsonPathAsserter.assertConvoStep({
72
+ convoStep: { stepTag: 'test' },
73
+ args: ['$.test'],
74
+ botMsg: {
75
+ sourceData: {}
76
+ }
77
+ })
78
+ assert.fail('expected jsonPathAsserter to fail')
79
+ } catch (err) {
80
+ assert.isTrue(err.message.includes('Could not find any element in jsonPath $.test'))
81
+ }
82
+ })
83
+ it('should succeed on matching jsonpath', async function () {
70
84
  await this.jsonPathAsserter.assertConvoStep({
71
85
  convoStep: { stepTag: 'test' },
72
- args: ['$.test'],
86
+ args: ['$.test', 'test'],
73
87
  botMsg: {
74
88
  sourceData: {
89
+ test: 'test'
75
90
  }
76
91
  }
77
92
  })
78
- assert.fail('expected jsonPathAsserter to fail')
79
- } catch (err) {
80
- assert.isTrue(err.message.includes('Could not find any element in jsonPath $.test'))
81
- }
82
- })
83
- it('should succeed on matching jsonpath', async function () {
84
- await this.jsonPathAsserter.assertConvoStep({
85
- convoStep: { stepTag: 'test' },
86
- args: ['$.test', 'test'],
87
- botMsg: {
88
- sourceData: {
89
- test: 'test'
90
- }
91
- }
92
93
  })
93
- })
94
- it('should succeed on matching jsonpath array', async function () {
95
- await this.jsonPathAsserter.assertConvoStep({
96
- convoStep: { stepTag: 'test' },
97
- args: ['$.test[0]', 'test'],
98
- botMsg: {
99
- sourceData: {
100
- test: ['test']
101
- }
102
- }
103
- })
104
- })
105
- it('should succeed on jsonpath object', async function () {
106
- await this.jsonPathAsserterWildcard.assertConvoStep({
107
- convoStep: { stepTag: 'test' },
108
- args: ['$.messages[0]', '{"label":"message1"}'],
109
- botMsg: {
110
- sourceData: {
111
- messages: [
112
- { label: 'message1' },
113
- { label: 'message2' },
114
- { label: 'message3' }
115
- ]
94
+ it('should succeed on matching jsonpath array', async function () {
95
+ await this.jsonPathAsserter.assertConvoStep({
96
+ convoStep: { stepTag: 'test' },
97
+ args: ['$.test[0]', 'test'],
98
+ botMsg: {
99
+ sourceData: {
100
+ test: ['test']
101
+ }
116
102
  }
117
- }
103
+ })
118
104
  })
119
- })
120
- it('should fail on invalid jsonpath object', async function () {
121
- try {
105
+ it('should succeed on jsonpath object', async function () {
122
106
  await this.jsonPathAsserterWildcard.assertConvoStep({
123
107
  convoStep: { stepTag: 'test' },
124
- args: ['$.messages[0]', '{"label":"message2"}'],
108
+ args: ['$.messages[0]', '{"label":"message1"}'],
125
109
  botMsg: {
126
110
  sourceData: {
127
111
  messages: [
@@ -132,295 +116,310 @@ describe('scripting.asserters.jsonPathAsserter', function () {
132
116
  }
133
117
  }
134
118
  })
135
- } catch (err) {
136
- assert.isTrue(err.message.indexOf('Expected: {"label":"message2"} in jsonPath $.messages[0]: Actual: {"label":"message1"}') > 0)
137
- assert.isNotNull(err.context)
138
- assert.isNotNull(err.context.cause)
139
- assert.isNotTrue(err.context.cause.not)
140
- assert.equal(err.context.cause.expected, '{"label":"message2"}')
141
- assert.deepEqual(err.context.cause.actual, { label: 'message1' })
142
- }
143
- })
119
+ })
120
+ it('should fail on invalid jsonpath object', async function () {
121
+ try {
122
+ await this.jsonPathAsserterWildcard.assertConvoStep({
123
+ convoStep: { stepTag: 'test' },
124
+ args: ['$.messages[0]', '{"label":"message2"}'],
125
+ botMsg: {
126
+ sourceData: {
127
+ messages: [
128
+ { label: 'message1' },
129
+ { label: 'message2' },
130
+ { label: 'message3' }
131
+ ]
132
+ }
133
+ }
134
+ })
135
+ } catch (err) {
136
+ assert.isTrue(err.message.indexOf('Expected: {"label":"message2"} in jsonPath $.messages[0]: Actual: {"label":"message1"}') > 0)
137
+ assert.isNotNull(err.context)
138
+ assert.isNotNull(err.context.cause)
139
+ assert.isNotTrue(err.context.cause.not)
140
+ assert.equal(err.context.cause.expected, '{"label":"message2"}')
141
+ assert.deepEqual(err.context.cause.actual, { label: 'message1' })
142
+ }
143
+ })
144
144
 
145
- it('should fail on not matching jsonpath', async function () {
146
- try {
147
- await this.jsonPathAsserter.assertConvoStep({
148
- convoStep: { stepTag: 'test' },
149
- args: ['$.test', 'test2'],
150
- botMsg: {
151
- sourceData: {
152
- test: 'test1'
145
+ it('should fail on not matching jsonpath', async function () {
146
+ try {
147
+ await this.jsonPathAsserter.assertConvoStep({
148
+ convoStep: { stepTag: 'test' },
149
+ args: ['$.test', 'test2'],
150
+ botMsg: {
151
+ sourceData: {
152
+ test: 'test1'
153
+ }
153
154
  }
154
- }
155
- })
156
- assert.fail('should have failed')
157
- } catch (err) {
158
- assert.isTrue(err.message.indexOf('Expected: test2 in jsonPath $.test') > 0)
159
- assert.isNotNull(err.context)
160
- assert.isNotNull(err.context.cause)
161
- assert.isNotTrue(err.context.cause.not)
162
- assert.equal(err.context.cause.expected, 'test2')
163
- assert.equal(err.context.cause.actual, 'test1')
164
- }
165
- })
166
- it('should succeed on non existing jsonpath', async function () {
167
- await this.jsonPathAsserter.assertNotConvoStep({
168
- convoStep: { stepTag: 'test' },
169
- args: ['$.test'],
170
- botMsg: {
171
- sourceData: {
172
- }
155
+ })
156
+ assert.fail('should have failed')
157
+ } catch (err) {
158
+ assert.isTrue(err.message.indexOf('Expected: test2 in jsonPath $.test') > 0)
159
+ assert.isNotNull(err.context)
160
+ assert.isNotNull(err.context.cause)
161
+ assert.isNotTrue(err.context.cause.not)
162
+ assert.equal(err.context.cause.expected, 'test2')
163
+ assert.equal(err.context.cause.actual, 'test1')
173
164
  }
174
165
  })
175
- })
176
- it('should succeed on non matching jsonpath', async function () {
177
- await this.jsonPathAsserter.assertNotConvoStep({
178
- convoStep: { stepTag: 'test' },
179
- args: ['$.test', 'test2'],
180
- botMsg: {
181
- sourceData: {
182
- test: 'test1'
166
+ it('should succeed on non existing jsonpath', async function () {
167
+ await this.jsonPathAsserter.assertNotConvoStep({
168
+ convoStep: { stepTag: 'test' },
169
+ args: ['$.test'],
170
+ botMsg: {
171
+ sourceData: {}
183
172
  }
184
- }
173
+ })
185
174
  })
186
- })
187
- it('should fail on matching jsonpath', async function () {
188
- try {
175
+ it('should succeed on non matching jsonpath', async function () {
189
176
  await this.jsonPathAsserter.assertNotConvoStep({
190
177
  convoStep: { stepTag: 'test' },
191
- args: ['$.test', 'test1'],
178
+ args: ['$.test', 'test2'],
192
179
  botMsg: {
193
180
  sourceData: {
194
181
  test: 'test1'
195
182
  }
196
183
  }
197
184
  })
198
- assert.fail('should have failed')
199
- } catch (err) {
200
- assert.isTrue(err.message.indexOf('Not expected: test1 in jsonPath $.test') > 0)
201
- assert.isNotNull(err.context)
202
- assert.isNotNull(err.context.cause)
203
- assert.isTrue(err.context.cause.not)
204
- assert.equal(err.context.cause.expected, 'test1')
205
- assert.equal(err.context.cause.actual, 'test1')
206
- }
207
- })
208
-
209
- it('should succeed on existing jsonpath from globalArgs', async function () {
210
- await this.jsonPathAsserterGlobalArgs.assertConvoStep({
211
- convoStep: { stepTag: 'test' },
212
- botMsg: {
213
- sourceData: {
214
- test: true
215
- }
216
- }
217
185
  })
218
- })
219
- it('should succeed on matching jsonpath from globalArgs', async function () {
220
- await this.jsonPathAsserter.assertConvoStep({
221
- convoStep: { stepTag: 'test' },
222
- args: ['test'],
223
- botMsg: {
224
- sourceData: {
225
- test: 'test'
226
- }
186
+ it('should fail on matching jsonpath', async function () {
187
+ try {
188
+ await this.jsonPathAsserter.assertNotConvoStep({
189
+ convoStep: { stepTag: 'test' },
190
+ args: ['$.test', 'test1'],
191
+ botMsg: {
192
+ sourceData: {
193
+ test: 'test1'
194
+ }
195
+ }
196
+ })
197
+ assert.fail('should have failed')
198
+ } catch (err) {
199
+ assert.isTrue(err.message.indexOf('Not expected: test1 in jsonPath $.test') > 0)
200
+ assert.isNotNull(err.context)
201
+ assert.isNotNull(err.context.cause)
202
+ assert.isTrue(err.context.cause.not)
203
+ assert.equal(err.context.cause.expected, 'test1')
204
+ assert.equal(err.context.cause.actual, 'test1')
227
205
  }
228
206
  })
229
- })
230
- it('should fail on not existing jsonpath from globalArgs', async function () {
231
- try {
207
+
208
+ it('should succeed on existing jsonpath from globalArgs', async function () {
232
209
  await this.jsonPathAsserterGlobalArgs.assertConvoStep({
233
210
  convoStep: { stepTag: 'test' },
234
211
  botMsg: {
235
212
  sourceData: {
213
+ test: true
236
214
  }
237
215
  }
238
216
  })
239
- assert.fail('expected jsonPathAsserter to fail')
240
- } catch (err) {
241
- assert.isTrue(err.message.includes('Could not find any element in jsonPath $.test'))
242
- }
243
- })
244
- it('should fail on not matching jsonpath from globalArgs', async function () {
245
- try {
246
- await this.jsonPathAsserterGlobalArgs.assertConvoStep({
217
+ })
218
+ it('should succeed on matching jsonpath from globalArgs', async function () {
219
+ await this.jsonPathAsserter.assertConvoStep({
247
220
  convoStep: { stepTag: 'test' },
248
- args: ['test2'],
221
+ args: ['test'],
249
222
  botMsg: {
250
223
  sourceData: {
251
- test: 'test1'
224
+ test: 'test'
252
225
  }
253
226
  }
254
227
  })
255
- assert.fail('should have failed')
256
- } catch (err) {
257
- assert.isTrue(err.message.indexOf('Expected: test2 in jsonPath $.test') > 0)
258
- assert.isNotNull(err.context)
259
- assert.isNotNull(err.context.cause)
260
- assert.isNotTrue(err.context.cause.not)
261
- assert.equal(err.context.cause.expected, 'test2')
262
- assert.equal(err.context.cause.actual, 'test1')
263
- }
264
- })
228
+ })
229
+ it('should fail on not existing jsonpath from globalArgs', async function () {
230
+ try {
231
+ await this.jsonPathAsserterGlobalArgs.assertConvoStep({
232
+ convoStep: { stepTag: 'test' },
233
+ botMsg: {
234
+ sourceData: {}
235
+ }
236
+ })
237
+ assert.fail('expected jsonPathAsserter to fail')
238
+ } catch (err) {
239
+ assert.isTrue(err.message.includes('Could not find any element in jsonPath $.test'))
240
+ }
241
+ })
242
+ it('should fail on not matching jsonpath from globalArgs', async function () {
243
+ try {
244
+ await this.jsonPathAsserterGlobalArgs.assertConvoStep({
245
+ convoStep: { stepTag: 'test' },
246
+ args: ['test2'],
247
+ botMsg: {
248
+ sourceData: {
249
+ test: 'test1'
250
+ }
251
+ }
252
+ })
253
+ assert.fail('should have failed')
254
+ } catch (err) {
255
+ assert.isTrue(err.message.indexOf('Expected: test2 in jsonPath $.test') > 0)
256
+ assert.isNotNull(err.context)
257
+ assert.isNotNull(err.context.cause)
258
+ assert.isNotTrue(err.context.cause.not)
259
+ assert.equal(err.context.cause.expected, 'test2')
260
+ assert.equal(err.context.cause.actual, 'test1')
261
+ }
262
+ })
263
+
264
+ it('should fail on invalid arg length from pathPattern', async function () {
265
+ this.jsonPathAsserter.globalArgs = {
266
+ argCount: 0,
267
+ pathTemplate: '$.test'
268
+ }
269
+ try {
270
+ await this.jsonPathAsserter.assertConvoStep({
271
+ convoStep: { stepTag: 'test' },
272
+ args: ['test2'],
273
+ botMsg: {
274
+ sourceData: {
275
+ test: 'test1'
276
+ }
277
+ }
278
+ })
279
+ assert.fail('should have failed')
280
+ } catch (err) {
281
+ assert.isTrue(err.message.indexOf('JsonPathAsserter 0 arguments expected') > 0)
282
+ }
283
+ })
284
+ it('should succeed on existing jsonpath from pathPattern', async function () {
285
+ this.jsonPathAsserter.globalArgs = {
286
+ argCount: 1,
287
+ pathTemplate: '$.{{args.0}}'
288
+ }
265
289
 
266
- it('should fail on invalid arg length from pathPattern', async function () {
267
- this.jsonPathAsserter.globalArgs = {
268
- argCount: 0,
269
- pathTemplate: '$.test'
270
- }
271
- try {
272
290
  await this.jsonPathAsserter.assertConvoStep({
273
291
  convoStep: { stepTag: 'test' },
274
- args: ['test2'],
292
+ args: ['test'],
275
293
  botMsg: {
276
294
  sourceData: {
277
- test: 'test1'
295
+ test: true
278
296
  }
279
297
  }
280
298
  })
281
- assert.fail('should have failed')
282
- } catch (err) {
283
- assert.isTrue(err.message.indexOf('JsonPathAsserter 0 arguments expected') > 0)
284
- }
285
- })
286
- it('should succeed on existing jsonpath from pathPattern', async function () {
287
- this.jsonPathAsserter.globalArgs = {
288
- argCount: 1,
289
- pathTemplate: '$.{{args.0}}'
290
- }
291
-
292
- await this.jsonPathAsserter.assertConvoStep({
293
- convoStep: { stepTag: 'test' },
294
- args: ['test'],
295
- botMsg: {
296
- sourceData: {
297
- test: true
298
- }
299
- }
300
299
  })
301
- })
302
- it('should succeed on existing jsonpath from pathPattern and assertPattern', async function () {
303
- this.jsonPathAsserter.globalArgs = {
304
- argCount: 2,
305
- pathTemplate: '$.{{args.0}}',
306
- assertTemplate: '{{args.1}}'
307
- }
308
-
309
- await this.jsonPathAsserter.assertConvoStep({
310
- convoStep: { stepTag: 'test' },
311
- args: ['test', 'value'],
312
- botMsg: {
313
- sourceData: {
314
- test: 'value'
315
- }
300
+ it('should succeed on existing jsonpath from pathPattern and assertPattern', async function () {
301
+ this.jsonPathAsserter.globalArgs = {
302
+ argCount: 2,
303
+ pathTemplate: '$.{{args.0}}',
304
+ assertTemplate: '{{args.1}}'
316
305
  }
317
- })
318
- })
319
- it('should fail on not matching jsonpath from pathPattern and assertPattern', async function () {
320
- this.jsonPathAsserter.globalArgs = {
321
- argCount: 2,
322
- pathTemplate: '$.{{args.0}}',
323
- assertTemplate: '{{args.1}}'
324
- }
325
- try {
306
+
326
307
  await this.jsonPathAsserter.assertConvoStep({
327
308
  convoStep: { stepTag: 'test' },
328
309
  args: ['test', 'value'],
329
310
  botMsg: {
330
311
  sourceData: {
331
- test: 'something else'
312
+ test: 'value'
332
313
  }
333
314
  }
334
315
  })
335
- assert.fail('should have failed')
336
- } catch (err) {
337
- assert.isTrue(err.message.indexOf('Expected: value in jsonPath $.test') > 0)
338
- }
339
- })
340
- it('should succeed on setting matching mode in global args', async function () {
341
- this.jsonPathAsserter.globalArgs = {
342
- argCount: 2,
343
- pathTemplate: '$.{{args.0}}',
344
- assertTemplate: '{{args.1}}',
345
- matchingMode: 'include'
346
- }
347
-
348
- await this.jsonPathAsserter.assertConvoStep({
349
- convoStep: { stepTag: 'test' },
350
- args: ['test', 'value'],
351
- botMsg: {
352
- sourceData: {
353
- test: 'value 123'
354
- }
316
+ })
317
+ it('should fail on not matching jsonpath from pathPattern and assertPattern', async function () {
318
+ this.jsonPathAsserter.globalArgs = {
319
+ argCount: 2,
320
+ pathTemplate: '$.{{args.0}}',
321
+ assertTemplate: '{{args.1}}'
322
+ }
323
+ try {
324
+ await this.jsonPathAsserter.assertConvoStep({
325
+ convoStep: { stepTag: 'test' },
326
+ args: ['test', 'value'],
327
+ botMsg: {
328
+ sourceData: {
329
+ test: 'something else'
330
+ }
331
+ }
332
+ })
333
+ assert.fail('should have failed')
334
+ } catch (err) {
335
+ assert.isTrue(err.message.indexOf('Expected: value in jsonPath $.test') > 0)
355
336
  }
356
337
  })
357
- })
358
- it('should fail on setting matching mode in global args', async function () {
359
- this.jsonPathAsserter.globalArgs = {
360
- argCount: 2,
361
- pathTemplate: '$.{{args.0}}',
362
- assertTemplate: '{{args.1}}',
363
- matchingMode: 'include'
364
- }
338
+ it('should succeed on setting matching mode in global args', async function () {
339
+ this.jsonPathAsserter.globalArgs = {
340
+ argCount: 2,
341
+ pathTemplate: '$.{{args.0}}',
342
+ assertTemplate: '{{args.1}}',
343
+ matchingMode: 'include'
344
+ }
365
345
 
366
- try {
367
346
  await this.jsonPathAsserter.assertConvoStep({
368
347
  convoStep: { stepTag: 'test' },
369
- args: ['test', 'value1'],
348
+ args: ['test', 'value'],
370
349
  botMsg: {
371
350
  sourceData: {
372
- test: 'value'
351
+ test: 'value 123'
373
352
  }
374
353
  }
375
354
  })
376
- assert.fail('should have failed')
377
- } catch (err) {
378
- assert.isTrue(err.message.indexOf('Expected: value1 in jsonPath $.test') > 0)
379
- }
380
- })
381
- })
382
-
383
- describe('scripting.asserters.jsonPathCountAsserter', function () {
384
- beforeEach(async function () {
385
- this.jsonPathCountAsserter = new JsonPathCountAsserter({}, {})
386
- })
355
+ })
356
+ it('should fail on setting matching mode in global args', async function () {
357
+ this.jsonPathAsserter.globalArgs = {
358
+ argCount: 2,
359
+ pathTemplate: '$.{{args.0}}',
360
+ assertTemplate: '{{args.1}}',
361
+ matchingMode: 'include'
362
+ }
387
363
 
388
- it('should succeed on no args with one jsonpath', async function () {
389
- await this.jsonPathCountAsserter.assertConvoStep({
390
- convoStep: { stepTag: 'test' },
391
- args: ['$.test'],
392
- botMsg: {
393
- sourceData: {
394
- test: [{ e1: 'e1' }, { e2: 'e2' }]
395
- }
364
+ try {
365
+ await this.jsonPathAsserter.assertConvoStep({
366
+ convoStep: { stepTag: 'test' },
367
+ args: ['test', 'value1'],
368
+ botMsg: {
369
+ sourceData: {
370
+ test: 'value'
371
+ }
372
+ }
373
+ })
374
+ assert.fail('should have failed')
375
+ } catch (err) {
376
+ assert.isTrue(err.message.indexOf('Expected: value1 in jsonPath $.test') > 0)
396
377
  }
397
378
  })
398
379
  })
399
- it('should succeed on <=2 with two jsonpath', async function () {
400
- await this.jsonPathCountAsserter.assertConvoStep({
401
- convoStep: { stepTag: 'test' },
402
- args: ['$.test', '<=2'],
403
- botMsg: {
404
- sourceData: {
405
- test: [{ e1: 'e1' }, { e2: 'e2' }]
380
+
381
+ describe('jsonPathCountAsserter', function () {
382
+ beforeEach(async function () {
383
+ this.jsonPathCountAsserter = new JsonPathCountAsserter({}, {})
384
+ })
385
+
386
+ it('should succeed on no args with one jsonpath', async function () {
387
+ await this.jsonPathCountAsserter.assertConvoStep({
388
+ convoStep: { stepTag: 'test' },
389
+ args: ['$.test'],
390
+ botMsg: {
391
+ sourceData: {
392
+ test: [{ e1: 'e1' }, { e2: 'e2' }]
393
+ }
406
394
  }
407
- }
395
+ })
408
396
  })
409
- })
410
- it('should fail on >2 with two jsonpath', async function () {
411
- try {
397
+ it('should succeed on <=2 with two jsonpath', async function () {
412
398
  await this.jsonPathCountAsserter.assertConvoStep({
413
399
  convoStep: { stepTag: 'test' },
414
- args: ['$.test', '>2'],
400
+ args: ['$.test', '<=2'],
415
401
  botMsg: {
416
402
  sourceData: {
417
403
  test: [{ e1: 'e1' }, { e2: 'e2' }]
418
404
  }
419
405
  }
420
406
  })
421
- assert.fail('should have failed')
422
- } catch (err) {
423
- assert.isTrue(err.message.indexOf('Expected JsonPath count 2 to be >2') >= 0)
424
- }
407
+ })
408
+ it('should fail on >2 with two jsonpath', async function () {
409
+ try {
410
+ await this.jsonPathCountAsserter.assertConvoStep({
411
+ convoStep: { stepTag: 'test' },
412
+ args: ['$.test', '>2'],
413
+ botMsg: {
414
+ sourceData: {
415
+ test: [{ e1: 'e1' }, { e2: 'e2' }]
416
+ }
417
+ }
418
+ })
419
+ assert.fail('should have failed')
420
+ } catch (err) {
421
+ assert.isTrue(err.message.indexOf('Expected JsonPath count 2 to be >2') >= 0)
422
+ }
423
+ })
425
424
  })
426
425
  })