瀏覽代碼

More test

Michelle Bu 12 年之前
父節點
當前提交
6a1b20f80e
共有 1 個文件被更改,包括 46 次插入1 次删除
  1. 46 1
      test/server.js

+ 46 - 1
test/server.js

@@ -27,6 +27,7 @@ describe('PeerServer', function() {
   });
   });
 
 
   describe('#_initializeWSS', function() {
   describe('#_initializeWSS', function() {
+    WebSocketServer = sinon.stub();
 
 
   });
   });
 
 
@@ -35,6 +36,42 @@ describe('PeerServer', function() {
   });
   });
 
 
   describe('#_checkKey', 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() {
   describe('#_handleTransmission', function() {
-
+    // TODO: this is probably the most important method to test.
   });
   });
 
 
   describe('#_generateClientId', function() {
   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);
+    });
   });
   });
 });
 });