Browse Source

Merge commit '353ca60a003f7545adc2e957e944304726d94a47' into HEAD

docs/README
Jenkins 5 years ago
parent
commit
c2a0b891e4
  1. 11
      src/user.js
  2. 19
      test/user.js

11
src/user.js

@ -1,12 +1,15 @@
function User(socket, authenticatedDefault) {
this.registered = false
this.authenticated = authenticatedDefault
this.nickname = ""
this.nickname = undefined
this.connection = socket
this.realname = ""
this.username = ""
this.setNickname = function(nickname) {
if (this.nickname !== undefined) {
this.sendRaw(`:${this.nickname} NICK ${nickname}`)
}
this.nickname = nickname
}
@ -26,12 +29,6 @@ function User(socket, authenticatedDefault) {
this.getAddress = function() {
return this.connection.address().address
}
this.setNickname = function (nickname) {
this.nickname = nickname
}
this.setRealName = function (realname) {
this.realname = realname
}
this.closeConnection = function () {
this.connection.destroy()

19
test/user.js

@ -62,4 +62,23 @@ describe('User', function () {
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")
})
})
})
Loading…
Cancel
Save