UNPKG

hubot-slack

Version:
240 lines (229 loc) 6.53 kB
// Generated by CoffeeScript 1.10.0 (function() { var Brain, EventEmitter, SlackBot, SlackClient, SlackFormatter, _; SlackBot = require('../src/bot'); SlackFormatter = require('../src/formatter'); SlackClient = require('../src/client'); EventEmitter = require('events').EventEmitter; Brain = require('hubot').Brain; _ = require('lodash'); beforeEach(function() { this.stubs = {}; this.stubs.channel = { name: 'general', id: 'C123', sendMessage: function(msg) { return msg; } }; this.stubs.DM = { name: 'User', id: 'D1232', sendMessage: function(msg) { return msg; } }; this.stubs.user = { name: 'name', id: 'U123', profile: { email: 'email@example.com' } }; this.stubs.bot = { name: 'testbot', id: 'B123' }; this.stubs.self = { name: 'self', id: 'U456', profile: { email: 'self@example.com' } }; this.stubs.team = { name: 'Example Team' }; this.stubs.client = { send: (function(_this) { return function(env, msg) { if (/user/.test(env.room)) { _this.stubs._dmmsg = msg; } else { } return _this.stubs._msg = msg; }; })(this), dataStore: { getUserById: (function(_this) { return function(id) { var i, len, ref, user; ref = _this.stubs.client.dataStore.users; for (i = 0, len = ref.length; i < len; i++) { user = ref[i]; if (user.id === id) { return user; } } }; })(this), getBotById: (function(_this) { return function(id) { var bot, i, len, ref; ref = _this.stubs.client.dataStore.bots; for (i = 0, len = ref.length; i < len; i++) { bot = ref[i]; if (bot.id === id) { return bot; } } }; })(this), getUserByName: (function(_this) { return function(name) { var i, len, ref, user; ref = _this.stubs.client.dataStore.users; for (i = 0, len = ref.length; i < len; i++) { user = ref[i]; if (user.name === name) { return user; } } }; })(this), getChannelById: (function(_this) { return function(id) { if (_this.stubs.channel.id === id) { return _this.stubs.channel; } }; })(this), getChannelGroupOrDMById: (function(_this) { return function(id) { if (_this.stubs.channel.id === id) { return _this.stubs.channel; } }; })(this), getChannelGroupOrDMByName: (function(_this) { return function(name) { var dm, i, len, ref; if (_this.stubs.channel.name === name) { return _this.stubs.channel; } ref = _this.stubs.client.dataStore.dms; for (i = 0, len = ref.length; i < len; i++) { dm = ref[i]; if (dm.name === name) { return dm; } } }; })(this), users: [this.stubs.user, this.stubs.self], bots: [this.stubs.bot], dms: [ { name: 'user2', id: 'D5432' } ] } }; this.stubs.rtm = { login: (function(_this) { return function() { return _this.stubs._connected = true; }; })(this), on: (function(_this) { return function(name, callback) { console.log("#####"); console.log(name); console.log(callback); return callback(name); }; })(this), removeListener: (function(_this) { return function(name) {}; })(this), sendMessage: (function(_this) { return function(message, room) { _this.stubs._msg = message; return _this.stubs._room = room; }; })(this) }; this.stubs.chatMock = { postMessage: (function(_this) { return function(room, messageText, message) { _this.stubs._msg = messageText; return _this.stubs._room = room; }; })(this) }; this.stubs.channelsMock = { setTopic: (function(_this) { return function(id, topic) { return _this.stubs._topic = topic; }; })(this) }; this.stubs.robot = (function() { var robot; robot = new EventEmitter; robot.logger = { logs: {}, log: function(type, message) { var base; if ((base = this.logs)[type] == null) { base[type] = []; } return this.logs[type].push(message); }, info: function(message) { return this.log('info', message); }, debug: function(message) { return this.log('debug', message); }, error: function(message) { return this.log('error', message); } }; robot.received = []; robot.receive = function(msg) { return this.received.push(msg); }; robot.brain = new Brain(robot); robot.name = 'bot'; return robot; })(); this.stubs.callback = (function() { return "done"; })(); this.stubs.receiveMock = { receive: (function(_this) { return function(message, user) { return _this.stubs._received = message; }; })(this) }; this.slackbot = new SlackBot(this.stubs.robot, { token: 'xoxb-faketoken' }); _.merge(this.slackbot.client, this.stubs.client); _.merge(this.slackbot.client.rtm, this.stubs.rtm); _.merge(this.slackbot.client.web.chat, this.stubs.chatMock); _.merge(this.slackbot.client.web.channels, this.stubs.channelsMock); _.merge(this.slackbot, this.stubs.receiveMock); this.formatter = new SlackFormatter(this.stubs.client.dataStore); this.client = new SlackClient({ token: 'xoxb-faketoken' }); _.merge(this.client.rtm, this.stubs.rtm); _.merge(this.client.web.chat, this.stubs.chatMock); return _.merge(this.client.web.channels, this.stubs.channelsMock); }); }).call(this); //# sourceMappingURL=stubs.js.map