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

Refs #5121: Add test case for projections

Chris Sexton 12 лет назад
Родитель
Сommit
bb099ec726
1 измененных файлов с 47 добавлено и 0 удалено
  1. 47 0
      test/lib/pipeline/documentSources/CursorDocumentSource.js

+ 47 - 0
test/lib/pipeline/documentSources/CursorDocumentSource.js

@@ -119,6 +119,53 @@ module.exports = {
 					}
 				);
 			}
+		},
+
+		"#setProjection": {
+
+			"should set a projection": function() {
+				var cwc = new CursorDocumentSource.CursorWithContext();
+				cwc._cursor = new Cursor( [1,2,3] );
+
+				var cds = new CursorDocumentSource(cwc);
+				cds.setProjection({a:1}, {a:true});
+				assert.deepEqual(cds._projection, {a:1});
+				assert.deepEqual(cds._dependencies, {a:true});
+			},
+
+			"should throw an error if projection is already set": function (){
+				var cwc = new CursorDocumentSource.CursorWithContext();
+				cwc._cursor = new Cursor( [1,2,3] );
+
+				var cds = new CursorDocumentSource(cwc);
+				cds.setProjection({a:1}, {});
+				assert.throws(function() {
+					cds.setProjection({a:1}, {});
+				});
+			},
+
+			"should project properly": function(next) {
+				var cwc = new CursorDocumentSource.CursorWithContext();
+				cwc._cursor = new Cursor( [{a:1},{a:2,b:3},{c:4,d:5}] );
+
+				var cds = new CursorDocumentSource(cwc);
+				cds.setProjection({a:1}, {a:true});
+				assert.deepEqual(cds._projection, {a:1});
+				assert.deepEqual(cds._dependencies, {a:true});
+
+				async.series([
+						cds.getNext.bind(cds),
+						cds.getNext.bind(cds),
+						cds.getNext.bind(cds),
+						cds.getNext.bind(cds),
+					],
+					function(err,res) {
+						assert.deepEqual([{a:1},{a:2},{},DocumentSource.EOF], res);
+						next();
+					}
+				);
+			}
+
 		}
 
 	}