Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abarnhard committed Oct 15, 2014
1 parent fb3da3f commit be063f8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions client/components/factories/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
// console.log(gameInfo);
gameInfo = angular.fromJson(gameInfo);
$localForage.setItem('gameId', gameInfo.gameId).then(function(){
// alerts navbar controller that player has joined a game so it displays the Current Game menu
$rootScope.$broadcast('game-joined', gameInfo.gameId);
$location.path('/game');
});
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ exports.tallyVote = function(data){
};

exports.disconnect = function(){
console.log('user disconnected');
// console.log('user disconnected');
};

// HELPER FUNCTIONS
Expand Down
31 changes: 30 additions & 1 deletion test/acceptance/sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var expect = require('chai').expect,
app = require('../../server/index'),
io = require('socket.io-client'),
request = require('supertest'),
//socketUrl = 'http://192.168.200.201:',
socketUrl = 'http://localhost:',
portFound = false,
options = {transports: ['websocket'], 'force new connection': true};
Expand Down Expand Up @@ -64,6 +63,36 @@ describe('sockets', function(){
});
});

describe('event join-game', function(){
it('should alert everone in game room that another player joined', function(done){
var client1 = io.connect(socketUrl, options),
json1 = '{"gameId":"200000000000000000000001", "player":"bob"}';

client1.on('connect', function(data){

client1.on('player-joined', function(data){
data = JSON.parse(data);
expect(data.player).to.equal('bob');
client1.disconnect();
done();
});

client1.emit('player-connect', json1, function(err, roomId){
var json2 = '{"gameId":"200000000000000000000001", "player":"bob"}',
client2 = io.connect(socketUrl, options);
client2.on('connect', function(data){
client2.emit('join-game', json2, function(err, data){
data = JSON.parse(data);
expect(data.gameId).to.equal('200000000000000000000001');
client2.disconnect();
});
});
});
});

});
});

});

/*
Expand Down

0 comments on commit be063f8

Please sign in to comment.