Browse Source

added NICK already registered test

feature/extend_user
Wayne 5 years ago
parent
commit
924f87d634
  1. 30
      test/server.js

30
test/server.js

@ -2,22 +2,22 @@ const assert = require('assert');
const EventEmitter = require('events'); const EventEmitter = require('events');
const IRCServer = require("../src/server.js"); const IRCServer = require("../src/server.js");
describe('IRC server', function() {
describe('#create()', function() {
it("should return a socket server", function() {
describe('IRC server', function () {
describe('#create()', function () {
it("should return a socket server", function () {
const server = IRCServer.create() const server = IRCServer.create()
assert.equal(server.eventNames().toString(), ["connection", "error"].toString()) assert.equal(server.eventNames().toString(), ["connection", "error"].toString())
}) })
}) })
describe("on('connection')", function() {
it("should handle a PING command -> PING irc.example.com", function(done) {
describe("on('connection')", function () {
it("should handle a PING command -> PING irc.example.com", function (done) {
const server = IRCServer.create() const server = IRCServer.create()
let mockedSock = new EventEmitter() let mockedSock = new EventEmitter()
mockedSock.write = function(data) {
mockedSock.write = function (data) {
assert.equal(data.toString("ascii"), "PONG irc.example.com\r\n") assert.equal(data.toString("ascii"), "PONG irc.example.com\r\n")
done() done()
} }
mockedSock.destroy = function() {
mockedSock.destroy = function () {
done("Destroyed socket without answering") done("Destroyed socket without answering")
} }
@ -37,6 +37,22 @@ describe('IRC server', function() {
done("Destroyed socket without answering") 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) server.emit("connection", mockedSock)
mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii")) mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii"))
}) })

Loading…
Cancel
Save