| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 | 
							- "use strict";
 
- var assert = require("assert"),
 
- 	async = require("async"),
 
- 	DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource"),
 
- 	OutDocumentSource = require("../../../../lib/pipeline/documentSources/OutDocumentSource"),
 
- 	CursorDocumentSource = require("../../../../lib/pipeline/documentSources/CursorDocumentSource"),
 
- 	Cursor = require("../../../../lib/Cursor");
 
- var createOut = function(ctx) {
 
- 	var ds = new OutDocumentSource(ctx);
 
- 	return ds;
 
- };
 
- module.exports = {
 
- 	"OutDocumentSource": {
 
- 		"constructor()":{
 
- 			"should not throw when constructing without args":function() {
 
- 				assert.doesNotThrow(function(){
 
- 					var ods = createOut();
 
- 				});
 
- 			}
 
- 		},
 
- 		"#getSourceName()":{
 
- 			"should return the correct source name; $out": function() {
 
- 				var ods = createOut();
 
- 				assert.strictEqual(ods.getSourceName(), "$out");
 
- 			}
 
- 		},
 
- 		"#getNext()":{
 
- 			"callback is required":function() {
 
- 				var ods = createOut();
 
- 				assert.throws(ods.getNext.bind(ods));
 
- 			},
 
- 			"should act ass passthrough (for now)": function(next) {
 
- 				var ods = OutDocumentSource.createFromJson("test"),
 
- 					cwc = new CursorDocumentSource.CursorWithContext(),
 
- 					l = [{_id:0,a:[{b:1},{b:2}]}, {_id:1,a:[{b:1},{b:1}]} ];
 
- 				cwc._cursor = new Cursor( l );
 
- 				var cds = new CursorDocumentSource(cwc);
 
- 				ods.setSource(cds);
 
- 				var docs = [], i = 0;
 
- 				async.doWhilst(
 
- 					function(cb) {
 
- 						ods.getNext(function(err, val) {
 
- 							docs[i] = val;
 
- 							return cb(err);
 
- 						});
 
- 					},
 
- 					function() {
 
- 						return docs[i++] !== DocumentSource.EOF;
 
- 					},
 
- 					function(err) {
 
- 						assert.deepEqual([{_id:0,a:[{b:1},{b:2}]}, {_id:1,a:[{b:1},{b:1}]}, DocumentSource.EOF], docs);
 
- 						next();
 
- 					}
 
- 				);
 
- 			}
 
- 		},
 
- 		"#createFromJson()":{
 
- 			"method creates OutDocumentSource with given title":function() {
 
- 				var title = "CognitiveScientists",
 
- 					ods = OutDocumentSource.createFromJson(title);
 
- 				assert.strictEqual(title, ods._collectionName);
 
- 			}
 
- 		},
 
- 		"#serialize()":{
 
- 			"serialize":function() {
 
- 				var cwc = new CursorDocumentSource.CursorWithContext();
 
- 				var input = [{_id: 0, a: 1}, {_id: 1, a: 2}];
 
- 				cwc._cursor = new Cursor( input );
 
- 				var cds = new CursorDocumentSource(cwc);
 
- 				var title = "CognitiveScientists";
 
- 				var ods = OutDocumentSource.createFromJson(title);
 
- 				ods.setSource(cds);
 
- 				var srcNm = ods.getSourceName();
 
- 				var serialize = {};
 
- 				serialize[srcNm] = title;
 
- 				assert.deepEqual(ods.serialize(), serialize);
 
- 			}
 
- 		}
 
- 	}
 
- };
 
- if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);
 
 
  |