gratifyguy / botkit-mock

Write tests for Botkit.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

botkit 4.x support?

alecl opened this issue · comments

I love the idea of this project. Is it going to be updated for bot.createConversation and other botkit 4.x changes?

Nice. In addition to being able to test conversation flows/state (setting variables, repeating until you give an accepted answer, etc would be good to have reactions and reminders API support - https://github.com/howdyai/botkit/blob/master/lib/Slack_web_api.js#L80

Thanks @alecl we'll leave this issue open until we push that functionality. Feel free to submit a PR if you happen to add this into your own fork first.

I think a great tracking goal would be to support test all the examples here: https://github.com/howdyai/botkit-starter-slack

I actually forked that to start my bot and when doing simple testing found I couldn't test a few more things there too.

The storage mock was created on the botkit class but not the controller so that is still needed.

  controller.hears(['hello', 'hi'], 'direct_message,direct_mention,mention', function (bot, message) {

    bot.api.reactions.add({
      timestamp: message.ts,
      channel: message.channel,
      name: 'robot_face',
    }, function (err, res) {
      if (err) {
        bot.botkit.log('Failed to add emoji reaction :(', err);
      }
    });

    controller.storage.users.get(message.user, function (err, user) {
      if (user && user.name) {
        bot.reply(message, 'Hello, ' + user.name + '!!');
      } else {
        bot.reply(message, 'Hello.');
      }
    });
  });

Also the message.match came up as undefined when stepping through the code with the mock

controller.hears(['^say (.*)','^say'], 'direct_message,direct_mention', function(bot, message) {
        if (message.match[1]) {

            if (!wordfilter.blacklisted(message.match[1])) {
                bot.reply(message, message.match[1]);
            } else {
                bot.reply(message, '_sigh_');
            }
        } else {
            bot.reply(message, 'I will repeat whatever you say.')
        }
    });

I'm debating with myself whether to continue down this route or record the Slack incoming/outgoing messages and use that to simulate things somehow.

We'll work to get these implemented. Thanks for the link.

I'm not sure what you mean by simulate, but If you're talking about hacking around something that can be covered in botkit-mock, then it's probably best to avoid and wait for a PR.

Solved in latest version of master. Grab the latest version from npm.