Skip to content

Commit

Permalink
Merge pull request #667 from codeforequity-at/develop
Browse files Browse the repository at this point in the history
Botium Core 1.12.1
  • Loading branch information
Botium authored Jan 24, 2022
2 parents 7643f98 + 4298c5c commit bf8be1b
Show file tree
Hide file tree
Showing 28 changed files with 1,201 additions and 889 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
ScriptingConstants: require('./src/scripting/Constants'),
Capabilities: require('./src/Capabilities'),
Defaults: require('./src/Defaults'),
Enums: require('./src/Enums'),
Source: require('./src/Source'),
Events: require('./src/Events'),
Plugins: require('./src/Plugins'),
Expand Down
1,586 changes: 786 additions & 800 deletions package-lock.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "botium-core",
"version": "1.12.0",
"version": "1.12.1",
"description": "The Selenium for Chatbots",
"main": "index.js",
"module": "dist/botium-es.js",
Expand Down Expand Up @@ -32,22 +32,22 @@
},
"homepage": "https://www.botium.ai",
"dependencies": {
"@babel/runtime": "^7.16.5",
"async": "^3.2.2",
"@babel/runtime": "^7.16.7",
"async": "^3.2.3",
"body-parser": "^1.19.1",
"boolean": "^3.1.4",
"bottleneck": "^2.19.5",
"csv-parse": "^5.0.3",
"csv-parse": "^5.0.4",
"debug": "^4.3.3",
"esprima": "^4.0.1",
"express": "^4.17.2",
"globby": "11.0.4",
"ioredis": "^4.28.2",
"ioredis": "^4.28.3",
"is-class": "^0.0.9",
"is-json": "^2.0.1",
"jsonpath": "^1.1.1",
"lodash": "^4.17.21",
"markdown-it": "^12.3.0",
"markdown-it": "^12.3.2",
"mime-types": "^2.1.34",
"mkdirp": "^1.0.4",
"moment": "^2.29.1",
Expand All @@ -58,40 +58,40 @@
"request": "^2.88.2",
"rimraf": "^3.0.2",
"sanitize-filename": "^1.6.3",
"slugify": "^1.6.4",
"socket.io": "^4.4.0",
"socket.io-client": "^4.4.0",
"slugify": "^1.6.5",
"socket.io": "^4.4.1",
"socket.io-client": "^4.4.1",
"socketio-auth": "^0.1.1",
"swagger-jsdoc": "^6.1.0",
"swagger-ui-express": "^4.3.0",
"uuid": "^8.3.2",
"vm2": "^3.9.5",
"write-yaml": "^1.0.0",
"xlsx": "^0.17.4",
"xlsx": "^0.17.5",
"xregexp": "^5.1.0",
"yaml": "^1.10.2"
},
"devDependencies": {
"@babel/core": "^7.16.5",
"@babel/node": "^7.16.5",
"@babel/plugin-transform-runtime": "^7.16.5",
"@babel/preset-env": "^7.16.5",
"@babel/core": "^7.16.12",
"@babel/node": "^7.16.8",
"@babel/plugin-transform-runtime": "^7.16.10",
"@babel/preset-env": "^7.16.11",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.3",
"eslint": "^8.4.1",
"eslint": "^8.7.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.2.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-standard": "^4.1.0",
"license-checker": "^25.0.1",
"license-compatibility-checker": "^0.3.5",
"mocha": "^9.1.3",
"nock": "^13.2.1",
"npm-check-updates": "^12.0.5",
"mocha": "^9.2.0",
"nock": "^13.2.2",
"npm-check-updates": "^12.2.1",
"nyc": "^15.1.0",
"rollup": "^2.61.1",
"rollup": "^2.66.0",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
Expand Down
3 changes: 3 additions & 0 deletions src/Capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ module.exports = {
SCRIPTING_NORMALIZE_TEXT: 'SCRIPTING_NORMALIZE_TEXT',
SCRIPTING_ENABLE_MEMORY: 'SCRIPTING_ENABLE_MEMORY',
SCRIPTING_ENABLE_MULTIPLE_ASSERT_ERRORS: 'SCRIPTING_ENABLE_MULTIPLE_ASSERT_ERRORS',
SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS: 'SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS',
SCRIPTING_FORCE_BOT_CONSUMED: 'SCRIPTING_FORCE_BOT_CONSUMED',
// regexp, regexpIgnoreCase, wildcard, wildcardIgnoreCase, wildcardExact, wildcardExactIgnoreCase, include, includeIgnoreCase, equals, equalsIgnoreCase
SCRIPTING_MATCHING_MODE: 'SCRIPTING_MATCHING_MODE',
Expand All @@ -126,6 +127,8 @@ module.exports = {
SCRIPTING_MEMORYEXPANSION_KEEP_ORIG: 'SCRIPTING_MEMORYEXPANSION_KEEP_ORIG',
// word, non_whitespace, joker
SCRIPTING_MEMORY_MATCHING_MODE: 'SCRIPTING_MEMORY_MATCHING_MODE',
// varnames, testcasenames
SCRIPTING_MEMORY_COLUMN_MODE: 'SCRIPTING_MEMORY_COLUMN_MODE',
// Botium Lifecycle Hooks
CUSTOMHOOK_ONBUILD: 'CUSTOMHOOK_ONBUILD',
CUSTOMHOOK_ONSTART: 'CUSTOMHOOK_ONSTART',
Expand Down
1 change: 1 addition & 0 deletions src/Defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module.exports = {
[Capabilities.SCRIPTING_UTTEXPANSION_NAMING_MODE]: 'justLineTag',
[Capabilities.SCRIPTING_UTTEXPANSION_NAMING_UTTERANCE_MAX]: '16',
[Capabilities.SCRIPTING_MEMORYEXPANSION_KEEP_ORIG]: false,
[Capabilities.SCRIPTING_ENABLE_SKIP_ASSERT_ERRORS]: false,
[Capabilities.SCRIPTING_FORCE_BOT_CONSUMED]: false,
[Capabilities.ASSERTERS]: [],
[Capabilities.LOGIC_HOOKS]: [],
Expand Down
6 changes: 6 additions & 0 deletions src/Enums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
E_SCRIPTING_MEMORY_COLUMN_MODE: {
VARNAMES: 'varnames',
TESTCASENAMES: 'testcasenames'
}
}
21 changes: 21 additions & 0 deletions src/scripting/BotiumError.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ const BotiumError = class BotiumError extends Error {
this.context.message = message.message || message
}

isAsserterError () {
if (this.context) {
const errArr = _.isArray(this.context) ? this.context : [this.context]
const hasNotAsserterError = errArr.findIndex(errDetail => {
if (errDetail.type === 'list') {
if (errDetail.errors) {
return errDetail.errors.findIndex(e => e.type !== 'asserter') >= 0
} else {
return true
}
} else {
return errDetail.type !== 'asserter'
}
}) >= 0
if (hasNotAsserterError) return false
return true
} else {
return false
}
}

prettify (includeJson) {
const lines = []
if (this.context) {
Expand Down
18 changes: 4 additions & 14 deletions src/scripting/CompilerObjectBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const CompilerBase = require('./CompilerBase')
const Constants = require('./Constants')
const Utterance = require('./Utterance')
const { Convo } = require('./Convo')
const { linesToConvoStep, validSenders } = require('./helper')
const { linesToConvoStep, validSenders, linesToScriptingMemories } = require('./helper')

module.exports = class CompilerObjectBase extends CompilerBase {
constructor (context, caps = {}) {
Expand Down Expand Up @@ -109,20 +109,10 @@ module.exports = class CompilerObjectBase extends CompilerBase {
if (lines && lines.length > 0) {
if (_.isString(lines[0])) {
if (lines.length > 1) {
const names = lines[0].split('|').map((name) => name.trim()).slice(1)
const scriptingMemories = []
for (let row = 1; row < lines.length; row++) {
const rawRow = lines[row].split('|').map((name) => name.trim())
const caseName = rawRow[0]
const values = rawRow.slice(1)
const json = {}
for (let col = 0; col < names.length; col++) {
json[names[col]] = values[col]
}
const scriptingMemory = { header: { name: caseName }, values: json }
scriptingMemories.push(scriptingMemory)
const scriptingMemories = linesToScriptingMemories(lines, this.caps[Capabilities.SCRIPTING_MEMORY_COLUMN_MODE])
if (scriptingMemories && scriptingMemories.length > 0) {
this.context.AddScriptingMemories(scriptingMemories)
}
this.context.AddScriptingMemories(scriptingMemories)
return scriptingMemories
}
} else {
Expand Down
19 changes: 4 additions & 15 deletions src/scripting/CompilerTxt.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Constants = require('./Constants')
const CompilerBase = require('./CompilerBase')
const Utterance = require('./Utterance')
const { ConvoHeader, Convo } = require('./Convo')
const { linesToConvoStep, convoStepToLines, validateConvo, validSenders } = require('./helper')
const { linesToConvoStep, convoStepToLines, validateConvo, validSenders, linesToScriptingMemories } = require('./helper')

module.exports = class CompilerTxt extends CompilerBase {
constructor (context, caps = {}) {
Expand Down Expand Up @@ -131,21 +131,10 @@ module.exports = class CompilerTxt extends CompilerBase {

_compileScriptingMemory (lines) {
if (lines && lines.length > 1) {
const names = lines[0].split('|').map((name) => name.trim()).slice(1)
const scriptingMemories = []
for (let row = 1; row < lines.length; row++) {
if (!lines[row] || lines[row].length === 0) continue
const rawRow = lines[row].split('|').map((name) => name.trim())
const caseName = rawRow[0]
const values = rawRow.slice(1)
const json = {}
for (let col = 0; col < names.length; col++) {
json[names[col]] = values[col]
}
const scriptingMemory = { header: { name: caseName }, values: json }
scriptingMemories.push(scriptingMemory)
const scriptingMemories = linesToScriptingMemories(lines, this.caps[Capabilities.SCRIPTING_MEMORY_COLUMN_MODE])
if (scriptingMemories && scriptingMemories.length > 0) {
this.context.AddScriptingMemories(scriptingMemories)
}
this.context.AddScriptingMemories(scriptingMemories)
return scriptingMemories
}
}
Expand Down
106 changes: 81 additions & 25 deletions src/scripting/CompilerXlsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const _ = require('lodash')
const debug = require('debug')('botium-core-CompilerXlsx')

const Capabilities = require('../Capabilities')
const { E_SCRIPTING_MEMORY_COLUMN_MODE } = require('../Enums')
const CompilerBase = require('./CompilerBase')
const Constants = require('./Constants')
const Utterance = require('./Utterance')
Expand Down Expand Up @@ -286,38 +287,93 @@ module.exports = class CompilerXlsx extends CompilerBase {
}

if (scriptType === Constants.SCRIPTING_TYPE_SCRIPTING_MEMORY) {
const variableNames = []
let colindexTemp = colindex + 1
while (true) {
const variableNameCell = this.colnames[colindexTemp] + rowindex
if (sheet[variableNameCell] && sheet[variableNameCell].v) {
variableNames.push(sheet[variableNameCell].v)
} else {
break
const guessScriptingMemoryColumnMode = () => {
const line1Cell = this.colnames[colindex] + (rowindex + 1)
if (sheet[line1Cell] && sheet[line1Cell].v) {
if (sheet[line1Cell].v.startsWith('$')) return E_SCRIPTING_MEMORY_COLUMN_MODE.TESTCASENAMES
}

colindexTemp++
return E_SCRIPTING_MEMORY_COLUMN_MODE.VARNAMES
}
const columnMode = this.caps[Capabilities.SCRIPTING_MEMORY_COLUMN_MODE] || guessScriptingMemoryColumnMode()

if (columnMode === E_SCRIPTING_MEMORY_COLUMN_MODE.TESTCASENAMES) {
const caseNames = []
let colindexTemp = colindex + 1
while (true) {
const caseNameCell = this.colnames[colindexTemp] + rowindex
if (sheet[caseNameCell] && sheet[caseNameCell].v) {
caseNames.push(sheet[caseNameCell].v)
} else {
break
}
colindexTemp++
}

rowindex += 1
while (true) {
const caseNameCell = this.colnames[colindex] + rowindex
if (sheet[caseNameCell] && sheet[caseNameCell].v) {
const caseName = sheet[caseNameCell].v
const values = {}
for (let i = 0; i < variableNames.length; i++) {
const variableValueCell = this.colnames[colindex + 1 + i] + rowindex
if (sheet[variableValueCell] && sheet[variableValueCell].v) {
values[variableNames[i]] = sheet[variableValueCell].v.toString()
} else {
values[variableNames[i]] = null
const varNames = []
const varValues = []

rowindex += 1
while (true) {
const varNameCell = this.colnames[colindex] + rowindex
if (sheet[varNameCell] && sheet[varNameCell].v) {
varNames.push(sheet[varNameCell].v)
const values = []
for (let i = 0; i < caseNames.length; i++) {
const variableValueCell = this.colnames[colindex + 1 + i] + rowindex
if (sheet[variableValueCell] && sheet[variableValueCell].v) {
values.push(sheet[variableValueCell].v.toString())
} else {
values.push(null)
}
}
varValues.push(values)
rowindex += 1
} else {
break
}
rowindex += 1
}
for (let caseIndex = 0; caseIndex < caseNames.length; caseIndex++) {
const caseName = caseNames[caseIndex]

const values = varNames.reduce((agg, varName, varIndex) => {
agg[varName] = varValues[varIndex][caseIndex] || null
return agg
}, {})
scriptResults.push({ header: { name: caseName }, values: values })
} else {
break
}
} else {
const variableNames = []
let colindexTemp = colindex + 1
while (true) {
const variableNameCell = this.colnames[colindexTemp] + rowindex
if (sheet[variableNameCell] && sheet[variableNameCell].v) {
variableNames.push(sheet[variableNameCell].v)
} else {
break
}
colindexTemp++
}

rowindex += 1
while (true) {
const caseNameCell = this.colnames[colindex] + rowindex
if (sheet[caseNameCell] && sheet[caseNameCell].v) {
const caseName = sheet[caseNameCell].v
const values = {}
for (let i = 0; i < variableNames.length; i++) {
const variableValueCell = this.colnames[colindex + 1 + i] + rowindex
if (sheet[variableValueCell] && sheet[variableValueCell].v) {
values[variableNames[i]] = sheet[variableValueCell].v.toString()
} else {
values[variableNames[i]] = null
}
}
rowindex += 1

scriptResults.push({ header: { name: caseName }, values: values })
} else {
break
}
}
}
}
Expand Down
Loading

0 comments on commit bf8be1b

Please sign in to comment.