You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.2 KiB
62 lines
2.2 KiB
const assert = require('assert');
|
|
const EventEmitter = require('events');
|
|
const IRCServer = require("../src/server.js");
|
|
|
|
describe("NICK OK", function () {
|
|
it("should handle a NICK command -> NICK some_nickname", function () {
|
|
const server = IRCServer.create()
|
|
let mockedSock = new EventEmitter()
|
|
mockedSock.write = function (data) {
|
|
assert.equal(data.toString("ascii"), "001")
|
|
done()
|
|
}
|
|
mockedSock.destroy = function () {
|
|
done("Destroyed socket without answering")
|
|
}
|
|
|
|
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 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()
|
|
}
|
|
mockedSock2.destroy = function () {
|
|
done("Destroyed socket without answering")
|
|
}
|
|
|
|
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 () {
|
|
it("should handle a NICK command -> 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"))
|
|
})
|
|
})
|