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.

28 lines
970 B

  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. })