Browse Source

Add basic unit test file for users

After learning today that testing the leaves is more important, some
fixing for the unit test coverage towards users. Time to do better.
test/user
Sheogorath 5 years ago
parent
commit
b55e1cc810
No known key found for this signature in database GPG Key ID: 1F05CC3635CDDFFD
  1. 54
      test/user.js

54
test/user.js

@ -0,0 +1,54 @@
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)', function() {
it("should send a message to the user's socket", 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")
})
})
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()
})
})
})
Loading…
Cancel
Save