UNPKG

botium-core

Version:
110 lines (90 loc) 3.52 kB
const assert = require('chai').assert const path = require('path') const BotDriver = require('../../../').BotDriver const Capabilities = require('../../../').Capabilities const echoConnector = ({ queueBotSays }) => { return { UserSays (msg) { if (msg.messageText === 'button') { queueBotSays({ sender: 'bot', sourceData: msg.sourceData, messageText: '', buttons: [ { text: 'Push me!', payload: 'Push me!' } ] }) } queueBotSays({ sender: 'bot', sourceData: msg.sourceData, messageText: msg.messageText }) } } } describe('scripting.asserters.textAsserter', function () { beforeEach(async function () { const myCaps = { [Capabilities.PROJECTNAME]: 'scripting.asserters.textAsserter', [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', async function () { this.compiler.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos', 'text_ok.yml')) this.compiler.ExpandScriptingMemoryToConvos() assert.equal(this.compiler.convos.length, 1) await this.compiler.convos[0].Run(this.container) }) it('ok, no arg', async function () { this.compiler.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos', 'text_ok_no_arg.yml')) this.compiler.ExpandScriptingMemoryToConvos() assert.equal(this.compiler.convos.length, 1) await this.compiler.convos[0].Run(this.container) }) it('ok, no arg, negate', async function () { this.compiler.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos', 'text_ok_no_arg_negate.yml')) this.compiler.ExpandScriptingMemoryToConvos() assert.equal(this.compiler.convos.length, 1) await this.compiler.convos[0].Run(this.container) }) it('nok', async function () { this.compiler.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos', 'text_nok.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_nok/Line 2: assertion error - Line 2: Expected any text in response "Im Jane,Im George"') } }) it('nok no arg', async function () { this.compiler.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos', 'text_nok_no_arg.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_nok_no_arg/Line 2: assertion error - Line 2: Expected not empty response') } }) it('nok no arg, negate', async function () { this.compiler.ReadScriptsFromDirectory(path.resolve(__dirname, 'convos', 'text_nok_no_arg_negate.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_nok_no_arg_negate/Line 2: assertion error - Line 2: Expected empty response') } }) })