Simple tests for sub-set projections.

This commit is contained in:
Slava Kim
2013-09-09 14:48:39 -04:00
parent 280a9f7179
commit 2e10d43041

View File

@@ -1069,6 +1069,55 @@ Tinytest.add("minimongo - fetch with fields", function (test) {
});
});
Tinytest.add("minimongo - fetch with projection, subarrays", function (test) {
// Apparently projection of type 'foo.bar.x' for
// { foo: [ { bar: { x: 42 } }, { bar: { x: 3 } } ] }
// should return exactly this object. More precisely, arrays are considered as
// sets and are queried separately and then merged back to result set
var c = new LocalCollection();
// Insert a test object with two set fields
c.insert({
setA: [{
fieldA: 42,
fieldB: 33
}, {
fieldA: "the good",
fieldB: "the bad",
fieldC: "the ugly"
}],
setB: [{
anotherA: { },
anotherB: "meh"
}, {
anotherA: 1234,
anotherB: 431
}]
});
var equalNonStrict = function (a, b, desc) {
test.equal(EJSON.stringify(a), EJSON.stringify(b), desc);
};
var testForProjection = function (projection, expected) {
var fetched = c.find({}, { fields: projection }).fetch()[0];
equalNonStrict(fetched, expected, "failed sub-set projection: " +
JSON.stringify(projection));
};
testForProjection({ 'setA.fieldA': 1, 'setB.anotherB': 1, _id: 0 },
{
setA: [{ fieldA: 42 }, { fieldA: "the good" }],
setB: [{ anotherB: "meh" }, { anotherB: 431 }]
});
testForProjection({ 'setA.fieldA': 0, 'setB.anotherA': 0, _id: 0 },
{
setA: [{fieldB:33}, {fieldB:"the bad",fieldC:"the ugly"}],
setB: [{ anotherB: "meh" }, { anotherB: 431 }]
});
});
Tinytest.add("minimongo - observe ordered with projection", function (test) {
// These tests are copy-paste from "minimongo -observe ordered",
// slightly modified to test projection