UNPKG

botium-core

Version:
82 lines (66 loc) 2.85 kB
const assert = require('chai').assert const path = require('path') 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.asserters.textEqualsAsserter', function () { beforeEach(async function () { const myCaps = { [Capabilities.PROJECTNAME]: 'scripting.asserters.textEqualsAsserter', [Capabilities.CONTAINERMODE]: echoConnector } const driver = new BotDriver(myCaps) this.compiler = driver.BuildCompiler() this.container = await driver.Build() }) afterEach(async function () { this.container && await this.container.Clean() }) it('ok, base', async function () { this.compiler.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos', 'text_equals_ok_base.yml')) this.compiler.ExpandScriptingMemoryToConvos() assert.equal(this.compiler.convos.length, 1) await this.compiler.convos[0].Run(this.container) }) it('ok, ignore case', async function () { this.compiler.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos', 'text_equals_ok_ignore_case.yml')) this.compiler.ExpandScriptingMemoryToConvos() assert.equal(this.compiler.convos.length, 1) await this.compiler.convos[0].Run(this.container) }) it('ok, utterances', async function () { this.compiler.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos', 'text_equals_ok_utterances.yml')) this.compiler.ExpandScriptingMemoryToConvos() assert.equal(this.compiler.convos.length, 1) await this.compiler.convos[0].Run(this.container) }) it('nok, base', async function () { this.compiler.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos', 'text_equals_nok_base.yml')) this.compiler.ExpandScriptingMemoryToConvos() assert.equal(this.compiler.convos.length, 1) try { await this.compiler.convos[0].Run(this.container) assert.fail('expected error') } catch (err) { assert.equal(err.message, 'text_equals_nok_base/Line 2: assertion error - Line 2: Expected any text in response "Im Jane,Im George"') } }) it('nok, utterances', async function () { this.compiler.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos', 'text_equals_nok_utterances.yml')) this.compiler.ExpandScriptingMemoryToConvos() assert.equal(this.compiler.convos.length, 1) try { await this.compiler.convos[0].Run(this.container) assert.fail('expected error') } catch (err) { assert.equal(err.message, 'text_equals_nok_utterances/Line 2: assertion error - Line 2: Expected any text in response "Im Jane,Im George"') } }) })