Wayne
5 years ago
4 changed files with 84 additions and 76 deletions
@ -0,0 +1,12 @@ |
|||
const assert = require('assert'); |
|||
const EventEmitter = require('events'); |
|||
const IRCServer = require("../src/server.js"); |
|||
|
|||
describe('IRC server', function () { |
|||
describe('#create()', function () { |
|||
it("should return a socket server", function () { |
|||
const server = IRCServer.create() |
|||
assert.equal(server.eventNames().toString(), ["connection", "error"].toString()) |
|||
}) |
|||
}) |
|||
}) |
@ -0,0 +1,52 @@ |
|||
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 (done) { |
|||
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")) |
|||
}) |
|||
}) |
|||
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) { |
|||
assert.equal(data.toString("ascii"), "433") |
|||
done() |
|||
} |
|||
mockedSock.destroy = function () { |
|||
done("Destroyed socket without answering") |
|||
} |
|||
|
|||
server.emit("connection", mockedSock) |
|||
mockedSock.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")) |
|||
}) |
|||
}) |
@ -0,0 +1,20 @@ |
|||
const assert = require('assert'); |
|||
const EventEmitter = require('events'); |
|||
const IRCServer = require("../src/server.js"); |
|||
|
|||
describe("on('connection')", function () { |
|||
it("should handle a PING command -> PING irc.example.com", function (done) { |
|||
const server = IRCServer.create() |
|||
let mockedSock = new EventEmitter() |
|||
mockedSock.write = function (data) { |
|||
assert.equal(data.toString("ascii"), "PONG irc.example.com\r\n") |
|||
done() |
|||
} |
|||
mockedSock.destroy = function () { |
|||
done("Destroyed socket without answering") |
|||
} |
|||
|
|||
server.emit("connection", mockedSock) |
|||
mockedSock.emit('data', Buffer.from("PING irc.example.com\r\n", "ascii")) |
|||
}) |
|||
}) |
@ -1,76 +0,0 @@ |
|||
const assert = require('assert'); |
|||
const EventEmitter = require('events'); |
|||
const IRCServer = require("../src/server.js"); |
|||
|
|||
describe('IRC server', function () { |
|||
describe('#create()', function () { |
|||
it("should return a socket server", function () { |
|||
const server = IRCServer.create() |
|||
assert.equal(server.eventNames().toString(), ["connection", "error"].toString()) |
|||
}) |
|||
}) |
|||
describe("on('connection')", function () { |
|||
it("should handle a PING command -> PING irc.example.com", function (done) { |
|||
const server = IRCServer.create() |
|||
let mockedSock = new EventEmitter() |
|||
mockedSock.write = function (data) { |
|||
assert.equal(data.toString("ascii"), "PONG irc.example.com\r\n") |
|||
done() |
|||
} |
|||
mockedSock.destroy = function () { |
|||
done("Destroyed socket without answering") |
|||
} |
|||
|
|||
server.emit("connection", mockedSock) |
|||
mockedSock.emit('data', Buffer.from("PING irc.example.com\r\n", "ascii")) |
|||
}) |
|||
}) |
|||
describe("NICK OK", function () { |
|||
it("should handle a NICK command -> NICK some_nickname", function (done) { |
|||
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")) |
|||
}) |
|||
}) |
|||
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) { |
|||
assert.equal(data.toString("ascii"), "433") |
|||
done() |
|||
} |
|||
mockedSock.destroy = function () { |
|||
done("Destroyed socket without answering") |
|||
} |
|||
|
|||
server.emit("connection", mockedSock) |
|||
mockedSock.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")) |
|||
}) |
|||
}) |
|||
}) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue