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.

54 lines
1.9 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)', function() {
  17. it("should send a message to the user's socket", 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. })
  28. describe('#sendRaw(message)', function() {
  29. it("should send a raw command to the user's socket", function(done) {
  30. let mockedSock = {write: function (data) {
  31. assert.equal(data, ":irc.example.com TEST this :command with parameters\r\n")
  32. done()
  33. }}
  34. const user = new User(mockedSock, true)
  35. user.setNickname("some_nick")
  36. user.register("some_nick")
  37. user.sendRaw(":irc.example.com TEST this :command with parameters")
  38. })
  39. })
  40. describe('#closeConnection()', function() {
  41. it("should call destroy on user's socket", function(done) {
  42. let mockedSock = {destroy: function () {
  43. done()
  44. }}
  45. const user = new User(mockedSock, true)
  46. user.closeConnection()
  47. })
  48. })
  49. })