Permalink
Browse files

adding onClose method

  • Loading branch information...
1 parent e2e1aa8 commit 5189c6696be4ac4f8b0942bda30987aa96891a10 @cooperq cooperq committed Feb 3, 2013
Showing with 20 additions and 0 deletions.
  1. +15 −0 test/transactor.js
  2. +5 −0 transactor.js
View
15 test/transactor.js
@@ -1,6 +1,7 @@
var Transactor = require('../transactor');
var EventEmitter = require('events').EventEmitter;
var assert = require('chai').assert;
+var sinon = require('sinon');
describe('Transactor', function(){
var trans, socket;
@@ -104,6 +105,20 @@ describe('Transactor', function(){
setTimeout(done,20);
});
+
+ it('should call transactor.onClose() when the socket is closed', function(done){
+ trans.onClose = sinon.spy();
+ var socket1 = new EventEmitter();
+ trans.addSocket('channel_1',socket1);
+ socket1.emit('close');
+ assert(trans.onClose.calledOnce, 'transactor.onClose() was not called');
+ done();
+ });
+
+ it('should emit an event when onClose is called', function(){
+ //TODO: Figure out how and what we are going to emit for this event
+ });
+
});
});
});
View
5 transactor.js
@@ -31,6 +31,7 @@ Transactor.prototype.addSocket = function(channel,socket){
// add the supplied disconnection handler
socket.on('close', function(){
+ trans.onClose();
delete trans.sockets[channel][socket_id];
});
@@ -43,3 +44,7 @@ Transactor.prototype.broadcast = function(channel,data){
this.sockets[channel][socket_id].write(data);
}
};
+
+Transactor.prototype.onClose = function(){
+
+};

0 comments on commit 5189c66

Please sign in to comment.