node-red-contrib-chatbot
Version:
REDBot a Chat bot for a full featured chat bot for Telegram, Facebook Messenger and Slack. Almost no coding skills required
41 lines (36 loc) • 1.4 kB
JavaScript
var _ = require('underscore');
var assert = require('chai').assert;
var RED = require('../lib/red-stub')();
var AuthorizedBlock = require('../nodes/chatbot-authorized');
describe('Chat authorized node', function() {
it('should pass to the second output for unauthorized nodes', function () {
var msg = RED.createMessage({content: 'I am the input message'});
RED.node.config({
command: 'start'
});
AuthorizedBlock(RED);
msg.chat().set({authorized: false});
RED.node.get().emit('input', msg);
return RED.node.get().await()
.then(function () {
assert.equal(RED.node.message(0), null);
assert.equal(RED.node.message(1).originalMessage.chat.id, 42);
assert.equal(RED.node.message(1).payload.content, 'I am the input message');
});
});
it('should pass to the first output for authorized nodes', function () {
var msg = RED.createMessage({content: 'I am the input message'});
RED.node.config({
command: 'start'
});
AuthorizedBlock(RED);
msg.chat().set({authorized: true});
RED.node.get().emit('input', msg);
return RED.node.get().await()
.then(function () {
assert.equal(RED.node.message(0).originalMessage.chat.id, 42);
assert.equal(RED.node.message(0).payload.content, 'I am the input message');
assert.equal(RED.node.message(1), null);
});
});
});