Skip to content

Commit

Permalink
Extracted lib/bot.js from bagofholding.
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffano committed Feb 3, 2013
1 parent 65df9d7 commit 1c78d9e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
9 changes: 5 additions & 4 deletions lib/irc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var _ = require('underscore'),
bag = require('bagofholding'),
Bot = require('./bot'),
Jenkins = require('./jenkins'),
jenkins = new Jenkins(),
bot;
Expand Down Expand Up @@ -91,7 +91,8 @@ function _version() {
* @param {String} nick: optional nickname, defaults to 'nestor'
*/
function start(host, channel, nick) {

const PENDING = 1000;

var commands = {
build: _build,
stop: _stop,
Expand All @@ -103,8 +104,8 @@ function start(host, channel, nick) {
ver: _version
};

bot = new bag.irc.Bot(commands);
bot.connect(host, channel, { nick: nick });
bot = new Bot(commands);
bot.connect(host, channel, { nick: nick, pending: PENDING });
}

exports.start = start;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
},
"dependencies": {
"async": "0.1.22",
"bagofholding": "0.0.17",
"bagofholding": "0.1.0",
"colors": "0.6.0-1",
"irc": "0.3.6",
"request": "2.12.0",
"underscore": "1.4.3",
"xml2js": "0.2.2"
Expand Down
52 changes: 26 additions & 26 deletions test/irc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var bag = require('bagofholding'),
var Bot = require('../lib/bot'),
buster = require('buster'),
irc = require('../lib/irc'),
Jenkins = new require('../lib/jenkins');

buster.testCase('irc - build', {
'should say job started successfully when build is called and job exists': function (done) {
this.stub(bag.irc.Bot.prototype, 'connect', function (host, channel, opts) {
this.stub(Bot.prototype, 'connect', function (host, channel, opts) {
assert.equals(host, 'somehost');
assert.equals(channel, 'somechannel');
assert.equals(opts.nick, 'somenick');
Expand All @@ -16,15 +16,15 @@ buster.testCase('irc - build', {
assert.equals(params, 'foo=bar&foo1=bar1');
cb();
});
this.stub(bag.irc.Bot.prototype, 'say', function (format, data) {
this.stub(Bot.prototype, 'say', function (format, data) {
assert.equals(format, 'Job %s was started successfully');
assert.equals(data, 'job1');
done();
});
irc.start('somehost', 'somechannel', 'somenick');
},
'should say job started successfully when build is called without params': function (done) {
this.stub(bag.irc.Bot.prototype, 'connect', function (host, channel, opts) {
this.stub(Bot.prototype, 'connect', function (host, channel, opts) {
assert.equals(host, 'somehost');
assert.equals(channel, 'somechannel');
assert.equals(opts.nick, 'somenick');
Expand All @@ -35,7 +35,7 @@ buster.testCase('irc - build', {
assert.equals(params, undefined);
cb();
});
this.stub(bag.irc.Bot.prototype, 'say', function (format, data) {
this.stub(Bot.prototype, 'say', function (format, data) {
assert.equals(format, 'Job %s was started successfully');
assert.equals(data, 'job1');
done();
Expand All @@ -46,7 +46,7 @@ buster.testCase('irc - build', {

buster.testCase('irc - stop', {
setUp: function () {
this.stub(bag.irc.Bot.prototype, 'connect', function (host, channel, opts) {
this.stub(Bot.prototype, 'connect', function (host, channel, opts) {
assert.equals(host, 'somehost');
assert.equals(channel, 'somechannel');
assert.equals(opts.nick, 'somenick');
Expand All @@ -58,7 +58,7 @@ buster.testCase('irc - stop', {
assert.equals(jobName, 'job1');
cb(null, 'job1');
});
this.stub(bag.irc.Bot.prototype, 'say', function (format, data) {
this.stub(Bot.prototype, 'say', function (format, data) {
assert.equals(format, 'Job %s was stopped successfully');
assert.equals(data, 'job1');
done();
Expand All @@ -69,7 +69,7 @@ buster.testCase('irc - stop', {

buster.testCase('irc - dashboard', {
setUp: function () {
this.stub(bag.irc.Bot.prototype, 'connect', function (host, channel, opts) {
this.stub(Bot.prototype, 'connect', function (host, channel, opts) {
assert.equals(host, 'somehost');
assert.equals(channel, 'somechannel');
assert.equals(opts.nick, 'somenick');
Expand All @@ -84,7 +84,7 @@ buster.testCase('irc - dashboard', {
{ status: 'FAIL', name: 'job2' }
]);
});
this.stub(bag.irc.Bot.prototype, 'say', function () {
this.stub(Bot.prototype, 'say', function () {
result.push(arguments);
if (result.length === 2) {
assert.equals(result[0][0], '%s - %s');
Expand All @@ -102,7 +102,7 @@ buster.testCase('irc - dashboard', {
this.stub(Jenkins.prototype, 'dashboard', function (cb) {
cb(null, []);
});
this.stub(bag.irc.Bot.prototype, 'say', function (format, data) {
this.stub(Bot.prototype, 'say', function (format, data) {
assert.equals(format, 'Jobless Jenkins');
done();
});
Expand All @@ -112,7 +112,7 @@ buster.testCase('irc - dashboard', {

buster.testCase('irc - discover', {
'should say version and url when discover is called and there is a running Jenkins instance': function (done) {
this.stub(bag.irc.Bot.prototype, 'connect', function (host, channel, opts) {
this.stub(Bot.prototype, 'connect', function (host, channel, opts) {
assert.equals(host, 'somehost');
assert.equals(channel, 'somechannel');
assert.equals(opts.nick, 'somenick');
Expand All @@ -129,7 +129,7 @@ buster.testCase('irc - discover', {
}
});
});
this.stub(bag.irc.Bot.prototype, 'say', function (format, data0, data1) {
this.stub(Bot.prototype, 'say', function (format, data0, data1) {
assert.equals(format, 'Jenkins ver. %s is running on %s');
assert.equals(data0, '1.2.3');
assert.equals(data1, 'http://localhost:8080/');
Expand All @@ -138,7 +138,7 @@ buster.testCase('irc - discover', {
irc.start('somehost', 'somechannel', 'somenick');
},
'should use localhost when discover is called without host arg': function (done) {
this.stub(bag.irc.Bot.prototype, 'connect', function (host, channel, opts) {
this.stub(Bot.prototype, 'connect', function (host, channel, opts) {
assert.equals(host, 'somehost');
assert.equals(channel, 'somechannel');
assert.equals(opts.nick, 'somenick');
Expand All @@ -155,7 +155,7 @@ buster.testCase('irc - discover', {
}
});
});
this.stub(bag.irc.Bot.prototype, 'say', function (format, data0, data1) {
this.stub(Bot.prototype, 'say', function (format, data0, data1) {
assert.equals(format, 'Jenkins ver. %s is running on %s');
assert.equals(data0, '1.2.3');
assert.equals(data1, 'http://localhost:8080/');
Expand All @@ -164,7 +164,7 @@ buster.testCase('irc - discover', {
irc.start('somehost', 'somechannel', 'somenick');
},
'should say host instead of url when discover result does not include any url': function (done) {
this.stub(bag.irc.Bot.prototype, 'connect', function (host, channel, opts) {
this.stub(Bot.prototype, 'connect', function (host, channel, opts) {
assert.equals(host, 'somehost');
assert.equals(channel, 'somechannel');
assert.equals(opts.nick, 'somenick');
Expand All @@ -180,7 +180,7 @@ buster.testCase('irc - discover', {
}
});
});
this.stub(bag.irc.Bot.prototype, 'say', function (format, data0, data1) {
this.stub(Bot.prototype, 'say', function (format, data0, data1) {
assert.equals(format, 'Jenkins ver. %s is running on %s');
assert.equals(data0, '1.2.3');
assert.equals(data1, 'localhost');
Expand All @@ -192,7 +192,7 @@ buster.testCase('irc - discover', {

buster.testCase('irc - executor', {
setUp: function () {
this.stub(bag.irc.Bot.prototype, 'connect', function (host, channel, opts) {
this.stub(Bot.prototype, 'connect', function (host, channel, opts) {
assert.equals(host, 'somehost');
assert.equals(channel, 'somechannel');
assert.equals(opts.nick, 'somenick');
Expand All @@ -213,7 +213,7 @@ buster.testCase('irc - executor', {
]
});
});
this.stub(bag.irc.Bot.prototype, 'say', function () {
this.stub(Bot.prototype, 'say', function () {
result.push(arguments);
if (result.length === 6) {
assert.equals(result[0][0], '+ master');
Expand All @@ -240,7 +240,7 @@ buster.testCase('irc - executor', {
this.stub(Jenkins.prototype, 'executor', function (cb) {
cb(null, {});
});
this.stub(bag.irc.Bot.prototype, 'say', function (format, data) {
this.stub(Bot.prototype, 'say', function (format, data) {
assert.equals(format, 'No executor found');
done();
});
Expand All @@ -250,7 +250,7 @@ buster.testCase('irc - executor', {

buster.testCase('irc - job', {
setUp: function () {
this.stub(bag.irc.Bot.prototype, 'connect', function (host, channel, opts) {
this.stub(Bot.prototype, 'connect', function (host, channel, opts) {
assert.equals(host, 'somehost');
assert.equals(channel, 'somechannel');
assert.equals(opts.nick, 'somenick');
Expand All @@ -266,7 +266,7 @@ buster.testCase('irc - job', {
reports: ['Coverage 100%', 'All good!']
});
});
this.stub(bag.irc.Bot.prototype, 'say', function () {
this.stub(Bot.prototype, 'say', function () {
result.push(arguments);
if (result.length === 3) {
assert.equals(result[0][0], '%s | %s');
Expand All @@ -285,7 +285,7 @@ buster.testCase('irc - job', {

buster.testCase('irc - queue', {
setUp: function () {
this.stub(bag.irc.Bot.prototype, 'connect', function (host, channel, opts) {
this.stub(Bot.prototype, 'connect', function (host, channel, opts) {
assert.equals(host, 'somehost');
assert.equals(channel, 'somechannel');
assert.equals(opts.nick, 'somenick');
Expand All @@ -297,7 +297,7 @@ buster.testCase('irc - queue', {
this.stub(Jenkins.prototype, 'queue', function (cb) {
cb(null, ['job1', 'job2']);
});
this.stub(bag.irc.Bot.prototype, 'say', function () {
this.stub(Bot.prototype, 'say', function () {
result.push(arguments);
if (result.length === 2) {
assert.equals(result[0][0], '- %s');
Expand All @@ -313,7 +313,7 @@ buster.testCase('irc - queue', {
this.stub(Jenkins.prototype, 'queue', function (cb) {
cb(null, []);
});
this.stub(bag.irc.Bot.prototype, 'say', function (format, data) {
this.stub(Bot.prototype, 'say', function (format, data) {
assert.equals(format, 'Queue is empty');
done();
});
Expand All @@ -323,7 +323,7 @@ buster.testCase('irc - queue', {

buster.testCase('irc - ver', {
setUp: function () {
this.stub(bag.irc.Bot.prototype, 'connect', function (host, channel, opts) {
this.stub(Bot.prototype, 'connect', function (host, channel, opts) {
assert.equals(host, 'somehost');
assert.equals(channel, 'somechannel');
assert.equals(opts.nick, 'somenick');
Expand All @@ -334,7 +334,7 @@ buster.testCase('irc - ver', {
this.stub(Jenkins.prototype, 'version', function (cb) {
cb(null, '1.2.3');
});
this.stub(bag.irc.Bot.prototype, 'say', function (format, data) {
this.stub(Bot.prototype, 'say', function (format, data) {
assert.equals(format, 'Jenkins ver. %s');
assert.equals(data, '1.2.3');
done();
Expand Down

0 comments on commit 1c78d9e

Please sign in to comment.