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.

51 lines
1.8 KiB

  1. const assert = require('assert');
  2. const EventEmitter = require('events');
  3. const IRCServer = require("../src/server.js");
  4. describe("NICK OK", function () {
  5. it("should handle a NICK command -> NICK some_nickname", function (done) {
  6. const server = IRCServer.create()
  7. let mockedSock = new EventEmitter()
  8. mockedSock.write = function (data) {
  9. assert.equal(data.toString("ascii"), "001")
  10. done()
  11. }
  12. mockedSock.destroy = function () {
  13. done("Destroyed socket without answering")
  14. }
  15. server.emit("connection", mockedSock)
  16. mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii"))
  17. })
  18. })
  19. describe("NICK already registered", function () {
  20. it("should handle a NICK command -> NICK some_nickname", function (done) {
  21. const server = IRCServer.create()
  22. let mockedSock = new EventEmitter()
  23. mockedSock.write = function (data) {
  24. assert.equal(data.toString("ascii"), "433")
  25. done()
  26. }
  27. mockedSock.destroy = function () {
  28. done("Destroyed socket without answering")
  29. }
  30. server.emit("connection", mockedSock)
  31. mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii"))
  32. })
  33. })
  34. describe("NICK no NICK given", function () {
  35. it("should handle a NICK command -> NICK ", function (done) {
  36. const server = IRCServer.create()
  37. let mockedSock = new EventEmitter()
  38. mockedSock.write = function (data) {
  39. assert.equal(data.toString("ascii"), "431")
  40. done()
  41. }
  42. mockedSock.destroy = function () {
  43. done("Destroyed socket without answering")
  44. }
  45. server.emit("connection", mockedSock)
  46. mockedSock.emit('data', Buffer.from("NICK \r\n", "ascii"))
  47. })
  48. })