| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- var assert = require("assert"),
- AddToSetAccumulator = require("../../../../lib/pipeline/accumulators/AddToSetAccumulator"),
- FieldPathExpression = require("../../../../lib/pipeline/expressions/FieldPathExpression");
- function createAccumulator(){
- var accumulator = new AddToSetAccumulator();
- accumulator.addOperand(new FieldPathExpression("b") );
- return accumulator;
- }
- module.exports = {
- "AddToSetAccumulator": {
- "constructor()": {
- "should not throw Error when constructing without args": function testConstructor(){
- assert.doesNotThrow(function(){
- new AddToSetAccumulator();
- });
- }
- },
- "#getOpName()": {
- "should return the correct op name; $addToSet": function testOpName(){
- assert.strictEqual(new AddToSetAccumulator().getOpName(), "$addToSet");
- }
- },
- "#evaluate()": {
- "should evaluate no documents": function testStuff(){
- var accumulator = createAccumulator();
- accumulator.evaluate();
- assert.deepEqual(accumulator.getValue(), []);
- },
- "should evaluate one document and return an set of 1: [1]": function testStuff(){
- var accumulator = createAccumulator();
- accumulator.evaluate({b:1});
- assert.deepEqual(accumulator.getValue(), [1]);
- },
- "should evaluate two documents with the same value and return a set of 1: [1]": function testStuff(){
- var accumulator = createAccumulator();
- accumulator.evaluate({b:1});
- accumulator.evaluate({b:1});
- assert.deepEqual(accumulator.getValue(), [1]);
- },
- "should evaluate two documents with the same objects as values and return a set of 1: [{foo:'bar'}]": function testStuff(){
- var accumulator = createAccumulator();
- accumulator.evaluate({b:{foo:"bar"}});
- accumulator.evaluate({b:{foo:"bar"}});
- assert.deepEqual(accumulator.getValue(), [{foo:"bar"}]);
- },
- "should evaluate two documents with the same arrays as values and return a set of 1: [[1,2,3]]": function testStuff(){
- var accumulator = createAccumulator();
- accumulator.evaluate({b:[1,2,3]});
- accumulator.evaluate({b:[1,2,3]});
- assert.deepEqual(accumulator.getValue(), [[1,2,3]]);
- },
- "should evaluate two documents with different values and return a set of 2: [1,2]": function testStuff(){
- var accumulator = createAccumulator();
- accumulator.evaluate({b:1});
- accumulator.evaluate({b:2});
- assert.deepEqual(accumulator.getValue(), [1,2]);
- },
- "should evaluate two documents with the different objects as values and return a set of 2: [{foo:'bar'},{foo:'baz'}]": function testStuff(){
- var accumulator = createAccumulator();
- accumulator.evaluate({b:{foo:"bar"}});
- accumulator.evaluate({b:{foo:"baz"}});
- assert.deepEqual(accumulator.getValue(), [{foo:"bar"},{foo:"baz"}]);
- },
- "should evaluate two documents with the different arrays as values and return a set of 1: [[1,2,3], [1,2]]": function testStuff(){
- var accumulator = createAccumulator();
- accumulator.evaluate({b:[1,2,3]});
- accumulator.evaluate({b:[1,2]});
- assert.deepEqual(accumulator.getValue(), [[1,2,3], [1,2]]);
- },
- "should evaluate one document with null and one document with a value and return an set of 1: [1]": function testStuff(){
- var accumulator = createAccumulator();
- accumulator.evaluate({b:1});
- accumulator.evaluate({b:null});
- assert.deepEqual(accumulator.getValue(), [1]);
- }
- }
- }
- };
- if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);
|