Permalink
Browse files

all tests passing

  • Loading branch information...
1 parent efb26e7 commit 6a59cf5c833cb6a0b67442e8e6a506a2b6f74996 @evantahler evantahler committed Mar 7, 2013
Showing with 69 additions and 73 deletions.
  1. +9 −5 examples/clients/web/actionHeroWebSocket.js
  2. +60 −68 test/client_webSockets.js
@@ -78,7 +78,7 @@
actionHeroWebSocket.prototype.send = function(args, callback){
var self = this;
- if(typeof callback == "function"){
+ if(typeof callback === "function"){
self.messageCount++;
self.callbacks[self.messageCount] = callback;
}
@@ -89,21 +89,21 @@
actionHeroWebSocket.prototype.handleMessage = function(message){
var self = this;
- if(message.context == "response"){
+ if(message.context === "response"){
if(typeof self.callbacks[message.messageCount] === 'function'){
self.callbacks[message.messageCount](message);
}
delete self.callbacks[message.messageCount];
}
- else if(message.context == "user"){
- if(typeof self.events.say == 'function'){
+ else if(message.context === "user"){
+ if(typeof self.events.say === 'function'){
self.events.say(message);
}
}
else{
- if(typeof self.events.alert == 'function'){
+ if(typeof self.events.alert === 'function'){
self.events.alert(message);
}
}
@@ -150,6 +150,10 @@
this.send({event: 'silenceRoom', room: room}, callback);
}
+ actionHeroWebSocket.prototype.disconnect = function(){
+ this.client.disconnect();
+ }
+
exports.actionHeroWebSocket = actionHeroWebSocket;
})(typeof exports === 'undefined' ? window : exports);
View
@@ -60,7 +60,7 @@ describe('Client: Web Sockets', function(){
});
});
- it('Other clients should have been told about people entering the room', function(done){
+ it('socket client connections should work: client 3', function(done){
client_3.connect(function(err, data){
data.should.be.an.instanceOf(Object);
data.context.should.equal("response");
@@ -85,10 +85,10 @@ describe('Client: Web Sockets', function(){
delete client_1.events.say;
response.should.be.an.instanceOf(Object);
response.context.should.equal('user');
- response.message.message.should.equal('hello from client 2');
+ response.message.should.equal('hello from client 2');
done();
}
- client_2.say({message: "hello from client 2"});
+ client_2.say("hello from client 2", function(){}); // TODO: why does this block without a callback?
});
it('can run actions with errors', function(done){
@@ -133,70 +133,62 @@ describe('Client: Web Sockets', function(){
});
- // it('can change rooms and get room details', function(done){
- // client_1.emit("roomChange", {room: "otherRoom"});
- // setTimeout(function(){
- // makeSocketRequest(client_1, "roomView", {}, function(response){
- // response.should.be.an.instanceOf(Object);
- // should.not.exist(response.error);
- // response.room.should.equal("otherRoom")
- // done();
- // });
- // }, 500);
- // });
-
- // it('I can register for messages from rooms I am not in', function(done){
- // this.timeout(5000);
- // makeSocketRequest(client_1, "roomChange", {room: 'room1'}, function(response){
- // makeSocketRequest(client_2, "roomChange", {room: 'room2'}, function(response){
- // makeSocketRequest(client_1, "listenToRoom", {room: 'room2'}, function(response){
- // var listener = function(message){
- // client_1.removeListener('say',listener);
- // message.message.should.eql("hello in room2")
- // done();
- // }
- // setTimeout(function(){
- // client_1.on('say', listener);
- // client_2.emit('say', {message: "hello in room2"});
- // }, 500);
- // });
- // });
- // });
- // });
-
- // it('I can unregister for messages from rooms I am not in', function(done){
- // this.timeout(5000);
- // makeSocketRequest(client_1, "roomChange", {room: 'room1'}, function(response){
- // makeSocketRequest(client_2, "roomChange", {room: 'room2'}, function(response){
- // makeSocketRequest(client_1, "listenToRoom", {room: 'room2'}, function(response){
- // makeSocketRequest(client_1, "silenceRoom", {room: 'room2'}, function(response){
- // var listener = function(response){
- // client_1.removeListener('data',listener);
- // throw new Error("I should not have gotten this message: " + response)
- // done();
- // }
- // setTimeout(function(){
- // client_1.on('say', listener);
- // client_2.emit('say', {message: "hello in room2"});
- // }, 200);
- // setTimeout(function(){
- // client_1.removeListener('say',listener);
- // done(); // yay, I didn't get the message
- // }, 2000);
- // });
- // });
- // });
- // });
- // });
-
- // it('can disconnect', function(done){
- // countWebSocketConnections().should.equal(2);
- // client_1.disconnect();
- // client_2.disconnect();
- // setTimeout(function(){
- // countWebSocketConnections().should.equal(0);
- // done();
- // }, 500);
- // });
+ it('can change rooms and get room details', function(done){
+ client_1.roomChange("otherRoom", function(){
+ client_1.detailsView(function(response){
+ response.should.be.an.instanceOf(Object);
+ should.not.exist(response.error);
+ response.details.room.should.equal("otherRoom")
+ done();
+ });
+ });
+ });
+
+ it('I can register for messages from rooms I am not in; and then unregister', function(done){
+ this.timeout(5000)
+ client_1.roomChange("room1", function(){
+ client_2.roomChange("room2", function(){
+
+ setTimeout(function(){
+ client_1.listenToRoom("room2", function(){
+ client_1.events.say = function(response){
+ delete client_1.events.say;
+ response.should.be.an.instanceOf(Object);
+ response.context.should.equal('user');
+ response.message.should.equal('hello in room2');
+
+ client_1.silenceRoom("room2");
+
+ client_1.events.say = function(response){
+ delete client_1.events.say;
+ throw new Error("I should not have gotten this message: " + response);
+ }
+ setTimeout(function(){
+ delete client_1.events.say;
+ done(); // yay!
+ }, 1000)
+ setTimeout(function(){
+ client_2.say("hello in room2");
+ }, 500);
+
+ }
+ client_2.say("hello in room2");
+ });
+ }, 500);
+
+ });
+ });
+ });
+
+ it('can disconnect', function(done){
+ countWebSocketConnections().should.equal(3);
+ client_1.disconnect();
+ client_2.disconnect();
+ client_3.disconnect();
+ setTimeout(function(){
+ countWebSocketConnections().should.equal(0);
+ done();
+ }, 500);
+ });
});

0 comments on commit 6a59cf5

Please sign in to comment.