Переглянути джерело

Refs #2069. Added group concat test case.

Spencer Rathbun 12 роки тому
батько
коміт
779e5adda5
1 змінених файлів з 43 додано та 0 видалено
  1. 43 0
      test/lib/aggregate.js

+ 43 - 0
test/lib/aggregate.js

@@ -285,6 +285,49 @@ module.exports = {
 					],
 				aggregater = aggregate(p);	
 
+			aggregater(i, function(err, results){
+				var a = results;
+				assert.equal(JSON.stringify(a), JSON.stringify(e), "Unexpected value!");
+				assert.deepEqual(a, e, "Unexpected value (not deepEqual)!");
+
+				aggregater(i, function(err, results){
+					assert.equal(JSON.stringify(results), JSON.stringify(e), "Reuse of aggregater should yield the same results!");
+
+					aggregate(p, i, function(err, results){
+						assert.equal(JSON.stringify(results), JSON.stringify(e), "Alternate use of aggregate should yield the same results!");
+						next();
+					});
+				});
+			});
+		},
+
+		"should be able to construct an instance with $group using concat": function(next){
+			var i = [
+						{_id:0, a:null},
+						{_id:1, a:"a"},
+						{_id:1, a:"b"},
+						{_id:1, a:"b"},
+						{_id:1, a:"c"}
+					],
+				p = [{$group:{
+						_id:{$concat:["$a"]},
+					}}],
+				e = [
+						{
+							_id:null,
+						},
+						{
+							_id:"a",
+						},
+						{
+							_id:"b",
+						},
+						{
+							_id:"c",
+						}
+					],
+				aggregater = aggregate(p);	
+
 			aggregater(i, function(err, results){
 				var a = results;
 				assert.equal(JSON.stringify(a), JSON.stringify(e), "Unexpected value!");