Browse Source

Add sendMsg function to channel class

This function implements sending messages to all users in a channel
while sending the channel name as target to the user's socket.
feature/sendChannelMsg
Sheogorath 5 years ago
parent
commit
0251dda8ad
No known key found for this signature in database GPG Key ID: 1F05CC3635CDDFFD
  1. 7
      src/channel.js
  2. 17
      test/channel.js

7
src/channel.js

@ -20,6 +20,13 @@ function Channel(name) {
this.userlist.splice(index, 1)
}
}
this.sendMsg = function(from, message) {
const channel = this
this.userlist.forEach(function(item) {
item.sendMsg(from, message, channel.name)
})
}
}
module.exports = Channel

17
test/channel.js

@ -38,4 +38,21 @@ describe('Channel', function () {
channel.part(mockedUser)
})
})
describe('#sendMsg(from, message)', function () {
it("should remove a user from a channel and send a PART command to the user", function (done) {
const channel = new Channel("#testchan")
let mockedUser = {nickname: "some_nick", sendRaw: function() {}}
mockedUser.sendMsg = function(from, message, to) {
assert.equal(from, mockedUser)
assert.equal(message, "test message")
assert.equal(to, "#testchan")
done()
}
// we can't part a channel without joining it first
channel.join(mockedUser)
channel.sendMsg(mockedUser, "test message")
})
})
})
Loading…
Cancel
Save