botium-core 1.13.6 → 1.13.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "botium-core",
3
- "version": "1.13.6",
3
+ "version": "1.13.8",
4
4
  "description": "The Selenium for Chatbots",
5
5
  "main": "index.js",
6
6
  "module": "dist/botium-es.js",
@@ -885,12 +885,11 @@ module.exports = class ScriptingProvider {
885
885
  // drop unwanted convos
886
886
  convoFilter: null
887
887
  }, options)
888
- const context = { count: 0 }
889
888
  const expandedConvos = []
890
889
  debug(`ExpandConvos - Using utterances expansion mode: ${this.caps[Capabilities.SCRIPTING_UTTEXPANSION_MODE]}`)
891
890
  this.convos.forEach((convo) => {
892
891
  convo.expandPartialConvos()
893
- for (const expanded of this._expandConvo(convo, options, context)) {
892
+ for (const expanded of this._expandConvo(convo, options, {})) {
894
893
  expanded.header.assertionCount = this.GetAssertionCount(expanded)
895
894
  if (options.justHeader) {
896
895
  const ConvoWithOnlyHeader = {
@@ -922,10 +921,9 @@ module.exports = class ScriptingProvider {
922
921
  // creating a nested generator, calling the other.
923
922
  // We hope this.convos does not changes while this iterator is used
924
923
  const _convosIterable = function * (options) {
925
- const context = { count: 0 }
926
924
  for (const convo of this.convos) {
927
925
  convo.expandPartialConvos()
928
- yield * this._expandConvo(convo, options, context)
926
+ yield * this._expandConvo(convo, options, {})
929
927
  }
930
928
  }.bind(this)
931
929
 
@@ -1122,11 +1120,6 @@ module.exports = class ScriptingProvider {
1122
1120
  } else {
1123
1121
  const expanded = Object.assign(_.cloneDeep(currentConvo), { conversation: _.cloneDeep(convoStepsStack) })
1124
1122
  if (!options.convoFilter || options.convoFilter(expanded)) {
1125
- context.count++
1126
- const logPerEntry = context.count < 10 ? 1 : context.count < 100 ? 10 : context.count < 1000 ? 100 : context.count < 10000 ? 1000 : 10000
1127
- if (context.count % logPerEntry === 0) {
1128
- debug(`Convo #${context.count} expanded (${expanded.header.name})`)
1129
- }
1130
1123
  yield expanded
1131
1124
  }
1132
1125
  }
@@ -111,19 +111,19 @@ module.exports = class LogicHookUtils {
111
111
 
112
112
  // 1 gives possibility to use default asserter as global asserter
113
113
  if (hookType === 'asserter') {
114
- const asserter = DEFAULT_ASSERTERS.find(asserter => src === asserter.className)
114
+ const asserter = DEFAULT_ASSERTERS.find(asserter => src === asserter.className || src === asserter.name)
115
115
  if (asserter) {
116
116
  return new (asserter.Class)({ ref, ...this.buildScriptContext }, this.caps, args)
117
117
  }
118
118
  }
119
119
  if (hookType === 'logichook') {
120
- const lh = DEFAULT_LOGIC_HOOKS.find(lh => src === lh.className)
120
+ const lh = DEFAULT_LOGIC_HOOKS.find(lh => src === lh.className || src === lh.name)
121
121
  if (lh) {
122
122
  return new (lh.Class)({ ref, ...this.buildScriptContext }, this.caps, args)
123
123
  }
124
124
  }
125
125
  if (hookType === 'userinput') {
126
- const ui = DEFAULT_USER_INPUTS.find(ui => src === ui.className)
126
+ const ui = DEFAULT_USER_INPUTS.find(ui => src === ui.className || src === ui.name)
127
127
  if (ui) {
128
128
  return new (ui.Class)({ ref, ...this.buildScriptContext }, this.caps, args)
129
129
  }
@@ -126,7 +126,12 @@ module.exports = class JsonPathAsserter {
126
126
  ))
127
127
  }
128
128
  }
129
- if (assert) {
129
+
130
+ if (this.globalArgs && this.globalArgs.checkExistanceOnEmptyAssert) {
131
+ if (!assert) return Promise.resolve()
132
+ }
133
+
134
+ if (!_.isNil(assert)) {
130
135
  const actual = (_.isArray(jsonPathValues) && jsonPathValues.length === 1) ? jsonPathValues[0] : jsonPathValues
131
136
 
132
137
  let matchFn = this.context.Match
@@ -134,10 +139,10 @@ module.exports = class JsonPathAsserter {
134
139
  matchFn = getMatchFunction(this.globalArgs.matchingMode)
135
140
  }
136
141
 
137
- const match = jsonPathValues.find(a => matchFn(a, assert))
142
+ const match = !_.isNil(jsonPathValues.find(a => matchFn(a, assert)))
138
143
 
139
144
  if (not && match) {
140
- return Promise.reject(new BotiumError(`${convoStep.stepTag}: Not expected: ${toString(actual)} in jsonPath ${path}"`,
145
+ return Promise.reject(new BotiumError(`${convoStep.stepTag}: Not expected: "${actual === '' ? '<empty>' : toString(actual)}" in jsonPath ${path}"`,
141
146
  {
142
147
  type: 'asserter',
143
148
  source: this.name,
@@ -158,7 +163,7 @@ module.exports = class JsonPathAsserter {
158
163
  ))
159
164
  }
160
165
  if (!not && !match) {
161
- return Promise.reject(new BotiumError(`${convoStep.stepTag}: Expected: ${assert} in jsonPath ${path}: Actual: ${toString(actual)}`,
166
+ return Promise.reject(new BotiumError(`${convoStep.stepTag}: Expected: "${assert === '' ? '<empty>' : assert}" in jsonPath ${path}, actual: ${actual === '' ? '<empty>' : toString(actual)}`,
162
167
  {
163
168
  type: 'asserter',
164
169
  source: this.name,
@@ -7,16 +7,78 @@ describe('scripting.asserters.jsonPathAsserter', function () {
7
7
  describe('jsonPathAsserter', function () {
8
8
  beforeEach(async function () {
9
9
  this.jsonPathAsserter = new JsonPathAsserter({
10
- Match: (botresponse, utterance) => botresponse.toLowerCase().indexOf(utterance.toLowerCase()) >= 0
10
+ Match: (botresponse, utterance) => {
11
+ return botresponse.toLowerCase().indexOf(utterance.toLowerCase()) >= 0
12
+ }
11
13
  }, {})
12
14
  this.jsonPathAsserterWildcard = new JsonPathAsserter({
13
15
  Match: getMatchFunction('wildcardIgnoreCase')
14
16
  }, {})
17
+ this.jsonPathAsserterEquals = new JsonPathAsserter({
18
+ Match: getMatchFunction('equals')
19
+ }, {})
15
20
  this.jsonPathAsserterGlobalArgs = new JsonPathAsserter({
16
21
  Match: (botresponse, utterance) => botresponse.toLowerCase().indexOf(utterance.toLowerCase()) >= 0
17
22
  }, {}, { path: '$.test' })
18
23
  })
19
24
 
25
+ describe('empty string', function () {
26
+ it('should succeed if both is empty', async function () {
27
+ await this.jsonPathAsserterWildcard.assertConvoStep({
28
+ convoStep: { stepTag: 'test' },
29
+ args: ['$.test', ''],
30
+ botMsg: {
31
+ sourceData: {
32
+ test: ''
33
+ }
34
+ }
35
+ })
36
+ })
37
+ it('should succeed if expected is empty, and asserter is negated', async function () {
38
+ await this.jsonPathAsserterEquals.assertNotConvoStep({
39
+ convoStep: { stepTag: 'test' },
40
+ args: ['$.test', ''],
41
+ botMsg: {
42
+ sourceData: {
43
+ test: 'something but not empty string'
44
+ }
45
+ }
46
+ })
47
+ })
48
+ it('should fail if expected is not empty', async function () {
49
+ try {
50
+ await this.jsonPathAsserterWildcard.assertConvoStep({
51
+ convoStep: { stepTag: 'test' },
52
+ args: ['$.test', 'something but not empty string'],
53
+ botMsg: {
54
+ sourceData: {
55
+ test: ''
56
+ }
57
+ }
58
+ })
59
+ assert.fail('expected jsonPathAsserter to fail')
60
+ } catch (err) {
61
+ assert.isTrue(err.message.includes('Expected: "something but not empty string" in jsonPath $.test, actual: <empty>'))
62
+ }
63
+ })
64
+ it('should fail if real is not empty', async function () {
65
+ try {
66
+ await this.jsonPathAsserterEquals.assertConvoStep({
67
+ convoStep: { stepTag: 'test' },
68
+ args: ['$.test', ''],
69
+ botMsg: {
70
+ sourceData: {
71
+ test: 'something but not empty string'
72
+ }
73
+ }
74
+ })
75
+ assert.fail('expected jsonPathAsserter to fail')
76
+ } catch (err) {
77
+ assert.isTrue(err.message.includes('Expected: "<empty>" in jsonPath $.test, actual: something but not empty string'))
78
+ }
79
+ })
80
+ })
81
+
20
82
  it('should do nothing on no arg', async function () {
21
83
  await this.jsonPathAsserter.assertConvoStep({})
22
84
  })
@@ -62,8 +124,7 @@ describe('scripting.asserters.jsonPathAsserter', function () {
62
124
  }
63
125
  })
64
126
  } catch (err) {
65
- console.log(err.message)
66
- assert.isTrue(err.message.includes('Expected: message4 in jsonPath $.messages[*].label: Actual: message1,message2,message3'))
127
+ assert.isTrue(err.message.includes('Expected: "message4" in jsonPath $.messages[*].label, actual: message1,message2,message3'))
67
128
  }
68
129
  })
69
130
  it('should fail on not existing jsonpath', async function () {
@@ -133,7 +194,7 @@ describe('scripting.asserters.jsonPathAsserter', function () {
133
194
  }
134
195
  })
135
196
  } catch (err) {
136
- assert.isTrue(err.message.indexOf('Expected: {"label":"message2"} in jsonPath $.messages[0]: Actual: {"label":"message1"}') > 0)
197
+ assert.isTrue(err.message.indexOf('Expected: "{"label":"message2"}" in jsonPath $.messages[0], actual: {"label":"message1"}') > 0)
137
198
  assert.isNotNull(err.context)
138
199
  assert.isNotNull(err.context.cause)
139
200
  assert.isNotTrue(err.context.cause.not)
@@ -155,7 +216,7 @@ describe('scripting.asserters.jsonPathAsserter', function () {
155
216
  })
156
217
  assert.fail('should have failed')
157
218
  } catch (err) {
158
- assert.isTrue(err.message.indexOf('Expected: test2 in jsonPath $.test') > 0)
219
+ assert.isTrue(err.message.indexOf('Expected: "test2" in jsonPath $.test') > 0)
159
220
  assert.isNotNull(err.context)
160
221
  assert.isNotNull(err.context.cause)
161
222
  assert.isNotTrue(err.context.cause.not)
@@ -196,7 +257,7 @@ describe('scripting.asserters.jsonPathAsserter', function () {
196
257
  })
197
258
  assert.fail('should have failed')
198
259
  } catch (err) {
199
- assert.isTrue(err.message.indexOf('Not expected: test1 in jsonPath $.test') > 0)
260
+ assert.isTrue(err.message.indexOf('Not expected: "test1" in jsonPath $.test') > 0)
200
261
  assert.isNotNull(err.context)
201
262
  assert.isNotNull(err.context.cause)
202
263
  assert.isTrue(err.context.cause.not)
@@ -216,7 +277,7 @@ describe('scripting.asserters.jsonPathAsserter', function () {
216
277
  })
217
278
  })
218
279
  it('should succeed on matching jsonpath from globalArgs', async function () {
219
- await this.jsonPathAsserter.assertConvoStep({
280
+ await this.jsonPathAsserterGlobalArgs.assertConvoStep({
220
281
  convoStep: { stepTag: 'test' },
221
282
  args: ['test'],
222
283
  botMsg: {
@@ -252,7 +313,7 @@ describe('scripting.asserters.jsonPathAsserter', function () {
252
313
  })
253
314
  assert.fail('should have failed')
254
315
  } catch (err) {
255
- assert.isTrue(err.message.indexOf('Expected: test2 in jsonPath $.test') > 0)
316
+ assert.isTrue(err.message.indexOf('Expected: "test2" in jsonPath $.test') > 0)
256
317
  assert.isNotNull(err.context)
257
318
  assert.isNotNull(err.context.cause)
258
319
  assert.isNotTrue(err.context.cause.not)
@@ -332,7 +393,7 @@ describe('scripting.asserters.jsonPathAsserter', function () {
332
393
  })
333
394
  assert.fail('should have failed')
334
395
  } catch (err) {
335
- assert.isTrue(err.message.indexOf('Expected: value in jsonPath $.test') > 0)
396
+ assert.isTrue(err.message.indexOf('Expected: "value" in jsonPath $.test') > 0)
336
397
  }
337
398
  })
338
399
  it('should succeed on setting matching mode in global args', async function () {
@@ -373,9 +434,24 @@ describe('scripting.asserters.jsonPathAsserter', function () {
373
434
  })
374
435
  assert.fail('should have failed')
375
436
  } catch (err) {
376
- assert.isTrue(err.message.indexOf('Expected: value1 in jsonPath $.test') > 0)
437
+ assert.isTrue(err.message.indexOf('Expected: "value1" in jsonPath $.test') > 0)
377
438
  }
378
439
  })
440
+
441
+ it('should succeed on empty string if checkExistanceOnEmptyAssert is on in globalArgs', async function () {
442
+ this.jsonPathAsserterEquals.globalArgs = {
443
+ checkExistanceOnEmptyAssert: true
444
+ }
445
+ await this.jsonPathAsserterEquals.assertConvoStep({
446
+ convoStep: { stepTag: 'test' },
447
+ args: ['test', ''],
448
+ botMsg: {
449
+ sourceData: {
450
+ test: 'asdf'
451
+ }
452
+ }
453
+ })
454
+ })
379
455
  })
380
456
 
381
457
  describe('jsonPathCountAsserter', function () {