diff --git a/src/user.js b/src/user.js index 85030e0..5df55bb 100644 --- a/src/user.js +++ b/src/user.js @@ -38,8 +38,8 @@ function User(socket, authenticatedDefault) { } - this.sendMsg = function (from, message) { - this.sendRaw(`:${from.nickname} PRIVMSG ${this.nickname} :${message}`, "ascii") + this.sendMsg = function (from, message, to = this.nickname) { + this.sendRaw(`:${from.nickname} PRIVMSG ${to} :${message}`, "ascii") } this.sendRaw = function(message) { this.connection.write(`${message}\r\n`, "ascii") diff --git a/test/user.js b/test/user.js index 35dc96b..19008ae 100644 --- a/test/user.js +++ b/test/user.js @@ -16,8 +16,8 @@ describe('User', function () { }) }) - describe('#sendMsg(from, message)', function() { - it("should send a message to the user's socket", function (done) { + 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() @@ -27,6 +27,17 @@ describe('User', function () { 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() {