You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.2 KiB

  1. const assert = require('assert');
  2. const Channel = require("../src/channel.js");
  3. describe('Channel', function () {
  4. describe('#contructor()', function () {
  5. it("should create a channel", function () {
  6. const channel = new Channel("#testchan")
  7. assert.equal(typeof channel, 'object')
  8. })
  9. })
  10. describe('#join(user)', function () {
  11. it("should add the user to a channel and send a JOIN command to the user", function (done) {
  12. const channel = new Channel("#testchan")
  13. let mockedUser = {nickname: "some_nick"}
  14. mockedUser.sendRaw = function(data) {
  15. assert.equal(data, ":some_nick JOIN #testchan")
  16. done()
  17. }
  18. channel.join(mockedUser)
  19. })
  20. })
  21. describe('#part(user)', function () {
  22. it("should remove a user from a channel and send a PART command to the user", function (done) {
  23. const channel = new Channel("#testchan")
  24. let mockedUser = {nickname: "some_nick"}
  25. mockedUser.sendRaw = function(data) {
  26. // we expect a PART message from our user to the channel (including us)
  27. if (data.indexOf("PART") >= 0) {
  28. assert.equal(data, ":some_nick PART #testchan")
  29. done()
  30. }
  31. }
  32. // we can't part a channel without joining it first
  33. channel.join(mockedUser)
  34. channel.part(mockedUser)
  35. })
  36. })
  37. describe('#sendMsg(from, message)', function () {
  38. it("should remove a user from a channel and send a PART command to the user", function (done) {
  39. const channel = new Channel("#testchan")
  40. let mockedUser = {nickname: "some_nick", sendRaw: function() {}}
  41. mockedUser.sendMsg = function(from, message, to) {
  42. assert.equal(from, mockedUser)
  43. assert.equal(message, "test message")
  44. assert.equal(to, "#testchan")
  45. done()
  46. }
  47. // we can't part a channel without joining it first
  48. channel.join(mockedUser)
  49. channel.sendMsg(mockedUser, "test message")
  50. })
  51. })
  52. })