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.

84 lines
3.1 KiB

  1. const assert = require('assert');
  2. const User = require("../src/user.js");
  3. describe('User', function () {
  4. describe('#contructor()', function () {
  5. it("should create a user while no password is required", function () {
  6. let mockedSock = {}
  7. const user = new User(mockedSock, true)
  8. assert.equal(typeof user, 'object')
  9. })
  10. it("should create a user while password is required", function () {
  11. let mockedSock = {}
  12. const user = new User(mockedSock, false)
  13. assert.equal(typeof user, 'object')
  14. })
  15. })
  16. describe('#sendMsg(from, message, to)', function() {
  17. it("should send a message to the user's socket with the user himself as target", function (done) {
  18. let mockedSock = {write: function (data) {
  19. assert.equal(data, ":some_nick PRIVMSG some_nick :test message\r\n")
  20. done()
  21. }}
  22. const user = new User(mockedSock, true)
  23. user.setNickname("some_nick")
  24. user.register("some_nick")
  25. user.sendMsg(user, "test message")
  26. })
  27. it("should send a message to the user's socket with a different target", function (done) {
  28. let mockedSock = {write: function (data) {
  29. assert.equal(data, ":some_nick PRIVMSG #testchan :test message\r\n")
  30. done()
  31. }}
  32. const user = new User(mockedSock, true)
  33. user.setNickname("some_nick")
  34. user.register("some_nick")
  35. user.sendMsg(user, "test message", "#testchan")
  36. })
  37. })
  38. describe('#sendRaw(message)', function() {
  39. it("should send a raw command to the user's socket", function(done) {
  40. let mockedSock = {write: function (data) {
  41. assert.equal(data, ":irc.example.com TEST this :command with parameters\r\n")
  42. done()
  43. }}
  44. const user = new User(mockedSock, true)
  45. user.setNickname("some_nick")
  46. user.register("some_nick")
  47. user.sendRaw(":irc.example.com TEST this :command with parameters")
  48. })
  49. })
  50. describe('#closeConnection()', function() {
  51. it("should call destroy on user's socket", function(done) {
  52. let mockedSock = {destroy: function () {
  53. done()
  54. }}
  55. const user = new User(mockedSock, true)
  56. user.closeConnection()
  57. })
  58. })
  59. describe('#setNickname(nickname)', function() {
  60. it('should not answer on inital setting of nickname', function () {
  61. let mockedSock = {}
  62. const user = new User(mockedSock, true)
  63. user.setNickname("some_nick")
  64. assert.equal(user.getNickname(), "some_nick")
  65. })
  66. it('should answer with NICK message from original nick on rename', function (done) {
  67. let mockedSock = {write: function (data) {
  68. assert.equal(data, ":some_nick NICK changed_nick\r\n")
  69. done()
  70. }}
  71. const user = new User(mockedSock, true)
  72. user.setNickname("some_nick")
  73. user.setNickname("changed_nick")
  74. })
  75. })
  76. })