Code Monkey home page Code Monkey logo

botmock's Introduction

README

BotMock - Write tests for Botkit.

Setup

  1. Clone repo
  2. Run npm install
  3. Run npm run test_mocha or npm run test_jasmine
  4. Copy mocks into your project root

Flags

first - indicates which user spoke first in multi-user testing.

deep - indicates the index of the conversation response to return in .then(). 0 is the last response, 1 is the second-to-last, etc..

isAssertion - indicates the conversation response array to return in .then() in multi-user testing.

How To Use

BotMock works by intercepting your normal Botkit instance.

var bot;
if(env !== 'test'){
    // your normal bot instance
    bot = require('app/bots/bot');
}

else{
    // your mock bot instance
    var botMock =  require('mocks/botMock');
    bot = new botMock.controller('userSlackId', 'userName').bot;
}

Normal botkit function

controller.hears(['help'], 'direct_message', function(bot, message){
    bot.reply(message, 'help message');
});

Normal botkit function test

const assert = require('assert');
const botMock = require('../mocks/botMock'); // require botmock
const testedFile = require("../bot/indexController"); // require file you are testing

describe("controller tests",()=>{
    beforeEach((done)=>{
        var self = this;
        self.slackId = 'test'
        self.userName = 'test'
        self.controller = new botMock.controller(self.slackId,self.userName) //instantiate botMock
        testedFile(self.controller.bot, self.controller) // inject botMock into the file being tested
        done();
    });
    it('should return `help message` if user types `help`', (done)=>{
    	var self = this;
    	return self.controller.usersInput([{
                first:true,
                user: self.slackId,
                messages:[{text: 'help', isAssertion:true}]
            }]).then((text)=>{
                assert.equal(text, 'help message')
                done()
            })
    });
});

Built by the team at https://www.gratify.chat.

botmock's People

Contributors

amplicity avatar arreche avatar ihorrusinko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.