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.
72 lines
3.0 KiB
72 lines
3.0 KiB
const assert = require('assert');
|
|
const EventEmitter = require('events');
|
|
const IRCServer = require("../src/server.js");
|
|
|
|
describe("JOIN OK", function () {
|
|
it("should handle a JOIN command -> JOIN #testchan", 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("JOIN") >= 0) {
|
|
assert.equal(answer, ":some_nick JOIN #testchan\r\n")
|
|
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("JOIN #testchan\r\n", "ascii"))
|
|
})
|
|
|
|
it("should handle a JOIN command for more than one user -> JOIN #testchan and send join events to all channel members", function (done) {
|
|
const server = IRCServer.create()
|
|
// helper to count join messages for channel
|
|
// we should see 2 of them
|
|
let counter = 0
|
|
let mockedSock1 = new EventEmitter()
|
|
mockedSock1.address = function () {
|
|
return {port: 12346, family: 'IPv4', address: '127.0.0.1'}
|
|
}
|
|
mockedSock1.write = function (data) {
|
|
let answer = data.toString("ascii")
|
|
if (answer.indexOf("JOIN") >= 0 && counter === 1) {
|
|
assert.equal(answer, ":other_nick JOIN #testchan\r\n")
|
|
done()
|
|
}
|
|
if (answer === ":some_nick JOIN #testchan\r\n") {
|
|
counter++
|
|
}
|
|
}
|
|
mockedSock1.destroy = function () {
|
|
done("Destroyed socket without answering")
|
|
}
|
|
|
|
let mockedSock2 = new EventEmitter()
|
|
mockedSock2.address = function () {
|
|
return {port: 12346, family: 'IPv4', address: '127.0.0.1'}
|
|
}
|
|
mockedSock2.write = function (data) {
|
|
return
|
|
}
|
|
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"))
|
|
mockedSock1.emit('data', Buffer.from("USER guest tolmoon tolsun :Ronnie Reagan\r\n", "ascii"))
|
|
mockedSock1.emit('data', Buffer.from("JOIN #testchan\r\n", "ascii"))
|
|
mockedSock2.emit('data', Buffer.from("NICK other_nick\r\n", "ascii"))
|
|
mockedSock2.emit('data', Buffer.from("USER guest tolmoon tolsun :Ronnie Reagan\r\n", "ascii"))
|
|
mockedSock2.emit('data', Buffer.from("JOIN #testchan\r\n", "ascii"))
|
|
})
|
|
})
|