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.

84 lines
3.1 KiB

const assert = require('assert');
const User = require("../src/user.js");
describe('User', function () {
describe('#contructor()', function () {
it("should create a user while no password is required", function () {
let mockedSock = {}
const user = new User(mockedSock, true)
assert.equal(typeof user, 'object')
})
it("should create a user while password is required", function () {
let mockedSock = {}
const user = new User(mockedSock, false)
assert.equal(typeof user, 'object')
})
})
describe('#sendMsg(from, message, to)', function() {
it("should send a message to the user's socket with the user himself as target", function (done) {
let mockedSock = {write: function (data) {
assert.equal(data, ":some_nick PRIVMSG some_nick :test message\r\n")
done()
}}
const user = new User(mockedSock, true)
user.setNickname("some_nick")
user.register("some_nick")
user.sendMsg(user, "test message")
})
it("should send a message to the user's socket with a different target", function (done) {
let mockedSock = {write: function (data) {
assert.equal(data, ":some_nick PRIVMSG #testchan :test message\r\n")
done()
}}
const user = new User(mockedSock, true)
user.setNickname("some_nick")
user.register("some_nick")
user.sendMsg(user, "test message", "#testchan")
})
})
describe('#sendRaw(message)', function() {
it("should send a raw command to the user's socket", function(done) {
let mockedSock = {write: function (data) {
assert.equal(data, ":irc.example.com TEST this :command with parameters\r\n")
done()
}}
const user = new User(mockedSock, true)
user.setNickname("some_nick")
user.register("some_nick")
user.sendRaw(":irc.example.com TEST this :command with parameters")
})
})
describe('#closeConnection()', function() {
it("should call destroy on user's socket", function(done) {
let mockedSock = {destroy: function () {
done()
}}
const user = new User(mockedSock, true)
user.closeConnection()
})
})
describe('#setNickname(nickname)', function() {
it('should not answer on inital setting of nickname', function () {
let mockedSock = {}
const user = new User(mockedSock, true)
user.setNickname("some_nick")
assert.equal(user.getNickname(), "some_nick")
})
it('should answer with NICK message from original nick on rename', function (done) {
let mockedSock = {write: function (data) {
assert.equal(data, ":some_nick NICK changed_nick\r\n")
done()
}}
const user = new User(mockedSock, true)
user.setNickname("some_nick")
user.setNickname("changed_nick")
})
})
})