From 3a3b9454b16a9676b5d21b11a30836970f10cd30 Mon Sep 17 00:00:00 2001 From: Alan Scherger Date: Mon, 8 Feb 2016 06:13:34 -0600 Subject: [PATCH 1/2] get tests passing again --- test/away.js | 30 ++++++----- test/invite.js | 40 +++++++------- test/join.js | 38 +++++++------- test/kick.js | 40 +++++++------- test/names.js | 123 +++++++++++++++++++++---------------------- test/nick.js | 38 +++++++------- test/notice.js | 81 ++++++++++++++-------------- test/part.js | 40 +++++++------- test/pong.js | 44 ++++++++-------- test/privmsg.js | 39 +++++++------- test/quit.js | 37 +++++++------ test/topic.js | 39 +++++++------- test/welcome.js | 39 +++++++------- test/whois.js | 137 +++++++++++++++++++++++------------------------- 14 files changed, 391 insertions(+), 374 deletions(-) diff --git a/test/away.js b/test/away.js index d987979..724ebf2 100644 --- a/test/away.js +++ b/test/away.js @@ -1,19 +1,21 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('away()', function() { - describe('on RPL_AWAY', function() { - it('should emit "away"', function(done) { - var stream = new Stream; - var client = irc(stream); - - client.on('away', function(e) { - e.nick.should.equal('colinm'); - e.message.should.eql('brb food time'); - done(); - }); - - stream.write(':irc.host.net 301 me colinm :brb food time\r\n'); +describe('away()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); + }); + describe('on RPL_AWAY', function () { + it('should emit "away"', function (done) { + client.on('away', function (e) { + e.nick.should.equal('colinm'); + e.message.should.eql('brb food time'); + done(); + }); + stream.write(':irc.host.net 301 me colinm :brb food time\r\n'); + }); }); - }); }); diff --git a/test/invite.js b/test/invite.js index bca468f..4afdd47 100644 --- a/test/invite.js +++ b/test/invite.js @@ -1,24 +1,26 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('invite()', function() { - describe('on INVITE', function() { - it('should emit "invite"', function(done) { - var stream = new Stream; - var client = irc(stream); - - client.on('invite', function(e) { - e.from.should.equal('test'); - e.to.should.equal('astranger'); - e.channel.should.equal('#something'); - e.hostmask.nick.should.equal('test'); - e.hostmask.username.should.equal('~user'); - e.hostmask.hostname.should.equal('example.com'); - e.hostmask.string.should.equal('test!~user@example.com'); - done(); - }); - - stream.write(':test!~user@example.com INVITE astranger :#something\r\n'); +describe('invite()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); + }); + describe('on INVITE', function () { + it('should emit "invite"', function (done) { + client.on('invite', function (e) { + e.from.should.equal('test'); + e.to.should.equal('astranger'); + e.channel.should.equal('#something'); + e.hostmask.nick.should.equal('test'); + e.hostmask.username.should.equal('~user'); + e.hostmask.hostname.should.equal('example.com'); + e.hostmask.string.should.equal('test!~user@example.com'); + done(); + }); + stream.write(':test!~user@example.com INVITE astranger :#something\r\n'); + }); }); - }); }); diff --git a/test/join.js b/test/join.js index bc334c3..12d0522 100644 --- a/test/join.js +++ b/test/join.js @@ -1,23 +1,25 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('join()', function() { - describe('on JOIN', function() { - it('should emit "join"', function(done) { - var stream = new Stream; - var client = irc(stream); - - client.on('join', function(e) { - e.nick.should.equal('tjholowaychuk'); - e.channel.should.equal('#express'); - e.hostmask.nick.should.equal('tjholowaychuk'); - e.hostmask.username.should.equal('~tjholoway'); - e.hostmask.hostname.should.equal('S01067cb21b2fd643.gv.shawcable.net'); - e.hostmask.string.should.equal('tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net'); - done(); - }); - - stream.write(':tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net JOIN #express\r\n'); +describe('join()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); + }); + describe('on JOIN', function () { + it('should emit "join"', function (done) { + client.on('join', function (e) { + e.nick.should.equal('tjholowaychuk'); + e.channel.should.equal('#express'); + e.hostmask.nick.should.equal('tjholowaychuk'); + e.hostmask.username.should.equal('~tjholoway'); + e.hostmask.hostname.should.equal('S01067cb21b2fd643.gv.shawcable.net'); + e.hostmask.string.should.equal('tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net'); + done(); + }); + stream.write(':tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net JOIN #express\r\n'); + }); }); - }); }); diff --git a/test/kick.js b/test/kick.js index 933ec80..d418f05 100644 --- a/test/kick.js +++ b/test/kick.js @@ -1,24 +1,26 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('kick()', function() { - describe('on KICK', function() { - it('should emit "kick"', function(done) { - var stream = new Stream; - var client = irc(stream); - - client.on('kick', function(e) { - e.nick.should.equal('tjholowaychuk'); - e.client.should.equal('tobi'); - e.channel.should.eql('#express'); - e.hostmask.nick.should.equal('tjholowaychuk'); - e.hostmask.username.should.equal('~tjholoway'); - e.hostmask.hostname.should.equal('S01067cb21b2fd643.gv.shawcable.net'); - e.hostmask.string.should.equal('tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net'); - done(); - }); - - stream.write(':tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net KICK #express tobi :Too ferrety\r\n'); +describe('kick()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); + }); + describe('on KICK', function () { + it('should emit "kick"', function (done) { + client.on('kick', function (e) { + e.nick.should.equal('tjholowaychuk'); + e.client.should.equal('tobi'); + e.channel.should.eql('#express'); + e.hostmask.nick.should.equal('tjholowaychuk'); + e.hostmask.username.should.equal('~tjholoway'); + e.hostmask.hostname.should.equal('S01067cb21b2fd643.gv.shawcable.net'); + e.hostmask.string.should.equal('tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net'); + done(); + }); + stream.write(':tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net KICK #express tobi :Too ferrety\r\n'); + }); }); - }); }); diff --git a/test/names.js b/test/names.js index d8c5bfc..84ae399 100644 --- a/test/names.js +++ b/test/names.js @@ -1,74 +1,71 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('names()', function() { - describe('client.names(chan, fn)', function() { - it('should respond with user names', function(done) { - var stream = new Stream; - var client = irc(stream); - - client.names('#luna-lang', function(err, names) { - if (err) return done(err); - names.should.eql([ - {name: 'owner', mode: '~'}, - {name: 'foo', mode: '@'}, - {name: 'halfop', mode: '%'}, - {name: 'bar', mode: '+'}, - {name: 'baz', mode: ''}, - {name: 'some', mode: ''}, - {name: 'more', mode: ''} - ]); - done(); - }); +describe('names()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); + }); + describe('client.names(chan, fn)', function () { + it('should respond with user names', function (done) { + client.names('#luna-lang', function (err, names) { + if (err) return done(err); + names.should.eql([ + {name: 'owner', mode: '~'}, + {name: 'foo', mode: '@'}, + {name: 'halfop', mode: '%'}, + {name: 'bar', mode: '+'}, + {name: 'baz', mode: ''}, + {name: 'some', mode: ''}, + {name: 'more', mode: ''} + ]); + done(); + }); - setImmediate(function() { - stream.write(':pratchett.freenode.net 353 tjholowaychuk = #luna-lang :~owner @foo %halfop +bar baz\r\n'); - stream.write(':pratchett.freenode.net 353 tjholowaychuk = #luna-lang :some more\r\n'); - stream.write(':pratchett.freenode.net 366 tjholowaychuk #luna-lang :End of /NAMES list.\r\n'); - }); + setImmediate(function () { + stream.write(':pratchett.freenode.net 353 tjholowaychuk = #luna-lang :~owner @foo %halfop +bar baz\r\n'); + stream.write(':pratchett.freenode.net 353 tjholowaychuk = #luna-lang :some more\r\n'); + stream.write(':pratchett.freenode.net 366 tjholowaychuk #luna-lang :End of /NAMES list.\r\n'); + }); + }); }); - }); - it('should emit "names"', function(done) { - var stream = new Stream; - var client = irc(stream); + it('should emit "names"', function (done) { + client.on('names', function (e) { + e.channel.should.equal('#luna-lang'); + e.names.should.eql([ + {name: 'one', mode: ''}, + {name: 'two', mode: '~'}, + {name: 'three', mode: ''}, + {name: 'foo', mode: '@'}, + {name: 'bar', mode: '@'}, + {name: 'baz', mode: '%'} + ]); + done(); + }); - client.on('names', function(e) { - e.channel.should.equal('#luna-lang'); - e.names.should.eql([ - {name: 'one', mode: ''}, - {name: 'two', mode: '~'}, - {name: 'three', mode: ''}, - {name: 'foo', mode: '@'}, - {name: 'bar', mode: '@'}, - {name: 'baz', mode: '%'} - ]); - done(); + stream.write(':tobi!~tobi@184.151.231.170 JOIN #luna-lang\r\n'); + stream.write(':rothfuss.freenode.net 353 tjholowaychuk = #luna-lang :one ~two three\r\n'); + stream.write(':rothfuss.freenode.net 353 tjholowaychuk = #luna-lang :@foo @bar %baz\r\n'); + stream.write(':rothfuss.freenode.net 366 tjholowaychuk #luna-lang :End of /NAMES list.\r\n'); }); - stream.write(':tobi!~tobi@184.151.231.170 JOIN #luna-lang\r\n'); - stream.write(':rothfuss.freenode.net 353 tjholowaychuk = #luna-lang :one ~two three\r\n'); - stream.write(':rothfuss.freenode.net 353 tjholowaychuk = #luna-lang :@foo @bar %baz\r\n'); - stream.write(':rothfuss.freenode.net 366 tjholowaychuk #luna-lang :End of /NAMES list.\r\n'); - }); + it('should retain ~ / @ / % / +', function (done) { + client.on('names', function (e) { + e.channel.should.equal('##luna-lang'); + e.names.should.eql([ + {name: 'owner', mode: '~'}, + {name: 'tjholowaychuk', mode: '@'}, + {name: 'halfop', mode: '%'}, + {name: 'tobi', mode: '+'} + ]); + done(); + }); - it('should retain ~ / @ / % / +', function(done) { - var stream = new Stream; - var client = irc(stream); - - client.on('names', function(e) { - e.channel.should.equal('##luna-lang'); - e.names.should.eql([ - {name: 'owner', mode: '~'}, - {name: 'tjholowaychuk', mode: '@'}, - {name: 'halfop', mode: '%'}, - {name: 'tobi', mode: '+'} - ]); - done(); + stream.write(':tobi!~tobi@184.151.231.170 JOIN #luna-lang\r\n'); + stream.write(':rothfuss.freenode.net 353 tjholowaychuk @ ##luna-lang :~owner @tjholowaychuk %halfop +tobi\r\n'); + stream.write(':rothfuss.freenode.net 366 tjholowaychuk ##luna-lang :End of /NAMES list.\r\n'); }); - - stream.write(':tobi!~tobi@184.151.231.170 JOIN #luna-lang\r\n'); - stream.write(':rothfuss.freenode.net 353 tjholowaychuk @ ##luna-lang :~owner @tjholowaychuk %halfop +tobi\r\n'); - stream.write(':rothfuss.freenode.net 366 tjholowaychuk ##luna-lang :End of /NAMES list.\r\n'); - }); -}); +}); \ No newline at end of file diff --git a/test/nick.js b/test/nick.js index 46a60b1..325bfec 100644 --- a/test/nick.js +++ b/test/nick.js @@ -1,24 +1,26 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('nick()', function() { - describe('on NICK', function() { - - it('should emit "nick"', function(done) { - var stream = new Stream; - var client = irc(stream); - - client.on('nick', function(e) { - e.nick.should.eql('colinm'); - e.new.should.equal('cmilhench'); - e.hostmask.nick.should.equal('colinm'); - e.hostmask.username.should.equal('~colinm'); - e.hostmask.hostname.should.equal('host-92-17-247-88.as13285.net'); - e.hostmask.string.should.equal('colinm!~colinm@host-92-17-247-88.as13285.net'); - done(); - }); +describe('nick()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); + }); + describe('on NICK', function () { + it('should emit "nick"', function (done) { + client.on('nick', function (e) { + e.nick.should.eql('colinm'); + e.new.should.equal('cmilhench'); + e.hostmask.nick.should.equal('colinm'); + e.hostmask.username.should.equal('~colinm'); + e.hostmask.hostname.should.equal('host-92-17-247-88.as13285.net'); + e.hostmask.string.should.equal('colinm!~colinm@host-92-17-247-88.as13285.net'); + done(); + }); - stream.write(':colinm!~colinm@host-92-17-247-88.as13285.net NICK :cmilhench\r\n'); + stream.write(':colinm!~colinm@host-92-17-247-88.as13285.net NICK :cmilhench\r\n'); + }); }); - }); }); diff --git a/test/notice.js b/test/notice.js index 062e41b..0b32247 100644 --- a/test/notice.js +++ b/test/notice.js @@ -1,45 +1,48 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('notice()', function() { - describe('on NOTICE', function() { - it('should emit "notice"', function(done) { - var stream = new Stream; - var client = irc(stream); - var n = 0; - - client.on('notice', function(e) { - e.from.should.equal('NickServ'); - e.to.should.equal('cmilhench'); - e.hostmask.nick.should.equal('NickServ'); - e.hostmask.username.should.equal('NickServ'); - e.hostmask.hostname.should.equal('services.'); - e.hostmask.string.should.equal('NickServ!NickServ@services.'); - switch (++n) { - case 1: - e.message.should.equal([ - 'This nickname is registered. ', - 'Please choose a different nickname, ', - 'or identify via /msg NickServ identify .'].join('')); - break; - case 2: - e.message.should.equal([ - 'You have 30 seconds to identify to your nickname ', - 'before it is changed.'].join('')); - done(); - break; - } - }); +describe('notice()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); + }); + describe('on NOTICE', function () { + it('should emit "notice"', function (done) { + var n = 0; + client.on('notice', function(e) { + e.from.should.equal('NickServ'); + e.to.should.equal('cmilhench'); + e.hostmask.nick.should.equal('NickServ'); + e.hostmask.username.should.equal('NickServ'); + e.hostmask.hostname.should.equal('services.'); + e.hostmask.string.should.equal('NickServ!NickServ@services.'); + switch (++n) { + case 1: + e.message.should.equal([ + 'This nickname is registered. ', + 'Please choose a different nickname, ', + 'or identify via /msg NickServ identify .'].join('')); + break; + case 2: + e.message.should.equal([ + 'You have 30 seconds to identify to your nickname ', + 'before it is changed.'].join('')); + done(); + break; + } + }); - stream.write([ - ':NickServ!NickServ@services. NOTICE cmilhench :', - 'This nickname is registered. ', - 'Please choose a different nickname, ', - 'or identify via /msg NickServ identify .\r\n'].join('')); - stream.write([ - ':NickServ!NickServ@services. NOTICE cmilhench :', - 'You have 30 seconds to identify to your nickname ', - 'before it is changed.\r\n'].join('')); + stream.write([ + ':NickServ!NickServ@services. NOTICE cmilhench :', + 'This nickname is registered. ', + 'Please choose a different nickname, ', + 'or identify via /msg NickServ identify .\r\n'].join('')); + stream.write([ + ':NickServ!NickServ@services. NOTICE cmilhench :', + 'You have 30 seconds to identify to your nickname ', + 'before it is changed.\r\n'].join('')); + }); }); - }); }); diff --git a/test/part.js b/test/part.js index 210e2f5..aed7a93 100644 --- a/test/part.js +++ b/test/part.js @@ -1,24 +1,26 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('part()', function() { - describe('on PART', function() { - it('should emit "part"', function(done) { - var stream = new Stream; - var client = irc(stream); - - client.on('part', function(e) { - e.nick.should.equal('tjholowaychuk'); - e.channels.should.eql(['#express']); - e.message.should.equal('So long!'); - e.hostmask.nick.should.equal('tjholowaychuk'); - e.hostmask.username.should.equal('~tjholoway'); - e.hostmask.hostname.should.equal('S01067cb21b2fd643.gv.shawcable.net'); - e.hostmask.string.should.equal('tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net'); - done(); - }); - - stream.write(':tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net PART #express :So long!\r\n'); +describe('part()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); + }); + describe('on PART', function () { + it('should emit "part"', function (done) { + client.on('part', function (e) { + e.nick.should.equal('tjholowaychuk'); + e.channels.should.eql(['#express']); + e.message.should.equal('So long!'); + e.hostmask.nick.should.equal('tjholowaychuk'); + e.hostmask.username.should.equal('~tjholoway'); + e.hostmask.hostname.should.equal('S01067cb21b2fd643.gv.shawcable.net'); + e.hostmask.string.should.equal('tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net'); + done(); + }); + stream.write(':tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net PART #express :So long!\r\n'); + }); }); - }); }); diff --git a/test/pong.js b/test/pong.js index 6abee4a..477c1c1 100644 --- a/test/pong.js +++ b/test/pong.js @@ -1,26 +1,28 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('pong()', function() { - describe('on PING', function() { - it('should respond with PONG', function(done) { - var stream = new Stream; - var client = irc(stream); - var n = 0; - - stream.on('data', function(chunk) { - switch (n++) { - case 0: - chunk.should.equal('PING :rothfuss.freenode.net\r\n'); - break; - case 1: - chunk.should.equal('PONG :rothfuss.freenode.net\r\n'); - done(); - break; - } - }); - - stream.write('PING :rothfuss.freenode.net\r\n'); +describe('pong()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); + }); + describe('on PING', function () { + it('should respond with PONG', function (done) { + var n = 0; + stream.on('data', function(chunk) { + switch (n++) { + case 0: + chunk.should.equal('PING :rothfuss.freenode.net\r\n'); + break; + case 1: + chunk.should.equal('PONG :rothfuss.freenode.net\r\n'); + done(); + break; + } + }); + stream.write('PING :rothfuss.freenode.net\r\n'); + }); }); - }); }); diff --git a/test/privmsg.js b/test/privmsg.js index 2cbd041..f4b1fae 100644 --- a/test/privmsg.js +++ b/test/privmsg.js @@ -1,24 +1,27 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('privmsg()', function() { - describe('on PRIVMSG', function() { - it('should emit "message"', function(done) { - var stream = new Stream; - var client = irc(stream); - - client.on('message', function(e) { - e.from.should.equal('tobi'); - e.to.should.equal('loki'); - e.message.should.equal('Hello :)'); - e.hostmask.nick.should.equal('tobi'); - e.hostmask.username.should.equal('~user'); - e.hostmask.hostname.should.equal('example.com'); - e.hostmask.string.should.equal('tobi!~user@example.com'); - done(); - }); +describe('privmsg()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); + }); + describe('on PRIVMSG', function () { + it('should emit "message"', function (done) { + client.on('message', function (e) { + e.from.should.equal('tobi'); + e.to.should.equal('loki'); + e.message.should.equal('Hello :)'); + e.hostmask.nick.should.equal('tobi'); + e.hostmask.username.should.equal('~user'); + e.hostmask.hostname.should.equal('example.com'); + e.hostmask.string.should.equal('tobi!~user@example.com'); + done(); + }); - stream.write(':tobi!~user@example.com PRIVMSG loki :Hello :)\r\n'); + stream.write(':tobi!~user@example.com PRIVMSG loki :Hello :)\r\n'); + }); }); - }); }); diff --git a/test/quit.js b/test/quit.js index 39a0f71..9ad0b98 100644 --- a/test/quit.js +++ b/test/quit.js @@ -1,23 +1,26 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('quit()', function() { - describe('on QUIT', function() { - it('should emit "quit"', function(done) { - var stream = new Stream; - var client = irc(stream); - - client.on('quit', function(e) { - e.nick.should.equal('tobi'); - e.message.should.eql('Remote host closed the connection'); - e.hostmask.nick.should.equal('tobi'); - e.hostmask.username.should.equal('~tobi'); - e.hostmask.hostname.should.equal('107-214-168-243.lightspeed.cicril.sbcglobal.net'); - e.hostmask.string.should.equal('tobi!~tobi@107-214-168-243.lightspeed.cicril.sbcglobal.net'); - done(); - }); +describe('quit()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); + }); + describe('on QUIT', function () { + it('should emit "quit"', function (done) { + client.on('quit', function (e) { + e.nick.should.equal('tobi'); + e.message.should.eql('Remote host closed the connection'); + e.hostmask.nick.should.equal('tobi'); + e.hostmask.username.should.equal('~tobi'); + e.hostmask.hostname.should.equal('107-214-168-243.lightspeed.cicril.sbcglobal.net'); + e.hostmask.string.should.equal('tobi!~tobi@107-214-168-243.lightspeed.cicril.sbcglobal.net'); + done(); + }); - stream.write(':tobi!~tobi@107-214-168-243.lightspeed.cicril.sbcglobal.net QUIT :Remote host closed the connection\r\n'); + stream.write(':tobi!~tobi@107-214-168-243.lightspeed.cicril.sbcglobal.net QUIT :Remote host closed the connection\r\n'); + }); }); - }); }); diff --git a/test/topic.js b/test/topic.js index 7645979..97ce8ee 100644 --- a/test/topic.js +++ b/test/topic.js @@ -1,24 +1,27 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('topic()', function() { - describe('on TOPIC', function() { - it('should emit "topic"', function(done) { - var stream = new Stream; - var client = irc(stream); - - client.on('topic', function(e) { - e.nick.should.equal('tobi'); - e.channel.should.eql('#slate'); - e.topic.should.equal('Slate 1.0 is out!'); - e.hostmask.nick.should.equal('tobi'); - e.hostmask.username.should.equal('~user'); - e.hostmask.hostname.should.equal('example.com'); - e.hostmask.string.should.equal('tobi!~user@example.com'); - done(); - }); +describe('topic()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); + }); + describe('on TOPIC', function () { + it('should emit "topic"', function (done) { + client.on('topic', function (e) { + e.nick.should.equal('tobi'); + e.channel.should.eql('#slate'); + e.topic.should.equal('Slate 1.0 is out!'); + e.hostmask.nick.should.equal('tobi'); + e.hostmask.username.should.equal('~user'); + e.hostmask.hostname.should.equal('example.com'); + e.hostmask.string.should.equal('tobi!~user@example.com'); + done(); + }); - stream.write(':tobi!~user@example.com TOPIC #slate :Slate 1.0 is out!\r\n'); + stream.write(':tobi!~user@example.com TOPIC #slate :Slate 1.0 is out!\r\n'); + }); }); - }); }); diff --git a/test/welcome.js b/test/welcome.js index 33b40b8..acbebf4 100644 --- a/test/welcome.js +++ b/test/welcome.js @@ -1,27 +1,28 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('welcome()', function() { - describe('on RPL_WELCOME', function() { - it('should set client.me to the users nick', function() { - var stream = new Stream; - var client = irc(stream); - stream.write(':cameron.freenode.net 001 tobi :Welcome to the freenode Internet Relay Chat Network tobi\r\n'); - process.nextTick(function() { - client.me.should.equal('tobi'); - }); +describe('welcome()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); }); + describe('on RPL_WELCOME', function () { + it('should set client.me to the users nick', function () { + stream.write(':cameron.freenode.net 001 tobi :Welcome to the freenode Internet Relay Chat Network tobi\r\n'); + process.nextTick(function () { + client.me.should.equal('tobi'); + }); + }); - it('should emit "welcome"', function(done) { - var stream = new Stream; - var client = irc(stream); + it('should emit "welcome"', function (done) { + client.on('welcome', function (nick) { + nick.should.equal('tobi'); + done(); + }); - client.on('welcome', function(nick) { - nick.should.equal('tobi'); - done(); - }); - - stream.write(':cameron.freenode.net 001 tobi :Welcome to the freenode Internet Relay Chat Network tobi\r\n'); + stream.write(':cameron.freenode.net 001 tobi :Welcome to the freenode Internet Relay Chat Network tobi\r\n'); + }); }); - }); }); diff --git a/test/whois.js b/test/whois.js index ea6deac..3e0be54 100644 --- a/test/whois.js +++ b/test/whois.js @@ -1,27 +1,31 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('whois()', function() { - describe('client.whois(target, mask, fn)', function() { - it('should respond with user info', function(done) { - var stream = new Stream; - var client = irc(stream); - - client.whois('colinm', function(err, e) { - if (err) return done(err);e.hostname.should.equal('client.host.net'); - e.username.should.equal('~colinm'); - e.realname.should.equal('Colin Milhench'); - e.server.should.equal('other.host.net'); - e.channels.should.be.instanceof(Array).and.have.lengthOf(4); - e.channels.should.containEql('#Node.js'); - e.channels.should.containEql('#express'); - e.channels.should.containEql('#some'); - e.channels.should.containEql('#more'); - e.away.should.equal('brb'); - e.sign.should.equal('1384330635'); - e.idle.should.equal('10543'); - done(); - }); +describe('whois()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () {}; + client = irc(stream); + }); + describe('client.whois(target, mask, fn)', function () { + it('should respond with user info', function (done) { + client.whois('colinm', function (err, e) { + if (err) return done(err); + e.hostname.should.equal('client.host.net'); + e.username.should.equal('~colinm'); + e.realname.should.equal('Colin Milhench'); + e.server.should.equal('other.host.net'); + e.channels.should.be.instanceof(Array).and.have.lengthOf(4); + e.channels.should.containEql('#Node.js'); + e.channels.should.containEql('#express'); + e.channels.should.containEql('#some'); + e.channels.should.containEql('#more'); + e.away.should.equal('brb'); + e.sign.should.equal('1384330635'); + e.idle.should.equal('10543'); + done(); + }); stream.write(':irc.host.net 311 me colinm ~colinm client.host.net * :Colin Milhench\r\n'); stream.write(':irc.host.net 319 me colinm :#Node.js #express\r\n'); @@ -34,24 +38,21 @@ describe('whois()', function() { stream.write(':irc.host.net 318 me colinm :End of /WHOIS list.\r\n'); }); - it('should emit "info"', function(done) { - var stream = new Stream; - var client = irc(stream); - - client.on('whois', function(err, e) { - e.hostname.should.equal('client.host.net'); - e.username.should.equal('~colinm'); - e.realname.should.equal('Colin Milhench'); - e.server.should.equal('other.host.net'); - e.channels.should.be.instanceof(Array).and.have.lengthOf(4); - e.channels.should.containEql('#Node.js'); - e.channels.should.containEql('#express'); - e.channels.should.containEql('#some'); - e.channels.should.containEql('#more'); - e.sign.should.equal('1384330635'); - e.idle.should.equal('10543'); - done(); - }); + it('should emit "info"', function (done) { + client.on('whois', function (err, e) { + e.hostname.should.equal('client.host.net'); + e.username.should.equal('~colinm'); + e.realname.should.equal('Colin Milhench'); + e.server.should.equal('other.host.net'); + e.channels.should.be.instanceof(Array).and.have.lengthOf(4); + e.channels.should.containEql('#Node.js'); + e.channels.should.containEql('#express'); + e.channels.should.containEql('#some'); + e.channels.should.containEql('#more'); + e.sign.should.equal('1384330635'); + e.idle.should.equal('10543'); + done(); + }); stream.write(':irc.host.net 311 me colinm ~colinm client.host.net * :Colin Milhench\r\n'); stream.write(':irc.host.net 319 me colinm :#Node.js #express\r\n'); @@ -63,11 +64,9 @@ describe('whois()', function() { stream.write(':irc.host.net 318 me colinm :End of /WHOIS list.\r\n'); }); - it('should emit "info"', function(done) { - var stream = new Stream; - var client = irc(stream); - client.whois('colinm'); + it('should emit "info"', function (done) { + client.whois('colinm'); client.on('whois', function(err, e) { e.hostname.should.equal('client.host.net'); @@ -94,36 +93,30 @@ describe('whois()', function() { stream.write(':irc.host.net 318 me colinm :End of /WHOIS list.\r\n'); }); - it('should err with No such nick/channel', function(done) { - var stream = new Stream; - var client = irc(stream); - client.whois('nonick'); - client.on('whois', function(err, e) { - err.should.equal('No such nick/channel'); - done(); - }); - stream.write(':irc.freenode.net 401 me nonick :No such nick/channel\r\n'); - stream.write(':irc.freenode.net 318 me nonick :End of /WHOIS list.\r\n'); - }); + it('should err with No such nick/channel', function (done) { + client.whois('nonick'); + client.on('whois', function (err, e) { + err.should.equal('No such nick/channel'); + done(); + }); + stream.write(':irc.freenode.net 401 me nonick :No such nick/channel\r\n'); + stream.write(':irc.freenode.net 318 me nonick :End of /WHOIS list.\r\n'); + }); - it('should err with No such server', function(done) { - var stream = new Stream; - var client = irc(stream); - client.whois('nonick', function(err, e) { - err.should.equal('No such server'); - done(); - }); - stream.write(':holmes.freenode.net 402 me nonick :No such server\r\n'); - }); + it('should err with No such server', function (done) { + client.whois('nonick', function (err, e) { + err.should.equal('No such server'); + done(); + }); + stream.write(':holmes.freenode.net 402 me nonick :No such server\r\n'); + }); - it('should err with Not enough parameters', function(done) { - var stream = new Stream; - var client = irc(stream); - client.on('whois', function(err, e) { - err.should.equal('Not enough parameters'); - done(); - }); - stream.write(':irc.freenode.net 461 me WHOIS :Not enough parameters\r\n'); + it('should err with Not enough parameters', function (done) { + client.on('whois', function (err, e) { + err.should.equal('Not enough parameters'); + done(); + }); + stream.write(':irc.freenode.net 461 me WHOIS :Not enough parameters\r\n'); + }); }); - }); }); From fd074f7e146e12006f6a3c7daf4d6a6ec30bb7e1 Mon Sep 17 00:00:00 2001 From: Alan Scherger Date: Mon, 8 Feb 2016 08:45:26 -0600 Subject: [PATCH 2/2] sasl support --- index.js | 52 ++++++++++++- lib/plugins/authenticate.js | 17 +++++ lib/plugins/cap.js | 20 +++++ lib/plugins/rplloggedin.js | 17 +++++ lib/plugins/rplsaslsuccess.js | 17 +++++ test/authenticate.js | 22 ++++++ test/away.js | 36 +++++---- test/cap.js | 46 ++++++++++++ test/invite.js | 46 ++++++------ test/join.js | 44 ++++++----- test/kick.js | 46 ++++++------ test/names.js | 125 ++++++++++++++++---------------- test/nick.js | 43 ++++++----- test/notice.js | 89 ++++++++++++----------- test/part.js | 46 ++++++------ test/pong.js | 51 +++++++------ test/privmsg.js | 45 ++++++------ test/quit.js | 43 ++++++----- test/rplloggedin.js | 22 ++++++ test/rplsaslsuccess.js | 22 ++++++ test/topic.js | 45 ++++++------ test/welcome.js | 43 ++++++----- test/whois.js | 133 +++++++++++++++++----------------- 23 files changed, 677 insertions(+), 393 deletions(-) create mode 100644 lib/plugins/authenticate.js create mode 100644 lib/plugins/cap.js create mode 100644 lib/plugins/rplloggedin.js create mode 100644 lib/plugins/rplsaslsuccess.js create mode 100644 test/authenticate.js create mode 100644 test/cap.js create mode 100644 test/rplloggedin.js create mode 100644 test/rplsaslsuccess.js diff --git a/index.js b/index.js index 7ab997d..c23b2aa 100755 --- a/index.js +++ b/index.js @@ -12,7 +12,9 @@ var replies = require('irc-replies'); * Core plugins. */ +var authenticate = require('./lib/plugins/authenticate'); var away = require('./lib/plugins/away'); +var cap = require('./lib/plugins/cap'); var disconnect = require('./lib/plugins/disconnect'); var errors = require('./lib/plugins/errors'); var invite = require('./lib/plugins/invite'); @@ -27,6 +29,8 @@ var part = require('./lib/plugins/part'); var pong = require('./lib/plugins/pong'); var privmsg = require('./lib/plugins/privmsg'); var quit = require('./lib/plugins/quit'); +var rplloggedin = require('./lib/plugins/rplloggedin'); +var rplsaslsuccess = require('./lib/plugins/rplsaslsuccess'); var topic = require('./lib/plugins/topic'); var welcome = require('./lib/plugins/welcome'); var whois = require('./lib/plugins/whois'); @@ -55,7 +59,9 @@ function Client(stream, parser, encoding) { this.parser.on('message', this.onmessage.bind(this)); stream.pipe(this.parser); this.setMaxListeners(100); + this.use(authenticate()); this.use(away()); + this.use(cap()); this.use(disconnect()); this.use(errors()); this.use(invite()); @@ -70,6 +76,8 @@ function Client(stream, parser, encoding) { this.use(pong()); this.use(privmsg()); this.use(quit()); + this.use(rplloggedin()); + this.use(rplsaslsuccess()); this.use(topic()); this.use(welcome()); this.use(whois()); @@ -88,11 +96,53 @@ Client.prototype.__proto__ = Emitter.prototype; * @param {Function} [fn] * @api public */ - Client.prototype.write = function(str, fn) { + debug('write %s', str); this.stream.write(str + '\r\n', fn); }; +/** + * CAP REQ + * + * @param {String} reqs + * @api public + */ +Client.prototype.cap_req = function(reqs) { + this.write('CAP REQ :' + reqs); +}; + +/** + * CAP END + * + * @api public + */ +Client.prototype.cap_end = function() { + this.write('CAP END'); +}; + +/** + * AUTHENTICATE + * + * @param {String} msg + * @api public + */ +Client.prototype.authenticate = function(msg) { + this.write('AUTHENTICATE ' + msg) +}; + +/** + * AUTHENTICATE base64(\0\0) + * + * @param {String} username + * @param {String} password + * @api public + */ +Client.prototype.authenticate64 = function(username, password) { + var b = new Buffer(username + "\0" + username + "\0" + password, 'utf8'); + var b64 = b.toString('base64'); + this.write('AUTHENTICATE ' + b64) +}; + /** * PASS * diff --git a/lib/plugins/authenticate.js b/lib/plugins/authenticate.js new file mode 100644 index 0000000..9ef496d --- /dev/null +++ b/lib/plugins/authenticate.js @@ -0,0 +1,17 @@ +/** + * AUTHENTICATE plugin to emit "authenticate" events. + * + * @return {Function} + * @api public + */ + +module.exports = function () { + return function (irc) { + irc.on('data', function (msg) { + if ('AUTHENTICATE' != msg.command) return; + var e = {}; + e.message = msg.params; + irc.emit('authenticate', e); + }); + } +}; diff --git a/lib/plugins/cap.js b/lib/plugins/cap.js new file mode 100644 index 0000000..77f44ab --- /dev/null +++ b/lib/plugins/cap.js @@ -0,0 +1,20 @@ +/** + * CAP plugin to emit "cap" events. + * + * @return {Function} + * @api public + */ + +module.exports = function () { + return function (irc) { + irc.on('data', function (msg) { + if ('CAP' != msg.command) return; + var params = msg.params.split(' '); + var e = {}; + e.nick = params[0]; + e.command = params[1]; + e.capabilities = msg.trailing.split(' '); + irc.emit('cap', e); + }); + } +}; diff --git a/lib/plugins/rplloggedin.js b/lib/plugins/rplloggedin.js new file mode 100644 index 0000000..23adcf7 --- /dev/null +++ b/lib/plugins/rplloggedin.js @@ -0,0 +1,17 @@ +/** + * RPL_LOGGEDIN plugin to emit "loggedin" events. + * + * @return {Function} + * @api public + */ + +module.exports = function () { + return function (irc) { + irc.on('data', function (msg) { + if ('900' != msg.command && 'RPL_LOGGEDIN' != msg.command) return; + var e = {}; + e.message = msg.trailing; + irc.emit('loggedin', e); + }); + } +}; diff --git a/lib/plugins/rplsaslsuccess.js b/lib/plugins/rplsaslsuccess.js new file mode 100644 index 0000000..da3b718 --- /dev/null +++ b/lib/plugins/rplsaslsuccess.js @@ -0,0 +1,17 @@ +/** + * RPL_SASLSUCCESS plugin to emit "saslsuccess" events. + * + * @return {Function} + * @api public + */ + +module.exports = function () { + return function (irc) { + irc.on('data', function (msg) { + if ('903' != msg.command && 'RPL_SASLSUCCESS' != msg.command) return; + var e = {}; + e.message = msg.trailing; + irc.emit('saslsuccess', e); + }); + } +}; diff --git a/test/authenticate.js b/test/authenticate.js new file mode 100644 index 0000000..d056e25 --- /dev/null +++ b/test/authenticate.js @@ -0,0 +1,22 @@ +var irc = require('..'); +var Stream = require('stream').PassThrough; + +describe('authenticate()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + describe('on AUTHENTICATE', function () { + it('should emit "AUTHENTICATE"', function (done) { + client.on('authenticate', function (e) { + e.message.should.equal('+') + done(); + }); + + stream.write('AUTHENTICATE +\r\n'); + }); + }); +}); diff --git a/test/away.js b/test/away.js index 724ebf2..8882424 100644 --- a/test/away.js +++ b/test/away.js @@ -1,21 +1,25 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('away()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); - }); - describe('on RPL_AWAY', function () { - it('should emit "away"', function (done) { - client.on('away', function (e) { - e.nick.should.equal('colinm'); - e.message.should.eql('brb food time'); - done(); - }); - stream.write(':irc.host.net 301 me colinm :brb food time\r\n'); - }); +describe('away()', function() { + var stream, client; + + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + + describe('on RPL_AWAY', function() { + it('should emit "away"', function(done) { + client.on('away', function(e) { + e.nick.should.equal('colinm'); + e.message.should.eql('brb food time'); + done(); + }); + + stream.write(':irc.host.net 301 me colinm :brb food time\r\n'); }); + }); }); diff --git a/test/cap.js b/test/cap.js new file mode 100644 index 0000000..58710cd --- /dev/null +++ b/test/cap.js @@ -0,0 +1,46 @@ +var irc = require('..'); +var Stream = require('stream').PassThrough; + +describe('cap()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + describe('on CAP', function () { + it('should emit "CAP" and parse ACK with capabilities', function (done) { + client.on('cap', function (e) { + e.nick.should.equal('jilles'); + e.command.should.eql('ACK'); + e.should.have.property('capabilities').with.lengthOf(1); + e.capabilities[0].should.eql('sasl'); + done(); + }); + + stream.write(':jaguar.test CAP jilles ACK :sasl\r\n'); + }); + it('should emit "CAP" and parse ACK with multiple capabilities', function (done) { + client.on('cap', function (e) { + e.nick.should.equal('jilles'); + e.command.should.eql('ACK'); + e.should.have.property('capabilities').with.lengthOf(3); + done(); + }); + + stream.write(':jaguar.test CAP jilles ACK :sasl foo bar\r\n'); + }); + it('should emit "CAP" and parse LS with capabilites', function (done) { + client.on('cap', function (e) { + e.nick.should.eql('*'); + e.command.should.eql('LS'); + e.should.have.property('capabilities').with.lengthOf(2); + e.capabilities.should.containDeep(['multi-prefix', 'sasl']); + done(); + }); + + stream.write(':jaguar.test CAP * LS :multi-prefix sasl\r\n'); + }); + }); +}); diff --git a/test/invite.js b/test/invite.js index 4afdd47..8652a52 100644 --- a/test/invite.js +++ b/test/invite.js @@ -1,26 +1,30 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('invite()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); - }); - describe('on INVITE', function () { - it('should emit "invite"', function (done) { - client.on('invite', function (e) { - e.from.should.equal('test'); - e.to.should.equal('astranger'); - e.channel.should.equal('#something'); - e.hostmask.nick.should.equal('test'); - e.hostmask.username.should.equal('~user'); - e.hostmask.hostname.should.equal('example.com'); - e.hostmask.string.should.equal('test!~user@example.com'); - done(); - }); - stream.write(':test!~user@example.com INVITE astranger :#something\r\n'); - }); +describe('invite()', function() { + var stream, client; + + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + + describe('on INVITE', function() { + it('should emit "invite"', function(done) { + client.on('invite', function(e) { + e.from.should.equal('test'); + e.to.should.equal('astranger'); + e.channel.should.equal('#something'); + e.hostmask.nick.should.equal('test'); + e.hostmask.username.should.equal('~user'); + e.hostmask.hostname.should.equal('example.com'); + e.hostmask.string.should.equal('test!~user@example.com'); + done(); + }); + + stream.write(':test!~user@example.com INVITE astranger :#something\r\n'); }); + }); }); diff --git a/test/join.js b/test/join.js index 12d0522..07b9ac4 100644 --- a/test/join.js +++ b/test/join.js @@ -1,25 +1,29 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('join()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); - }); - describe('on JOIN', function () { - it('should emit "join"', function (done) { - client.on('join', function (e) { - e.nick.should.equal('tjholowaychuk'); - e.channel.should.equal('#express'); - e.hostmask.nick.should.equal('tjholowaychuk'); - e.hostmask.username.should.equal('~tjholoway'); - e.hostmask.hostname.should.equal('S01067cb21b2fd643.gv.shawcable.net'); - e.hostmask.string.should.equal('tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net'); - done(); - }); - stream.write(':tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net JOIN #express\r\n'); - }); +describe('join()', function() { + var stream, client; + + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + + describe('on JOIN', function() { + it('should emit "join"', function(done) { + client.on('join', function(e) { + e.nick.should.equal('tjholowaychuk'); + e.channel.should.equal('#express'); + e.hostmask.nick.should.equal('tjholowaychuk'); + e.hostmask.username.should.equal('~tjholoway'); + e.hostmask.hostname.should.equal('S01067cb21b2fd643.gv.shawcable.net'); + e.hostmask.string.should.equal('tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net'); + done(); + }); + + stream.write(':tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net JOIN #express\r\n'); }); + }); }); diff --git a/test/kick.js b/test/kick.js index d418f05..46fd1d1 100644 --- a/test/kick.js +++ b/test/kick.js @@ -1,26 +1,30 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('kick()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); - }); - describe('on KICK', function () { - it('should emit "kick"', function (done) { - client.on('kick', function (e) { - e.nick.should.equal('tjholowaychuk'); - e.client.should.equal('tobi'); - e.channel.should.eql('#express'); - e.hostmask.nick.should.equal('tjholowaychuk'); - e.hostmask.username.should.equal('~tjholoway'); - e.hostmask.hostname.should.equal('S01067cb21b2fd643.gv.shawcable.net'); - e.hostmask.string.should.equal('tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net'); - done(); - }); - stream.write(':tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net KICK #express tobi :Too ferrety\r\n'); - }); +describe('kick()', function() { + var stream, client; + + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + + describe('on KICK', function() { + it('should emit "kick"', function(done) { + client.on('kick', function(e) { + e.nick.should.equal('tjholowaychuk'); + e.client.should.equal('tobi'); + e.channel.should.eql('#express'); + e.hostmask.nick.should.equal('tjholowaychuk'); + e.hostmask.username.should.equal('~tjholoway'); + e.hostmask.hostname.should.equal('S01067cb21b2fd643.gv.shawcable.net'); + e.hostmask.string.should.equal('tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net'); + done(); + }); + + stream.write(':tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net KICK #express tobi :Too ferrety\r\n'); }); + }); }); diff --git a/test/names.js b/test/names.js index 84ae399..d47a3fc 100644 --- a/test/names.js +++ b/test/names.js @@ -1,71 +1,74 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('names()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); - }); - describe('client.names(chan, fn)', function () { - it('should respond with user names', function (done) { - client.names('#luna-lang', function (err, names) { - if (err) return done(err); - names.should.eql([ - {name: 'owner', mode: '~'}, - {name: 'foo', mode: '@'}, - {name: 'halfop', mode: '%'}, - {name: 'bar', mode: '+'}, - {name: 'baz', mode: ''}, - {name: 'some', mode: ''}, - {name: 'more', mode: ''} - ]); - done(); - }); +describe('names()', function() { + var stream, client; - setImmediate(function () { - stream.write(':pratchett.freenode.net 353 tjholowaychuk = #luna-lang :~owner @foo %halfop +bar baz\r\n'); - stream.write(':pratchett.freenode.net 353 tjholowaychuk = #luna-lang :some more\r\n'); - stream.write(':pratchett.freenode.net 366 tjholowaychuk #luna-lang :End of /NAMES list.\r\n'); - }); - }); - }); + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); - it('should emit "names"', function (done) { - client.on('names', function (e) { - e.channel.should.equal('#luna-lang'); - e.names.should.eql([ - {name: 'one', mode: ''}, - {name: 'two', mode: '~'}, - {name: 'three', mode: ''}, - {name: 'foo', mode: '@'}, - {name: 'bar', mode: '@'}, - {name: 'baz', mode: '%'} - ]); - done(); - }); + describe('client.names(chan, fn)', function() { + it('should respond with user names', function(done) { + client.names('#luna-lang', function(err, names) { + if (err) return done(err); + names.should.eql([ + {name: 'owner', mode: '~'}, + {name: 'foo', mode: '@'}, + {name: 'halfop', mode: '%'}, + {name: 'bar', mode: '+'}, + {name: 'baz', mode: ''}, + {name: 'some', mode: ''}, + {name: 'more', mode: ''} + ]); + done(); + }); - stream.write(':tobi!~tobi@184.151.231.170 JOIN #luna-lang\r\n'); - stream.write(':rothfuss.freenode.net 353 tjholowaychuk = #luna-lang :one ~two three\r\n'); - stream.write(':rothfuss.freenode.net 353 tjholowaychuk = #luna-lang :@foo @bar %baz\r\n'); - stream.write(':rothfuss.freenode.net 366 tjholowaychuk #luna-lang :End of /NAMES list.\r\n'); + setImmediate(function() { + stream.write(':pratchett.freenode.net 353 tjholowaychuk = #luna-lang :~owner @foo %halfop +bar baz\r\n'); + stream.write(':pratchett.freenode.net 353 tjholowaychuk = #luna-lang :some more\r\n'); + stream.write(':pratchett.freenode.net 366 tjholowaychuk #luna-lang :End of /NAMES list.\r\n'); + }); }); + }); - it('should retain ~ / @ / % / +', function (done) { - client.on('names', function (e) { - e.channel.should.equal('##luna-lang'); - e.names.should.eql([ - {name: 'owner', mode: '~'}, - {name: 'tjholowaychuk', mode: '@'}, - {name: 'halfop', mode: '%'}, - {name: 'tobi', mode: '+'} - ]); - done(); - }); + it('should emit "names"', function(done) { + client.on('names', function(e) { + e.channel.should.equal('#luna-lang'); + e.names.should.eql([ + {name: 'one', mode: ''}, + {name: 'two', mode: '~'}, + {name: 'three', mode: ''}, + {name: 'foo', mode: '@'}, + {name: 'bar', mode: '@'}, + {name: 'baz', mode: '%'} + ]); + done(); + }); - stream.write(':tobi!~tobi@184.151.231.170 JOIN #luna-lang\r\n'); - stream.write(':rothfuss.freenode.net 353 tjholowaychuk @ ##luna-lang :~owner @tjholowaychuk %halfop +tobi\r\n'); - stream.write(':rothfuss.freenode.net 366 tjholowaychuk ##luna-lang :End of /NAMES list.\r\n'); + stream.write(':tobi!~tobi@184.151.231.170 JOIN #luna-lang\r\n'); + stream.write(':rothfuss.freenode.net 353 tjholowaychuk = #luna-lang :one ~two three\r\n'); + stream.write(':rothfuss.freenode.net 353 tjholowaychuk = #luna-lang :@foo @bar %baz\r\n'); + stream.write(':rothfuss.freenode.net 366 tjholowaychuk #luna-lang :End of /NAMES list.\r\n'); + }); + + it('should retain ~ / @ / % / +', function(done) { + client.on('names', function(e) { + e.channel.should.equal('##luna-lang'); + e.names.should.eql([ + {name: 'owner', mode: '~'}, + {name: 'tjholowaychuk', mode: '@'}, + {name: 'halfop', mode: '%'}, + {name: 'tobi', mode: '+'} + ]); + done(); }); -}); \ No newline at end of file + + stream.write(':tobi!~tobi@184.151.231.170 JOIN #luna-lang\r\n'); + stream.write(':rothfuss.freenode.net 353 tjholowaychuk @ ##luna-lang :~owner @tjholowaychuk %halfop +tobi\r\n'); + stream.write(':rothfuss.freenode.net 366 tjholowaychuk ##luna-lang :End of /NAMES list.\r\n'); + }); +}); diff --git a/test/nick.js b/test/nick.js index 325bfec..b0efb7d 100644 --- a/test/nick.js +++ b/test/nick.js @@ -1,26 +1,29 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('nick()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); - }); - describe('on NICK', function () { - it('should emit "nick"', function (done) { - client.on('nick', function (e) { - e.nick.should.eql('colinm'); - e.new.should.equal('cmilhench'); - e.hostmask.nick.should.equal('colinm'); - e.hostmask.username.should.equal('~colinm'); - e.hostmask.hostname.should.equal('host-92-17-247-88.as13285.net'); - e.hostmask.string.should.equal('colinm!~colinm@host-92-17-247-88.as13285.net'); - done(); - }); +describe('nick()', function() { + var stream, client; + + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + + describe('on NICK', function() { + it('should emit "nick"', function(done) { + client.on('nick', function(e) { + e.nick.should.eql('colinm'); + e.new.should.equal('cmilhench'); + e.hostmask.nick.should.equal('colinm'); + e.hostmask.username.should.equal('~colinm'); + e.hostmask.hostname.should.equal('host-92-17-247-88.as13285.net'); + e.hostmask.string.should.equal('colinm!~colinm@host-92-17-247-88.as13285.net'); + done(); + }); - stream.write(':colinm!~colinm@host-92-17-247-88.as13285.net NICK :cmilhench\r\n'); - }); + stream.write(':colinm!~colinm@host-92-17-247-88.as13285.net NICK :cmilhench\r\n'); }); + }); }); diff --git a/test/notice.js b/test/notice.js index 0b32247..e022982 100644 --- a/test/notice.js +++ b/test/notice.js @@ -1,48 +1,53 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('notice()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); - }); - describe('on NOTICE', function () { - it('should emit "notice"', function (done) { - var n = 0; - client.on('notice', function(e) { - e.from.should.equal('NickServ'); - e.to.should.equal('cmilhench'); - e.hostmask.nick.should.equal('NickServ'); - e.hostmask.username.should.equal('NickServ'); - e.hostmask.hostname.should.equal('services.'); - e.hostmask.string.should.equal('NickServ!NickServ@services.'); - switch (++n) { - case 1: - e.message.should.equal([ - 'This nickname is registered. ', - 'Please choose a different nickname, ', - 'or identify via /msg NickServ identify .'].join('')); - break; - case 2: - e.message.should.equal([ - 'You have 30 seconds to identify to your nickname ', - 'before it is changed.'].join('')); - done(); - break; - } - }); +describe('notice()', function() { + + var stream, client; + + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + + describe('on NOTICE', function() { + it('should emit "notice"', function(done) { + var n = 0; + + client.on('notice', function(e) { + e.from.should.equal('NickServ'); + e.to.should.equal('cmilhench'); + e.hostmask.nick.should.equal('NickServ'); + e.hostmask.username.should.equal('NickServ'); + e.hostmask.hostname.should.equal('services.'); + e.hostmask.string.should.equal('NickServ!NickServ@services.'); + switch (++n) { + case 1: + e.message.should.equal([ + 'This nickname is registered. ', + 'Please choose a different nickname, ', + 'or identify via /msg NickServ identify .'].join('')); + break; + case 2: + e.message.should.equal([ + 'You have 30 seconds to identify to your nickname ', + 'before it is changed.'].join('')); + done(); + break; + } + }); - stream.write([ - ':NickServ!NickServ@services. NOTICE cmilhench :', - 'This nickname is registered. ', - 'Please choose a different nickname, ', - 'or identify via /msg NickServ identify .\r\n'].join('')); - stream.write([ - ':NickServ!NickServ@services. NOTICE cmilhench :', - 'You have 30 seconds to identify to your nickname ', - 'before it is changed.\r\n'].join('')); - }); + stream.write([ + ':NickServ!NickServ@services. NOTICE cmilhench :', + 'This nickname is registered. ', + 'Please choose a different nickname, ', + 'or identify via /msg NickServ identify .\r\n'].join('')); + stream.write([ + ':NickServ!NickServ@services. NOTICE cmilhench :', + 'You have 30 seconds to identify to your nickname ', + 'before it is changed.\r\n'].join('')); }); + }); }); diff --git a/test/part.js b/test/part.js index aed7a93..db766e8 100644 --- a/test/part.js +++ b/test/part.js @@ -1,26 +1,30 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('part()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); - }); - describe('on PART', function () { - it('should emit "part"', function (done) { - client.on('part', function (e) { - e.nick.should.equal('tjholowaychuk'); - e.channels.should.eql(['#express']); - e.message.should.equal('So long!'); - e.hostmask.nick.should.equal('tjholowaychuk'); - e.hostmask.username.should.equal('~tjholoway'); - e.hostmask.hostname.should.equal('S01067cb21b2fd643.gv.shawcable.net'); - e.hostmask.string.should.equal('tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net'); - done(); - }); - stream.write(':tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net PART #express :So long!\r\n'); - }); +describe('part()', function() { + var stream, client; + + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + + describe('on PART', function() { + it('should emit "part"', function(done) { + client.on('part', function(e) { + e.nick.should.equal('tjholowaychuk'); + e.channels.should.eql(['#express']); + e.message.should.equal('So long!'); + e.hostmask.nick.should.equal('tjholowaychuk'); + e.hostmask.username.should.equal('~tjholoway'); + e.hostmask.hostname.should.equal('S01067cb21b2fd643.gv.shawcable.net'); + e.hostmask.string.should.equal('tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net'); + done(); + }); + + stream.write(':tjholowaychuk!~tjholoway@S01067cb21b2fd643.gv.shawcable.net PART #express :So long!\r\n'); }); + }); }); diff --git a/test/pong.js b/test/pong.js index 477c1c1..243c0af 100644 --- a/test/pong.js +++ b/test/pong.js @@ -1,28 +1,33 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('pong()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); - }); - describe('on PING', function () { - it('should respond with PONG', function (done) { - var n = 0; - stream.on('data', function(chunk) { - switch (n++) { - case 0: - chunk.should.equal('PING :rothfuss.freenode.net\r\n'); - break; - case 1: - chunk.should.equal('PONG :rothfuss.freenode.net\r\n'); - done(); - break; - } - }); - stream.write('PING :rothfuss.freenode.net\r\n'); - }); +describe('pong()', function() { + var stream, client; + + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + + describe('on PING', function() { + it('should respond with PONG', function(done) { + var n = 0; + + stream.on('data', function(chunk) { + switch (n++) { + case 0: + chunk.should.equal('PING :rothfuss.freenode.net\r\n'); + break; + case 1: + chunk.should.equal('PONG :rothfuss.freenode.net\r\n'); + done(); + break; + } + }); + + stream.write('PING :rothfuss.freenode.net\r\n'); }); + }); }); diff --git a/test/privmsg.js b/test/privmsg.js index f4b1fae..2dc615e 100644 --- a/test/privmsg.js +++ b/test/privmsg.js @@ -1,27 +1,30 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('privmsg()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); - }); - describe('on PRIVMSG', function () { - it('should emit "message"', function (done) { - client.on('message', function (e) { - e.from.should.equal('tobi'); - e.to.should.equal('loki'); - e.message.should.equal('Hello :)'); - e.hostmask.nick.should.equal('tobi'); - e.hostmask.username.should.equal('~user'); - e.hostmask.hostname.should.equal('example.com'); - e.hostmask.string.should.equal('tobi!~user@example.com'); - done(); - }); +describe('privmsg()', function() { + var stream, client; + + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + + describe('on PRIVMSG', function() { + it('should emit "message"', function(done) { + client.on('message', function(e) { + e.from.should.equal('tobi'); + e.to.should.equal('loki'); + e.message.should.equal('Hello :)'); + e.hostmask.nick.should.equal('tobi'); + e.hostmask.username.should.equal('~user'); + e.hostmask.hostname.should.equal('example.com'); + e.hostmask.string.should.equal('tobi!~user@example.com'); + done(); + }); - stream.write(':tobi!~user@example.com PRIVMSG loki :Hello :)\r\n'); - }); + stream.write(':tobi!~user@example.com PRIVMSG loki :Hello :)\r\n'); }); + }); }); diff --git a/test/quit.js b/test/quit.js index 9ad0b98..5a62ffa 100644 --- a/test/quit.js +++ b/test/quit.js @@ -1,26 +1,29 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('quit()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); - }); - describe('on QUIT', function () { - it('should emit "quit"', function (done) { - client.on('quit', function (e) { - e.nick.should.equal('tobi'); - e.message.should.eql('Remote host closed the connection'); - e.hostmask.nick.should.equal('tobi'); - e.hostmask.username.should.equal('~tobi'); - e.hostmask.hostname.should.equal('107-214-168-243.lightspeed.cicril.sbcglobal.net'); - e.hostmask.string.should.equal('tobi!~tobi@107-214-168-243.lightspeed.cicril.sbcglobal.net'); - done(); - }); +describe('quit()', function() { + var stream, client; + + beforeEach(function() { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + + describe('on QUIT', function() { + it('should emit "quit"', function(done) { + client.on('quit', function(e) { + e.nick.should.equal('tobi'); + e.message.should.eql('Remote host closed the connection'); + e.hostmask.nick.should.equal('tobi'); + e.hostmask.username.should.equal('~tobi'); + e.hostmask.hostname.should.equal('107-214-168-243.lightspeed.cicril.sbcglobal.net'); + e.hostmask.string.should.equal('tobi!~tobi@107-214-168-243.lightspeed.cicril.sbcglobal.net'); + done(); + }); - stream.write(':tobi!~tobi@107-214-168-243.lightspeed.cicril.sbcglobal.net QUIT :Remote host closed the connection\r\n'); - }); + stream.write(':tobi!~tobi@107-214-168-243.lightspeed.cicril.sbcglobal.net QUIT :Remote host closed the connection\r\n'); }); + }); }); diff --git a/test/rplloggedin.js b/test/rplloggedin.js new file mode 100644 index 0000000..8034b78 --- /dev/null +++ b/test/rplloggedin.js @@ -0,0 +1,22 @@ +var irc = require('..'); +var Stream = require('stream').PassThrough; + +describe('rplloggedin()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + describe('on successful login with sasl', function () { + it('should emit "LOGGEDIN"', function (done) { + client.on('loggedin', function (e) { + e.message.should.equal('You are now logged in as jilles'); + done(); + }); + + stream.write(':jaguar.test 900 jilles jilles!jilles@localhost.stack.nl jilles :You are now logged in as jilles\r\n'); + }); + }); +}); diff --git a/test/rplsaslsuccess.js b/test/rplsaslsuccess.js new file mode 100644 index 0000000..8773971 --- /dev/null +++ b/test/rplsaslsuccess.js @@ -0,0 +1,22 @@ +var irc = require('..'); +var Stream = require('stream').PassThrough; + +describe('rplsaslsuccess()', function () { + var stream, client; + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + describe('on successful login with sasl', function () { + it('should emit "SASLSUCCESS"', function (done) { + client.on('saslsuccess', function (e) { + e.message.should.equal('SASL authentication successful'); + done(); + }); + + stream.write(':jaguar.test 903 jilles :SASL authentication successful\r\n'); + }); + }); +}); diff --git a/test/topic.js b/test/topic.js index 97ce8ee..61e742b 100644 --- a/test/topic.js +++ b/test/topic.js @@ -1,27 +1,30 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('topic()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); - }); - describe('on TOPIC', function () { - it('should emit "topic"', function (done) { - client.on('topic', function (e) { - e.nick.should.equal('tobi'); - e.channel.should.eql('#slate'); - e.topic.should.equal('Slate 1.0 is out!'); - e.hostmask.nick.should.equal('tobi'); - e.hostmask.username.should.equal('~user'); - e.hostmask.hostname.should.equal('example.com'); - e.hostmask.string.should.equal('tobi!~user@example.com'); - done(); - }); +describe('topic()', function() { + var stream, client; + + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + + describe('on TOPIC', function() { + it('should emit "topic"', function(done) { + client.on('topic', function(e) { + e.nick.should.equal('tobi'); + e.channel.should.eql('#slate'); + e.topic.should.equal('Slate 1.0 is out!'); + e.hostmask.nick.should.equal('tobi'); + e.hostmask.username.should.equal('~user'); + e.hostmask.hostname.should.equal('example.com'); + e.hostmask.string.should.equal('tobi!~user@example.com'); + done(); + }); - stream.write(':tobi!~user@example.com TOPIC #slate :Slate 1.0 is out!\r\n'); - }); + stream.write(':tobi!~user@example.com TOPIC #slate :Slate 1.0 is out!\r\n'); }); + }); }); diff --git a/test/welcome.js b/test/welcome.js index acbebf4..6dbc5e3 100644 --- a/test/welcome.js +++ b/test/welcome.js @@ -1,28 +1,31 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('welcome()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); +describe('welcome()', function() { + var stream, client; + + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + + describe('on RPL_WELCOME', function() { + it('should set client.me to the users nick', function() { + stream.write(':cameron.freenode.net 001 tobi :Welcome to the freenode Internet Relay Chat Network tobi\r\n'); + process.nextTick(function() { + client.me.should.equal('tobi'); + }); }); - describe('on RPL_WELCOME', function () { - it('should set client.me to the users nick', function () { - stream.write(':cameron.freenode.net 001 tobi :Welcome to the freenode Internet Relay Chat Network tobi\r\n'); - process.nextTick(function () { - client.me.should.equal('tobi'); - }); - }); - it('should emit "welcome"', function (done) { - client.on('welcome', function (nick) { - nick.should.equal('tobi'); - done(); - }); + it('should emit "welcome"', function(done) { + client.on('welcome', function(nick) { + nick.should.equal('tobi'); + done(); + }); - stream.write(':cameron.freenode.net 001 tobi :Welcome to the freenode Internet Relay Chat Network tobi\r\n'); - }); + stream.write(':cameron.freenode.net 001 tobi :Welcome to the freenode Internet Relay Chat Network tobi\r\n'); }); + }); }); diff --git a/test/whois.js b/test/whois.js index 3e0be54..426e6cd 100644 --- a/test/whois.js +++ b/test/whois.js @@ -1,31 +1,34 @@ var irc = require('..'); var Stream = require('stream').PassThrough; -describe('whois()', function () { - var stream, client; - beforeEach(function () { - stream = new Stream; - stream.setTimeout = function () {}; - client = irc(stream); - }); - describe('client.whois(target, mask, fn)', function () { - it('should respond with user info', function (done) { - client.whois('colinm', function (err, e) { - if (err) return done(err); - e.hostname.should.equal('client.host.net'); - e.username.should.equal('~colinm'); - e.realname.should.equal('Colin Milhench'); - e.server.should.equal('other.host.net'); - e.channels.should.be.instanceof(Array).and.have.lengthOf(4); - e.channels.should.containEql('#Node.js'); - e.channels.should.containEql('#express'); - e.channels.should.containEql('#some'); - e.channels.should.containEql('#more'); - e.away.should.equal('brb'); - e.sign.should.equal('1384330635'); - e.idle.should.equal('10543'); - done(); - }); +describe('whois()', function() { + var stream, client; + + beforeEach(function () { + stream = new Stream; + stream.setTimeout = function () { + }; + client = irc(stream); + }); + + describe('client.whois(target, mask, fn)', function() { + it('should respond with user info', function(done) { + client.whois('colinm', function(err, e) { + if (err) return done(err); + e.hostname.should.equal('client.host.net'); + e.username.should.equal('~colinm'); + e.realname.should.equal('Colin Milhench'); + e.server.should.equal('other.host.net'); + e.channels.should.be.instanceof(Array).and.have.lengthOf(4); + e.channels.should.containEql('#Node.js'); + e.channels.should.containEql('#express'); + e.channels.should.containEql('#some'); + e.channels.should.containEql('#more'); + e.away.should.equal('brb'); + e.sign.should.equal('1384330635'); + e.idle.should.equal('10543'); + done(); + }); stream.write(':irc.host.net 311 me colinm ~colinm client.host.net * :Colin Milhench\r\n'); stream.write(':irc.host.net 319 me colinm :#Node.js #express\r\n'); @@ -38,21 +41,21 @@ describe('whois()', function () { stream.write(':irc.host.net 318 me colinm :End of /WHOIS list.\r\n'); }); - it('should emit "info"', function (done) { - client.on('whois', function (err, e) { - e.hostname.should.equal('client.host.net'); - e.username.should.equal('~colinm'); - e.realname.should.equal('Colin Milhench'); - e.server.should.equal('other.host.net'); - e.channels.should.be.instanceof(Array).and.have.lengthOf(4); - e.channels.should.containEql('#Node.js'); - e.channels.should.containEql('#express'); - e.channels.should.containEql('#some'); - e.channels.should.containEql('#more'); - e.sign.should.equal('1384330635'); - e.idle.should.equal('10543'); - done(); - }); + it('should emit "info"', function(done) { + client.on('whois', function(err, e) { + e.hostname.should.equal('client.host.net'); + e.username.should.equal('~colinm'); + e.realname.should.equal('Colin Milhench'); + e.server.should.equal('other.host.net'); + e.channels.should.be.instanceof(Array).and.have.lengthOf(4); + e.channels.should.containEql('#Node.js'); + e.channels.should.containEql('#express'); + e.channels.should.containEql('#some'); + e.channels.should.containEql('#more'); + e.sign.should.equal('1384330635'); + e.idle.should.equal('10543'); + done(); + }); stream.write(':irc.host.net 311 me colinm ~colinm client.host.net * :Colin Milhench\r\n'); stream.write(':irc.host.net 319 me colinm :#Node.js #express\r\n'); @@ -65,8 +68,8 @@ describe('whois()', function () { }); - it('should emit "info"', function (done) { - client.whois('colinm'); + it('should emit "info"', function(done) { + client.whois('colinm'); client.on('whois', function(err, e) { e.hostname.should.equal('client.host.net'); @@ -93,30 +96,30 @@ describe('whois()', function () { stream.write(':irc.host.net 318 me colinm :End of /WHOIS list.\r\n'); }); - it('should err with No such nick/channel', function (done) { - client.whois('nonick'); - client.on('whois', function (err, e) { - err.should.equal('No such nick/channel'); - done(); - }); - stream.write(':irc.freenode.net 401 me nonick :No such nick/channel\r\n'); - stream.write(':irc.freenode.net 318 me nonick :End of /WHOIS list.\r\n'); - }); + it('should err with No such nick/channel', function(done) { + client.whois('nonick'); + client.on('whois', function(err, e) { + err.should.equal('No such nick/channel'); + done(); + }); + stream.write(':irc.freenode.net 401 me nonick :No such nick/channel\r\n'); + stream.write(':irc.freenode.net 318 me nonick :End of /WHOIS list.\r\n'); + }); - it('should err with No such server', function (done) { - client.whois('nonick', function (err, e) { - err.should.equal('No such server'); - done(); - }); - stream.write(':holmes.freenode.net 402 me nonick :No such server\r\n'); - }); + it('should err with No such server', function(done) { + client.whois('nonick', function(err, e) { + err.should.equal('No such server'); + done(); + }); + stream.write(':holmes.freenode.net 402 me nonick :No such server\r\n'); + }); - it('should err with Not enough parameters', function (done) { - client.on('whois', function (err, e) { - err.should.equal('Not enough parameters'); - done(); - }); - stream.write(':irc.freenode.net 461 me WHOIS :Not enough parameters\r\n'); - }); + it('should err with Not enough parameters', function(done) { + client.on('whois', function(err, e) { + err.should.equal('Not enough parameters'); + done(); + }); + stream.write(':irc.freenode.net 461 me WHOIS :Not enough parameters\r\n'); }); + }); });