diff --git a/src/channel.js b/src/channel.js index cf0eddf..b6cb5ee 100644 --- a/src/channel.js +++ b/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 diff --git a/test/channel.js b/test/channel.js index 68accce..870a640 100644 --- a/test/channel.js +++ b/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") + }) + }) })