botium-core 1.13.7 → 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.7",
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
  }
@@ -127,6 +127,10 @@ module.exports = class JsonPathAsserter {
127
127
  }
128
128
  }
129
129
 
130
+ if (this.globalArgs && this.globalArgs.checkExistanceOnEmptyAssert) {
131
+ if (!assert) return Promise.resolve()
132
+ }
133
+
130
134
  if (!_.isNil(assert)) {
131
135
  const actual = (_.isArray(jsonPathValues) && jsonPathValues.length === 1) ? jsonPathValues[0] : jsonPathValues
132
136
 
@@ -135,10 +139,10 @@ module.exports = class JsonPathAsserter {
135
139
  matchFn = getMatchFunction(this.globalArgs.matchingMode)
136
140
  }
137
141
 
138
- const match = jsonPathValues.find(a => matchFn(a, assert))
142
+ const match = !_.isNil(jsonPathValues.find(a => matchFn(a, assert)))
139
143
 
140
144
  if (not && match) {
141
- 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}"`,
142
146
  {
143
147
  type: 'asserter',
144
148
  source: this.name,
@@ -159,7 +163,7 @@ module.exports = class JsonPathAsserter {
159
163
  ))
160
164
  }
161
165
  if (!not && !match) {
162
- 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)}`,
163
167
  {
164
168
  type: 'asserter',
165
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,7 +124,6 @@ describe('scripting.asserters.jsonPathAsserter', function () {
62
124
  }
63
125
  })
64
126
  } catch (err) {
65
- console.log(err.message)
66
127
  assert.isTrue(err.message.includes('Expected: "message4" in jsonPath $.messages[*].label, actual: message1,message2,message3'))
67
128
  }
68
129
  })
@@ -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: {
@@ -376,6 +437,21 @@ describe('scripting.asserters.jsonPathAsserter', function () {
376
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 () {