Просмотр исходного кода

EAGLESIX-812: added the rest of the PipelineD test cases and fixed some document sources

Phil Murray 11 лет назад
Родитель
Сommit
1d4a48582d

+ 1 - 1
lib/pipeline/documentSources/LimitDocumentSource.js

@@ -78,7 +78,7 @@ element named $limit.
 klass.createFromJson = function createFromJson(jsonElement, ctx) {
 	if (typeof jsonElement !== "number") throw new Error("code 15957; the limit must be specified as a number");
 	var limit = jsonElement;
-	return this.create(ctx, limit);
+	return klass.create(ctx, limit);
 };
 
 klass.create = function create(ctx, limit){

+ 1 - 1
lib/pipeline/documentSources/SortDocumentSource.js

@@ -398,7 +398,7 @@ proto.serializeSortKey = function serializeSortKey(explain) {
 klass.createFromJson = function createFromJson(elem, expCtx) {
 	if (typeof elem !== "object") throw new Error("code 15973; the " + klass.sortName + " key specification must be an object");
 
-	return this.create(expCtx, elem);
+	return klass.create(expCtx, elem);
 };
 
 /**

+ 58 - 4
test/lib/pipeline/PipelineD.js

@@ -75,10 +75,64 @@ module.exports = {
 				assert.equal(JSON.stringify(p.sources[0]._projection), JSON.stringify({ a: 1, b: 1, 'x.y.z': 1, _id: 0 }));
 				assert.deepEqual(p.sources[0]._dependencies, {"_fields":{"a":true,"b":true,"x":{"y":{"z":true}}}});
 			},
-			"should set the queryObj on the Cursor": function(){},
-			"should set the sort on the Cursor": function(){},
-			"should set the sort on the Cursor if there is a match first": function(){},
-			"should coalesce the Cursor with the rest of the pipeline": function(){},
+			"should set the queryObj on the Cursor": function(){
+				var cmdObj = {
+					aggregate: [],
+					pipeline: [
+						{$match:{
+							x:{$exists:true},
+							y:{$exists:false}
+						}}
+					]
+				};
+				var p = Pipeline.parseCommand(cmdObj),
+					cs = PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
+				assert.deepEqual(p.sources[0]._query, {x:{$exists: true}, y:{$exists:false}});
+			},
+			"should set the sort on the Cursor": function(){
+				var cmdObj = {
+					aggregate: [],
+					pipeline: [
+						{$sort:{
+							x:1,
+							y:-1
+						}}
+					]
+				};
+				var p = Pipeline.parseCommand(cmdObj),
+					cs = PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
+				assert.deepEqual(p.sources[0]._sort, {x:1, y:-1});
+			},
+			"should set the sort on the Cursor if there is a match first": function(){
+				var cmdObj = {
+					aggregate: [],
+					pipeline: [
+						{$match:{
+							x:{$exists:true},
+							y:{$exists:false}
+						}},
+						{$sort:{
+							x:1,
+							y:-1
+						}}
+					]
+				};
+				var p = Pipeline.parseCommand(cmdObj),
+					cs = PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
+				assert.deepEqual(p.sources[0]._sort, {x:1, y:-1});
+			},
+			"should coalesce the Cursor with the rest of the pipeline": function(){
+				var cmdObj = {
+					aggregate: [],
+					pipeline: [
+						{$limit:1}
+					]
+				};
+				var p = Pipeline.parseCommand(cmdObj),
+					cs = PipelineD.prepareCursorSource(p, {ns:[1,2,3,4,5]});
+				assert.equal(p.sources[0].getLimit(), 1);
+				assert.equal(p.sources.length, 1);
+			},
 		}
 	}