2 Commits

Author SHA1 Message Date
Jenkins c2a0b891e4 Merge commit '353ca60a003f7545adc2e957e944304726d94a47' into HEAD 5 years ago
Sheogorath 353ca60a00
Fix NICK command behaviour to RFC 5 years ago
  1. 11
      src/user.js
  2. 19
      test/user.js

11
src/user.js

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

19
test/user.js

@ -62,4 +62,23 @@ describe('User', function () {
user.closeConnection() 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