Compare commits

...

1 Commits

  1. 8
      src/server.js
  2. 15
      test/server.js

8
src/server.js

@ -9,6 +9,7 @@ const ERR_UNKNOWNCOMMAND = '421'
const ERR_ERRONEUSNICKNAME = '432'
const ERR_NICKNAMEINUSE = '433'
const ERR_NEEDMOREPARAMS = '461'
const ERR_NONICKNAMEGIVEN = '431'
let server = {}
let registeredUserlist = require("../src/userlist.js")
@ -29,17 +30,18 @@ server.create = function create() {
if (tokenized[1]) {
let nickname = tokenized[1]
// nick collision test
console.log(Object.keys(registeredUserlist));
if (!Object.keys(registeredUserlist).includes(nickname)) {
user.setNickname(nickname)
registeredUserlist[nickname] = user
socket.write(RPL_WELCOME, " nick " + nickname + " succesfully added.")
socket.write(RPL_WELCOME, " nick " + nickname + " succesfully added.\r\n")
} else {
socket.write(ERR_NICKNAMEINUSE, " nickname in use")
socket.write(ERR_NICKNAMEINUSE, " nickname in use\r\n")
}
} else {
socket.write("ERROR: NO NICKNAME PROVIDED")
socket.write(ERR_NONICKNAMEGIVEN, " :No nickname given\r\n")
}
break;

15
test/server.js

@ -40,5 +40,20 @@ describe('IRC server', function() {
server.emit("connection", mockedSock)
mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii"))
})
it("should send 431 on NICK command with no parameter -> NICK", function (done) {
const server = IRCServer.create()
let mockedSock = new EventEmitter()
mockedSock.write = function (data) {
assert.equal(data.toString("ascii"), "431")
done()
}
mockedSock.destroy = function () {
done("Destroyed socket without answering")
}
server.emit("connection", mockedSock)
mockedSock.emit('data', Buffer.from("NICK\r\n", "ascii"))
})
})
})
Loading…
Cancel
Save