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.

59 lines
2.1 KiB

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