From 6a1b20f80ea2aff57dae5e8c59998d139f886778 Mon Sep 17 00:00:00 2001 From: Michelle Bu Date: Sun, 7 Jul 2013 00:21:57 -0700 Subject: [PATCH] More test --- test/server.js | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/test/server.js b/test/server.js index cbcc576..8a04bc5 100644 --- a/test/server.js +++ b/test/server.js @@ -27,6 +27,7 @@ describe('PeerServer', function() { }); describe('#_initializeWSS', function() { + WebSocketServer = sinon.stub(); }); @@ -35,6 +36,42 @@ describe('PeerServer', function() { }); describe('#_checkKey', function() { + var p; + before(function() { + PeerServer.prototype._initializeHTTP = sinon.stub(); + p = new PeerServer({ port: 8000 }); + p._checkKey('peerjs', 'myip', function() {}); + }); + + it('should reject keys that are not the default', function(done) { + p._checkKey('bad key', null, function(response) { + expect(response).to.be('Invalid key provided'); + done(); + }); + }); + + it('should accept valid key/ip pairs', function(done) { + p._checkKey('peerjs', 'myip', function(response) { + expect(response).to.be(null); + done(); + }); + }); + + it('should reject ips that are at their limit', function(done) { + p._options.ip_limit = 0; + p._checkKey('peerjs', 'myip', function(response) { + expect(response).to.be('myip has reached its concurrent user limit'); + done(); + }); + }); + + it('should reject when the server is at its limit', function(done) { + p._options.concurrent_limit = 0; + p._checkKey('peerjs', 'myip', function(response) { + expect(response).to.be('Server has reached its concurrent user limit'); + done(); + }); + }); }); @@ -59,10 +96,18 @@ describe('PeerServer', function() { }); describe('#_handleTransmission', function() { - + // TODO: this is probably the most important method to test. }); describe('#_generateClientId', function() { + var p; + before(function() { + PeerServer.prototype._initializeHTTP = sinon.stub(); + p = new PeerServer({ port: 8000 }); + }); + it('should generate a 16-character ID', function() { + expect(p._generateClientId('anykey').length).to.be(16); + }); }); });