Skip to content

Commit 1e21928

Browse files
committed
Added tests for metadata presence in middleware.
1 parent fd4879c commit 1e21928

File tree

1 file changed

+33
-35
lines changed

1 file changed

+33
-35
lines changed

test/client/submit.js

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,32 +1216,32 @@ module.exports = function() {
12161216
describe('metadata projection', function() {
12171217
it('passed metadata to connect', function(done) {
12181218
var metadata = {username: 'user'};
1219-
1219+
12201220
this.backend.use('connect', function(request, next) {
12211221
Object.assign(request.agent.custom, request.req);
12221222
next();
12231223
});
1224-
1224+
12251225
var connection = this.backend.connect(undefined, metadata);
12261226
connection.on('connected', function() {
12271227
expect(connection.agent.custom).eql(metadata);
12281228
done();
12291229
});
12301230
});
1231-
1231+
12321232
it('passed metadata to submit', function(done) {
12331233
var metadata = {username: 'user'};
1234-
1234+
12351235
this.backend.use('connect', function(request, next) {
12361236
Object.assign(request.agent.custom, request.req);
12371237
next();
12381238
});
1239-
1239+
12401240
this.backend.use('submit', function(request) {
12411241
expect(request.agent.custom).eql(metadata);
12421242
done();
12431243
});
1244-
1244+
12451245
var connection = this.backend.connect(undefined, metadata);
12461246
var doc = null;
12471247
connection.on('connected', function() {
@@ -1252,22 +1252,22 @@ module.exports = function() {
12521252
});
12531253
});
12541254
});
1255-
1255+
12561256
it('received local op without metadata', function(done) {
12571257
var metadata = {username: 'user'};
1258-
1258+
12591259
this.backend.use('connect', function(request, next) {
12601260
Object.assign(request.agent.custom, request.req);
12611261
next();
12621262
});
1263-
1263+
12641264
this.backend.use('submit', function(request, next) {
12651265
expect(request.agent.custom).eql(metadata);
12661266
Object.assign(request.op.m, request.agent.custom);
12671267
request.opMetadataProjection = {username: true};
12681268
next();
12691269
});
1270-
1270+
12711271
var connection = this.backend.connect(undefined, metadata);
12721272
var doc = null;
12731273
connection.on('connected', function() {
@@ -1289,14 +1289,14 @@ module.exports = function() {
12891289
Object.assign(request.agent.custom, request.req);
12901290
next();
12911291
});
1292-
1292+
12931293
this.backend.use('submit', function(request, next) {
12941294
expect(request.agent.custom).to.have.property('username');
12951295
Object.assign(request.op.m, request.agent.custom);
12961296
request.opMetadataProjection = {username: true};
12971297
next();
12981298
});
1299-
1299+
13001300
this.backend.use('apply', function(request, next) {
13011301
expect(request.op.m).to.have.property('username');
13021302
next();
@@ -1311,25 +1311,25 @@ module.exports = function() {
13111311
expect(request.op.m).to.have.property('username');
13121312
next();
13131313
});
1314-
1314+
13151315
var subscriberCount = 10;
13161316
var subscriberOpCount = 10;
1317-
1317+
13181318
var metadatas = [];
13191319
for (var i = 0; i < subscriberCount; i++) {
13201320
metadatas[i] = {username: 'user-'+i};
13211321
}
1322-
1322+
13231323
var ops = [];
13241324
for (var i = 0; i < subscriberCount; i++) {
13251325
ops[i] = [];
13261326
for (var j = 0; j < subscriberOpCount; j++) {
13271327
ops[i].push({p: ['tricks '+i+' '+j], oi: 1});
13281328
}
13291329
}
1330-
1330+
13311331
var docs = [];
1332-
1332+
13331333
function submitOps() {
13341334
for (var j = 0; j < subscriberOpCount; j++) {
13351335
for (var i = 0; i < subscriberCount; i++) {
@@ -1338,7 +1338,7 @@ module.exports = function() {
13381338
}
13391339
}
13401340
}
1341-
1341+
13421342
function validateAndDone() {
13431343
var firstDoc = docs[0];
13441344
// validate that all documents across connections are in sync
@@ -1348,46 +1348,44 @@ module.exports = function() {
13481348
}
13491349
done();
13501350
};
1351-
1351+
13521352
var submitOpsAfter = util.callAfter(subscriberCount - 1, submitOps);
13531353
var doneAfter = util.callAfter((subscriberCount * subscriberCount * subscriberOpCount) - 1, validateAndDone);
1354-
1354+
13551355
function getDoc(callback) {
13561356
var thisDoc = this;
13571357
thisDoc.fetch(function() {
13581358
if (!thisDoc.data) {
1359-
return thisDoc.create({}, function() {
1360-
thisDoc.subscribe(callback);
1361-
});
1362-
}
1363-
thisDoc.subscribe(callback);
1359+
return thisDoc.create({}, function() {
1360+
thisDoc.subscribe(callback);
1361+
});
1362+
}
1363+
thisDoc.subscribe(callback);
13641364
});
13651365
}
1366-
1366+
13671367
for (var i = 0; i < subscriberCount; i++) {
13681368
var metadata = metadatas[i];
1369-
1369+
13701370
var connection = this.backend.connect(undefined, Object.assign({}, metadata));
13711371
connection.__test_metadata = Object.assign({}, metadata);
13721372
connection.__test_id = i;
1373-
1373+
13741374
connection.on('connected', function() {
13751375
var thisConnection = this;
1376-
1376+
13771377
expect(thisConnection.agent.custom).eql(thisConnection.__test_metadata);
1378-
1378+
13791379
thisConnection.doc = docs[thisConnection.__test_id] = thisConnection.get('dogs', 'fido');
1380-
1381-
thisConnection.doc.on('op', function(op, source, src, context) {
1380+
1381+
thisConnection.doc.on('op', function() {
13821382
doneAfter();
13831383
});
1384-
1384+
13851385
getDoc.bind(thisConnection.doc)(submitOpsAfter);
13861386
});
13871387
}
13881388
});
1389-
13901389
});
1391-
13921390
});
13931391
};

0 commit comments

Comments
 (0)