|
|
@@ -41,7 +41,7 @@ module.exports = {
|
|
|
},
|
|
|
|
|
|
"#getNext()": {
|
|
|
-
|
|
|
+ /** Assert that iterator state accessors consistently report the source is exhausted. */
|
|
|
"should return EOF if there are no more sources": function noSources(next){
|
|
|
var cwc = new CursorDocumentSource.CursorWithContext();
|
|
|
cwc._cursor = new Cursor( [{a: 1}] );
|
|
|
@@ -55,7 +55,22 @@ module.exports = {
|
|
|
next();
|
|
|
});
|
|
|
});
|
|
|
+ sds.getNext(function(err, val) {
|
|
|
+ assert.deepEqual(val, {a:1});
|
|
|
+ sds.getNext(function(err, val) {
|
|
|
+ assert.equal(val, DocumentSource.EOF);
|
|
|
+ next();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ sds.getNext(function(err, val) {
|
|
|
+ assert.deepEqual(val, {a:1});
|
|
|
+ sds.getNext(function(err, val) {
|
|
|
+ assert.equal(val, DocumentSource.EOF);
|
|
|
+ next();
|
|
|
+ });
|
|
|
+ });
|
|
|
},
|
|
|
+
|
|
|
"should return EOF if there are more documents": function hitSort(next){
|
|
|
var cwc = new CursorDocumentSource.CursorWithContext();
|
|
|
cwc._cursor = new Cursor( [{a: 1}] );
|
|
|
@@ -119,6 +134,22 @@ module.exports = {
|
|
|
|
|
|
"#serializeToArray()": {
|
|
|
|
|
|
+ /**
|
|
|
+ * Check that the BSON representation generated by the souce matches the BSON it was
|
|
|
+ * created with.
|
|
|
+ */
|
|
|
+ "should have equal json representation": function serializeToArrayCheck(){
|
|
|
+ var sds = new SortDocumentSource();
|
|
|
+ var spec = {"$sort":{"a":1}};
|
|
|
+ sds.createFromJson(spec, {});
|
|
|
+
|
|
|
+ var arr = sds.serializeToArray();
|
|
|
+ var generatedSpec = arr[0];
|
|
|
+
|
|
|
+ sds.serializeToArray(t, false);
|
|
|
+ assert.deepEqual(t, [{ "$sort": { "a": 1 } }]);
|
|
|
+ },
|
|
|
+
|
|
|
"should create an object representation of the SortDocumentSource": function serializeToArrayTest(){
|
|
|
var sds = new SortDocumentSource();
|
|
|
sds.vSortKey.push(new FieldPathExpression("b") );
|
|
|
@@ -449,10 +480,17 @@ module.exports = {
|
|
|
assert.equal(newSrc, false);
|
|
|
},
|
|
|
|
|
|
+
|
|
|
"should return limit source when coalescing a limit source": function limitSource() {
|
|
|
var sds = SortDocumentSource.createFromJson({a:1}),
|
|
|
lds = LimitDocumentSource.createFromJson(1);
|
|
|
|
|
|
+ // TODO: add missing test cases.
|
|
|
+ // array json getLimit
|
|
|
+ // getShardSource
|
|
|
+ // getMergeSource
|
|
|
+
|
|
|
+
|
|
|
var newSrc = sds.coalesce(LimitDocumentSource.createFromJson(10));
|
|
|
assert.ok(newSrc instanceof LimitDocumentSource);
|
|
|
assert.equal(sds.getLimit(), 10);
|
|
|
@@ -464,10 +502,17 @@ module.exports = {
|
|
|
var arr = [];
|
|
|
sds.serializeToArray(arr);
|
|
|
assert.deepEqual(arr, [{$sort: {a:1}}, {$limit: 5}]);
|
|
|
+
|
|
|
+ // TODO: add missing test cases
|
|
|
+ // doc array get limit
|
|
|
+ // getShardSource
|
|
|
+ // get MergeSource
|
|
|
+
|
|
|
},
|
|
|
},
|
|
|
|
|
|
"#dependencies": {
|
|
|
+ /** Dependant field paths. */
|
|
|
"should have Dependant field paths": function dependencies() {
|
|
|
var sds = new SortDocumentSource();
|
|
|
sds.addKey("a", true);
|
|
|
@@ -477,6 +522,8 @@ module.exports = {
|
|
|
assert.equal(2, Object.keys(deps).length);
|
|
|
assert.ok(deps.a);
|
|
|
assert.ok(deps["b.c"]);
|
|
|
+ // TODO: Add needWholeDocument
|
|
|
+ // TODO: Add needTextScore
|
|
|
}
|
|
|
}
|
|
|
|