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
1.1 KiB

  1. const assert = require('assert');
  2. const EventEmitter = require('events');
  3. const IRCServer = require("../src/server.js");
  4. describe("JOIN OK", function () {
  5. it("should handle a JOIN command -> JOIN #testchan", function (done) {
  6. const server = IRCServer.create()
  7. let mockedSock = new EventEmitter()
  8. mockedSock.address = function () {
  9. return {port: 12346, family: 'IPv4', address: '127.0.0.1'}
  10. }
  11. mockedSock.write = function (data) {
  12. let answer = data.toString("ascii")
  13. if (answer.indexOf("JOIN") >= 0) {
  14. assert.equal(answer, ":some_nick JOIN #testchan\r\n")
  15. done()
  16. }
  17. }
  18. mockedSock.destroy = function () {
  19. done("Destroyed socket without answering")
  20. }
  21. server.emit("connection", mockedSock)
  22. mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii"))
  23. mockedSock.emit('data', Buffer.from("USER guest tolmoon tolsun :Ronnie Reagan\r\n", "ascii"))
  24. mockedSock.emit('data', Buffer.from("JOIN #testchan\r\n", "ascii"))
  25. })
  26. })