Browse Source

Merge commit 'ba6a424bfe2e20fa2200ed94087e28e85aa0b955' into HEAD

test/channel
Jenkins 6 years ago
parent
commit
1346da5a1b
  1. 4
      src/user.js
  2. 15
      test/user.js

4
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.sendRaw = function(message) {
this.connection.write(`${message}\r\n`, "ascii") this.connection.write(`${message}\r\n`, "ascii")

15
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) { let mockedSock = {write: function (data) {
assert.equal(data, ":some_nick PRIVMSG some_nick :test message\r\n") assert.equal(data, ":some_nick PRIVMSG some_nick :test message\r\n")
done() done()
@ -27,6 +27,17 @@ describe('User', function () {
user.register("some_nick") user.register("some_nick")
user.sendMsg(user, "test message") 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() { describe('#sendRaw(message)', function() {

Loading…
Cancel
Save