|
|
@@ -1,5 +1,7 @@
|
|
|
"use strict";
|
|
|
var assert = require("assert"),
|
|
|
+ async = require("async"),
|
|
|
+ DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource"),
|
|
|
MatchDocumentSource = require("../../../../lib/pipeline/documentSources/MatchDocumentSource");
|
|
|
|
|
|
|
|
|
@@ -26,44 +28,122 @@ module.exports = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- "#accept()": {
|
|
|
+ "#serialize()": {
|
|
|
|
|
|
- "should return true on the input document": function acceptTest(){
|
|
|
- var mds = new MatchDocumentSource({ location : { $in : ['Kentucky'] } }, {});
|
|
|
- assert.strictEqual(mds.accept({ name: 'Adam', location: 'Kentucky'}), true);
|
|
|
+ "should append the match query to the input builder": function sourceToJsonTest(){
|
|
|
+ var mds = new MatchDocumentSource({ location : { $in : ['Kentucky'] } });
|
|
|
+ var t = mds.serialize(false);
|
|
|
+ assert.deepEqual(t, { "$match" : { location : { $in : ['Kentucky'] } }});
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
- "#sourceToJson()": {
|
|
|
+ "#createFromJson()": {
|
|
|
|
|
|
- "should append the match query to the input builder": function sourceToJsonTest(){
|
|
|
- var mds = new MatchDocumentSource({ location : { $in : ['Kentucky'] } });
|
|
|
- var t = {};
|
|
|
- mds.sourceToJson(t, false);
|
|
|
- assert.deepEqual(t, { "$match" : { location : { $in : ['Kentucky'] } }});
|
|
|
+ "should return a new MatchDocumentSource object from an input object": function createTest(){
|
|
|
+ var t = MatchDocumentSource.createFromJson({ someval:{$exists:true} });
|
|
|
+ assert.strictEqual(t instanceof MatchDocumentSource, true);
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
- "#toMatcherJson()": {
|
|
|
+ "#getNext()": {
|
|
|
|
|
|
- "should append the match query to an object suitable for creating a new matcher": function convertTest(){
|
|
|
- var mds = new MatchDocumentSource({ location : { $in : ['Kentucky'] } });
|
|
|
- var t = {};
|
|
|
- mds.toMatcherJson(t);
|
|
|
- assert.deepEqual(t, { location : { $in : ['Kentucky'] } });
|
|
|
- }
|
|
|
+ "should return the current document source": function currSource(next){
|
|
|
+ var mds = new MatchDocumentSource({item: 1});
|
|
|
+ mds.source = {getNext:function(cb){cb(null,{ item:1 });}};
|
|
|
+ mds.getNext(function(err,val) {
|
|
|
+ assert.deepEqual(val, { item:1 });
|
|
|
+ next();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ "should return matched sources remaining": function (next){
|
|
|
+ var mds = new MatchDocumentSource({ item: {$lt: 5} }),
|
|
|
+ items = [ 1,2,3,4,5,6,7,8,9 ];
|
|
|
+ mds.source = {
|
|
|
+ calls: 0,
|
|
|
+ getNext:function(cb) {
|
|
|
+ if (this.calls >= items.length)
|
|
|
+ return cb(null,DocumentSource.EOF);
|
|
|
+ return cb(null,{item: items[this.calls++]});
|
|
|
+ },
|
|
|
+ dispose:function() { return true; }
|
|
|
+ };
|
|
|
+
|
|
|
+ async.series([
|
|
|
+ mds.getNext.bind(mds),
|
|
|
+ mds.getNext.bind(mds),
|
|
|
+ mds.getNext.bind(mds),
|
|
|
+ mds.getNext.bind(mds),
|
|
|
+ mds.getNext.bind(mds),
|
|
|
+ ],
|
|
|
+ function(err,res) {
|
|
|
+ assert.deepEqual([{item:1},{item:2},{item:3},{item:4},DocumentSource.EOF], res);
|
|
|
+ next();
|
|
|
+ }
|
|
|
+ );
|
|
|
+ },
|
|
|
+
|
|
|
+ "should not return matched out documents for sources remaining": function (next){
|
|
|
+ var mds = new MatchDocumentSource({ item: {$gt: 5} }),
|
|
|
+ items = [ 1,2,3,4,5,6,7,8,9 ];
|
|
|
+ mds.source = {
|
|
|
+ calls: 0,
|
|
|
+ getNext:function(cb) {
|
|
|
+ if (this.calls >= items.length)
|
|
|
+ return cb(null,DocumentSource.EOF);
|
|
|
+ return cb(null,{item: items[this.calls++]});
|
|
|
+ },
|
|
|
+ dispose:function() { return true; }
|
|
|
+ };
|
|
|
+
|
|
|
+ async.series([
|
|
|
+ mds.getNext.bind(mds),
|
|
|
+ mds.getNext.bind(mds),
|
|
|
+ mds.getNext.bind(mds),
|
|
|
+ mds.getNext.bind(mds),
|
|
|
+ mds.getNext.bind(mds),
|
|
|
+ ],
|
|
|
+ function(err,res) {
|
|
|
+ assert.deepEqual([{item:6},{item:7},{item:8},{item:9},DocumentSource.EOF], res);
|
|
|
+ next();
|
|
|
+ }
|
|
|
+ );
|
|
|
+ },
|
|
|
+
|
|
|
+ "should return EOF for no sources remaining": function (next){
|
|
|
+ var mds = new MatchDocumentSource({ item: {$gt: 5} }),
|
|
|
+ items = [ ];
|
|
|
+ mds.source = {
|
|
|
+ calls: 0,
|
|
|
+ getNext:function(cb) {
|
|
|
+ if (this.calls >= items.length)
|
|
|
+ return cb(null,DocumentSource.EOF);
|
|
|
+ return cb(null,{item: items[this.calls++]});
|
|
|
+ },
|
|
|
+ dispose:function() { return true; }
|
|
|
+ };
|
|
|
+
|
|
|
+ async.series([
|
|
|
+ mds.getNext.bind(mds),
|
|
|
+ ],
|
|
|
+ function(err,res) {
|
|
|
+ assert.deepEqual([DocumentSource.EOF], res);
|
|
|
+ next();
|
|
|
+ }
|
|
|
+ );
|
|
|
+ },
|
|
|
|
|
|
},
|
|
|
|
|
|
- "#createFromJson()": {
|
|
|
+ "#coalesce()": {
|
|
|
+ },
|
|
|
|
|
|
- "should return a new MatchDocumentSource object from an input object": function createTest(){
|
|
|
- var t = MatchDocumentSource.createFromJson({ someval:{$exists:true} });
|
|
|
- assert.strictEqual(t instanceof MatchDocumentSource, true);
|
|
|
- }
|
|
|
+ "#getQuery()": {
|
|
|
+ },
|
|
|
|
|
|
+ "#redactSafePortion()": {
|
|
|
}
|
|
|
|
|
|
}
|