Browse Source

finished command_quit command tests

feature/command_quit
Wayne 5 years ago
parent
commit
53f75858bb
  1. 16
      src/server.js
  2. 11
      src/user.js
  3. 5
      test/command_quit.js

16
src/server.js

@ -63,7 +63,8 @@ server.create = function create() {
socket.write(`001 ${user.nickname} :Welcome to the example IRC Project ${user.nickname}!~${user.username}@${address}`) socket.write(`001 ${user.nickname} :Welcome to the example IRC Project ${user.nickname}!~${user.username}@${address}`)
break; break;
case "QUIT": case "QUIT":
server.closeConnection(user)
server.closeConnection(user.nickname)
break;
default: default:
console.error(`Unknown command: ${command}`); console.error(`Unknown command: ${command}`);
} }
@ -79,17 +80,10 @@ server.create = function create() {
return userlist return userlist
} }
server.getUserObjectFromNickName = function (nickname) {
user_list = server.getUserlist()
if (nickname in user_list)
return user_list[nickname]
}
server.closeConnection = function (user_nickname) { server.closeConnection = function (user_nickname) {
console.log(user_nickname)
userObject = server.getUserObjectFromNickName(user_nickname)
userObject.closeConnection()
delete server.getUserlist()[user_nickname]
let user = userlist[user_nickname]
user.closeConnection()
delete userlist[user_nickname];
} }
return server return server

11
src/user.js

@ -29,19 +29,10 @@ function User(socket) {
this.realname = realname this.realname = realname
} }
this.quit = function (quit_message) {
if (quit_message === undefined)
this.sendMessage("QUIT")
else this.sendMessage(("QUIT :" + quit_message))
}
this.closeConnection = function () { this.closeConnection = function () {
socket.close()
socket.destroy()
} }
this.sendMessage = function (message) {
connection.write(message)
}
} }

5
test/command_quit.js

@ -15,8 +15,11 @@ describe("QUIT OK", function () {
server.emit('connection', mockedSock) server.emit('connection', mockedSock)
mockedSock.emit('data', Buffer.from("NICK nick" + i + "\r\n", "ascii")) mockedSock.emit('data', Buffer.from("NICK nick" + i + "\r\n", "ascii"))
mockedSock.destroy = function () {
done()
} }
console.log(server.getUserlist())
}
server.getUserlist()["nick0"].connection.emit('data', Buffer.from("QUIT :Gone to have lunch\r\n", "ascii"))
}) })
}) })
Loading…
Cancel
Save