Tests with _server startup and teardown callbacks

This commit is contained in:
Vsevolod Strukchinsky 2014-04-04 15:07:59 +06:00 committed by lmb
parent 2ce55f8e33
commit eb4f31dabd

View File

@ -14,12 +14,17 @@ describe('PeerServer', function() {
describe('#_checkKey', function() {
var p;
before(function() {
before(function(done) {
PeerServer.prototype._initializeHTTP = sinon.stub();
p = PeerServer({ port: 8000 });
p = PeerServer({ port: 8000 }, done);
p._checkKey('peerjs', 'myip', function() {});
});
after(function(done) {
p._server.close(done);
});
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');
@ -70,9 +75,9 @@ describe('PeerServer', function() {
describe('#_removePeer', function() {
var p;
before(function() {
before(function(done) {
PeerServer.prototype._initializeHTTP = sinon.stub();
p = PeerServer({ port: 8000 });
p = new PeerServer({ port: 8000 }, done);
var fake = {ip: '0.0.0.0'};
p._ips[fake.ip] = 1;
@ -80,6 +85,10 @@ describe('PeerServer', function() {
p._clients['peerjs']['test'] = fake;
});
after(function(done) {
p._server.close(done);
});
it('should decrement the number of ips being used and remove the connection', function() {
expect(p._ips['0.0.0.0']).to.be(1);
p._removePeer('peerjs', 'test');
@ -92,12 +101,16 @@ describe('PeerServer', function() {
var p;
var KEY = 'peerjs';
var ID = 'test';
before(function() {
before(function(done) {
PeerServer.prototype._initializeHTTP = sinon.stub();
p = PeerServer({ port: 8000 });
p = PeerServer({ port: 8000 }, done);
p._clients[KEY] = {};
});
after(function(done) {
p._server.close(done);
});
it('should send to the socket when appropriate', function() {
var send = sinon.spy();
var write = sinon.spy();
@ -177,9 +190,12 @@ describe('PeerServer', function() {
describe('#_generateClientId', function() {
var p;
before(function() {
PeerServer.prototype._initializeHTTP = sinon.stub();
p = PeerServer({ port: 8000 });
before(function(done) {
p = new PeerServer({ port: 8000 }, done);
});
after(function(done) {
p._server.close(done);
});
it('should generate a 16-character ID', function() {