botium-core
Version:
The Selenium for Chatbots
53 lines (46 loc) • 1.89 kB
JavaScript
const path = require('path')
const assert = require('chai').assert
const BotDriver = require('../../../').BotDriver
const Capabilities = require('../../../').Capabilities
const echoConnector = ({ queueBotSays }) => {
return {
UserSays (msg) {
const botMsg = { sender: 'bot', sourceData: msg.sourceData, messageText: msg.messageText }
queueBotSays(botMsg)
}
}
}
describe('scripting.scriptingmemory.regexp', function () {
beforeEach(async function () {
const myCaps = {
[Capabilities.PROJECTNAME]: 'scripting.scriptingmemory',
[Capabilities.CONTAINERMODE]: echoConnector,
[Capabilities.SCRIPTING_ENABLE_MEMORY]: true,
[Capabilities.SCRIPTING_MATCHING_MODE]: 'regexp'
}
const driver = new BotDriver(myCaps)
this.compiler = driver.BuildCompiler()
this.container = await driver.Build()
})
afterEach(async function () {
this.container && await this.container.Clean()
})
it('should quote regexp', async function () {
// scripting memory file wins, log on console
this.compiler.ReadScriptsFromDirectory(path.resolve(__dirname, 'quoteregexp'))
this.compiler.ExpandScriptingMemoryToConvos()
assert.equal(this.compiler.convos.length, 1)
const transcript = await this.compiler.convos[0].Run(this.container)
assert.isObject(transcript.scriptingMemory)
assert.isEmpty(transcript.scriptingMemory)
})
it('should extract memory from regexp', async function () {
// scripting memory file wins, log on console
this.compiler.ReadScriptsFromDirectory(path.resolve(__dirname, 'extractregexp'))
this.compiler.ExpandScriptingMemoryToConvos()
assert.equal(this.compiler.convos.length, 1)
const transcript = await this.compiler.convos[0].Run(this.container)
assert.isObject(transcript.scriptingMemory)
assert.equal(transcript.scriptingMemory.$count, '7')
})
})