Jenkins
5 years ago
4 changed files with 68 additions and 51 deletions
@ -1,28 +0,0 @@ |
|||
const assert = require('assert'); |
|||
const EventEmitter = require('events'); |
|||
const IRCServer = require("../src/server.js"); |
|||
|
|||
describe("PRIVMSG OK", function () { |
|||
it("should handle a PRIVMSG command -> PRIVMSG some_nick :I'm a message", function (done) { |
|||
const server = IRCServer.create() |
|||
let mockedSock = new EventEmitter() |
|||
mockedSock.address = function() { |
|||
return { port: 12346, family: 'IPv4', address: '127.0.0.1' } |
|||
} |
|||
mockedSock.write = function (data) { |
|||
let answer = data.toString("ascii") |
|||
if (answer.indexOf("PRIVMSG") >= 0) { |
|||
assert.equal(answer, ":some_nick PRIVMSG some_nick :I'm a message") |
|||
done() |
|||
} |
|||
} |
|||
mockedSock.destroy = function () { |
|||
done("Destroyed socket without answering") |
|||
} |
|||
|
|||
server.emit("connection", mockedSock) |
|||
mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii")) |
|||
mockedSock.emit('data', Buffer.from("USER guest tolmoon tolsun :Ronnie Reagan\r\n", "ascii")) |
|||
mockedSock.emit('data', Buffer.from("PRIVMSG some_nick :I'm a message\r\n", "ascii")) |
|||
}) |
|||
}) |
@ -0,0 +1,25 @@ |
|||
const assert = require('assert'); |
|||
const EventEmitter = require('events'); |
|||
const IRCServer = require("../src/server.js"); |
|||
|
|||
describe("QUIT OK", function () { |
|||
it("should handle a QUIT command -> QUIT quitmessage", function (done) { |
|||
const server = IRCServer.create() |
|||
|
|||
for (var i = 0; i < 3; i++) { |
|||
|
|||
let mockedSock = new EventEmitter() |
|||
|
|||
mockedSock.write = function (data) { |
|||
} |
|||
|
|||
server.emit('connection', mockedSock) |
|||
mockedSock.emit('data', Buffer.from("NICK nick" + i + "\r\n", "ascii")) |
|||
mockedSock.destroy = function () { |
|||
done() |
|||
} |
|||
} |
|||
server.getUserlist()["nick0"].connection.emit('data', Buffer.from("QUIT :Gone to have lunch\r\n", "ascii")) |
|||
|
|||
}) |
|||
}) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue