-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from apeiron/tests-for-286
Write a test for setting the hostmask when nick is in use
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var irc = require('../lib/irc'); | ||
var test = require('tape'); | ||
|
||
var MockIrcd = require('./mockircd'); | ||
|
||
test('connect and sets hostmask when nick in use', function(t) { | ||
var client, mock, expected; | ||
|
||
mock = MockIrcd(); | ||
client = new irc.Client('localhost', 'testbot', {debug: true}); | ||
|
||
expected = { | ||
sent: [ | ||
['NICK testbot', 'Client sent NICK message'], | ||
['USER nodebot 8 * :nodeJS IRC client', 'Client sent USER message'], | ||
['NICK testbot1', 'Client sent proper response to 433 nickname in use message'], | ||
['QUIT :node-irc says goodbye', 'Client sent QUIT message'] | ||
], | ||
|
||
received: [ | ||
[':localhost 433 * testbot :Nickname is already in use.\r\n', 'Received nick in use error'], | ||
[':localhost 001 testbot1 :Welcome to the Internet Relay Chat Network testbot\r\n', 'Received welcome message'] | ||
], | ||
clientInfo: [ | ||
['hostmask is as expected after 433'], | ||
['nick is as expected after 433'], | ||
['maxLineLength is as expected after 433'] | ||
] | ||
}; | ||
|
||
t.plan(expected.sent.length + expected.received.length + expected.clientInfo.length); | ||
|
||
mock.server.on('connection', function() { | ||
mock.send(':localhost 433 * testbot :Nickname is already in use.\r\n') | ||
mock.send(':localhost 001 testbot1 :Welcome to the Internet Relay Chat Network testbot\r\n'); | ||
}); | ||
|
||
client.on('registered', function() { | ||
t.equal(mock.outgoing[0], expected.received[0][0], expected.received[0][1]); | ||
t.equal(mock.outgoing[1], expected.received[1][0], expected.received[1][1]); | ||
client.disconnect(function() { | ||
t.equal(client.hostMask, 'testbot', 'hostmask is as expected after 433'); | ||
t.equal(client.nick, 'testbot1', 'nick is as expected after 433'); | ||
t.equal(client.maxLineLength, 482, 'maxLineLength is as expected after 433'); | ||
}); | ||
}); | ||
|
||
mock.on('end', function() { | ||
var msgs = mock.getIncomingMsgs(); | ||
|
||
for (var i = 0; i < msgs.length; i++) { | ||
t.equal(msgs[i], expected.sent[i][0], expected.sent[i][1]); | ||
} | ||
mock.close(); | ||
}); | ||
}); |