Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should listen to authenticated event from websocket', () => {
// use stub to prevent actual call to websocket
const robot = new Robot('token');
const wsStartStub = sinon.stub(RtmClient.prototype, 'start');
const wsMessageStub = sinon.stub(RtmClient.prototype, 'on');
const loggerStub = sinon.stub(Log.prototype, 'info');
// mock dataStore
const botUserMock = {
id: 5,
name: 'slackbot'
};
robot._rtm.activeUserId = 5;
robot._rtm.dataStore = {
getUserById: sinon.stub().withArgs(robot._rtm.activeUserId).returns(botUserMock)
};
wsMessageStub.withArgs('authenticated').callsArg(1);
// start to listen
robot.start();
// this duck is not giving you the noise that you want, you've got to just
// punch that duck until it returns what you expect."
Log.SUCCESS = Log.INFO;
Log.prototype.success = function () {
arguments[0] = ' ✔ '.green + arguments[0];
this.log('SUCCESS', arguments);
};
Log.prototype.info = function () {
arguments[0] = ' ➔ '.black + arguments[0];
this.log('INFO', arguments);
};
Log.prototype.error = function () {
arguments[0] = ' ✘ '.red + arguments[0];
this.log('ERROR', arguments);
throw new Error(arguments[arguments.length - 1]);
};
module.exports = new Log('error').colorful({
SUCCESS : '\033[0;37m',
INFO : '\033[0;37m',
ERROR : '\033[0;37m'
});
var Log = require('log'),
colors = require('colors');
// Duck Punch the logger
// "... if it walks like a duck and talks like a duck, it's a duck, right? So if
// this duck is not giving you the noise that you want, you've got to just
// punch that duck until it returns what you expect."
Log.SUCCESS = Log.INFO;
Log.prototype.success = function () {
arguments[0] = ' ✔ '.green + arguments[0];
this.log('SUCCESS', arguments);
};
Log.prototype.info = function () {
arguments[0] = ' ➔ '.black + arguments[0];
this.log('INFO', arguments);
};
Log.prototype.error = function () {
arguments[0] = ' ✘ '.red + arguments[0];
this.log('ERROR', arguments);
throw new Error(arguments[arguments.length - 1]);
};
module.exports = new Log('error').colorful({
SUCCESS : '\033[0;37m',
INFO : '\033[0;37m',
ERROR : '\033[0;37m'
});
var Log = require('log'),
colors = require('colors');
// Duck Punch the logger
// "... if it walks like a duck and talks like a duck, it's a duck, right? So if
// this duck is not giving you the noise that you want, you've got to just
// punch that duck until it returns what you expect."
Log.SUCCESS = Log.INFO;
Log.prototype.success = function () {
arguments[0] = ' ✔ '.green + arguments[0];
this.log('SUCCESS', arguments);
};
Log.prototype.info = function () {
arguments[0] = ' ➔ '.black + arguments[0];
this.log('INFO', arguments);
};
Log.prototype.error = function () {
arguments[0] = ' ✘ '.red + arguments[0];
this.log('ERROR', arguments);
throw new Error(arguments[arguments.length - 1]);
};
module.exports = new Log('error').colorful({
'use strict';
const qs = require('querystring');
const Log = require('log');
const Axios = require('axios');
const Cookie = require('cookie');
// Extend log.js, add log type `verbose`
Log.VERBOSE = 8;
Log.prototype.verbose = function () {
this.log('VERBOSE', arguments);
};
const log = new Log(process.env.LOG_LEVEL || 'info');
function transformHeaders(k, v) {
if (k === 'Cookie') {
return Cookie.parse(v);
} else return v;
}
function logResponse(resp) {
if (resp) {
log.debug(`[HttpClient] ${(resp.config.method).toUpperCase()} ${resp.status} ${resp.statusText}
URL: ${resp.config.url}`);
log.verbose(`[HttpClient]
it('should log error from slack', () => {
const loggerStub = sinon.stub(Log.prototype, 'error');
const error = 'Random slack error';
slackEventStub.withArgs('error').callsArgWith(1, error);
new Robot(SLACK_ACCESS_TOKEN);
loggerStub.should.be.calledWith(error);
loggerStub.restore();
});
});
it('should store bot information after login', () => {
const loggerStub = sinon.stub(Log.prototype, 'info');
slackEventStub.withArgs('loggedIn').callsArgWith(1, botInfo);
const robot = new Robot(SLACK_ACCESS_TOKEN);
robot.id.should.be.deep.equal(botInfo.id);
robot.name.should.be.deep.equal(botInfo.name);
robot.mention.should.be.deep.equal(botInfo.mention);
loggerStub.should.be.calledWith('Logged in as x-men');
loggerStub.restore();
});
Logger.prototype.debug = function(msg) {
//do not print debug logs in production
if (!this.isProd())
Log.prototype.debug.call(this, msg);
}