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.

65 lines
2.4 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. })