|
|
@ -3,7 +3,7 @@ const EventEmitter = require('events'); |
|
|
|
const IRCServer = require("../src/server.js"); |
|
|
|
|
|
|
|
describe("NICK OK", function () { |
|
|
|
it("should handle a NICK command -> NICK some_nickname", function (done) { |
|
|
|
it("should handle a NICK command -> NICK some_nickname", function () { |
|
|
|
const server = IRCServer.create() |
|
|
|
let mockedSock = new EventEmitter() |
|
|
|
mockedSock.write = function (data) { |
|
|
@ -16,22 +16,32 @@ describe("NICK OK", function () { |
|
|
|
|
|
|
|
server.emit("connection", mockedSock) |
|
|
|
mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii")) |
|
|
|
assert.deepEqual(Object.keys(server.getUserlist()), ["some_nick"]); |
|
|
|
}) |
|
|
|
}) |
|
|
|
describe("NICK already registered", function () { |
|
|
|
it("should handle a NICK command -> NICK some_nickname", function (done) { |
|
|
|
const server = IRCServer.create() |
|
|
|
let mockedSock = new EventEmitter() |
|
|
|
mockedSock.write = function (data) { |
|
|
|
let mockedSock1 = new EventEmitter() |
|
|
|
mockedSock1.write = function (data) { |
|
|
|
done("send data to wrong socket") |
|
|
|
} |
|
|
|
mockedSock1.destroy = function () { |
|
|
|
done("Destroyed socket without answering") |
|
|
|
} |
|
|
|
let mockedSock2 = new EventEmitter() |
|
|
|
mockedSock2.write = function (data) { |
|
|
|
assert.equal(data.toString("ascii"), "433") |
|
|
|
done() |
|
|
|
} |
|
|
|
mockedSock.destroy = function () { |
|
|
|
mockedSock2.destroy = function () { |
|
|
|
done("Destroyed socket without answering") |
|
|
|
} |
|
|
|
|
|
|
|
server.emit("connection", mockedSock) |
|
|
|
mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii")) |
|
|
|
server.emit("connection", mockedSock1) |
|
|
|
server.emit("connection", mockedSock2) |
|
|
|
mockedSock1.emit('data', Buffer.from("NICK some_nick\r\n", "ascii")) |
|
|
|
mockedSock2.emit('data', Buffer.from("NICK some_nick\r\n", "ascii")) |
|
|
|
}) |
|
|
|
}) |
|
|
|
describe("NICK no NICK given", function () { |
|
|
@ -49,4 +59,4 @@ describe("NICK no NICK given", function () { |
|
|
|
server.emit("connection", mockedSock) |
|
|
|
mockedSock.emit('data', Buffer.from("NICK \r\n", "ascii")) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |