sharedb
Version:
JSON OT database backend
41 lines (31 loc) • 950 B
JavaScript
var Backend = require('../lib/backend');
var expect = require('expect.js');
describe('middleware', function() {
beforeEach(function() {
this.backend = new Backend();
});
describe('connect', function() {
it('passes the agent on connect', function() {
var clientId;
this.backend.use('connect', function(request, next) {
clientId = request.agent.clientId;
next();
});
var connection = this.backend.connect();
expect(connection.id).equal(null);
connection.on('connected', function() {
expect(connection.id).equal(clientId);
done();
});
});
it('passing an error on connect stops the client', function(done) {
this.backend.use('connect', function(request, next) {
next({message: 'No good'});
});
var connection = this.backend.connect();
connection.on('stopped', function() {
done();
});
});
});
});