PushAccumulator.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. "use strict";
  2. var assert = require("assert"),
  3. PushAccumulator = require("../../../../lib/pipeline/accumulators/PushAccumulator");
  4. function createAccumulator(){
  5. return new PushAccumulator();
  6. }
  7. module.exports = {
  8. "PushAccumulator": {
  9. "constructor()": {
  10. "should not throw Error when constructing without args": function testConstructor(){
  11. assert.doesNotThrow(function(){
  12. new PushAccumulator();
  13. });
  14. }
  15. },
  16. "#getOpName()": {
  17. "should return the correct op name; $push": function testOpName(){
  18. assert.strictEqual(new PushAccumulator().getOpName(), "$push");
  19. }
  20. },
  21. "#getFactory()": {
  22. "should return the constructor for this class": function factoryIsConstructor(){
  23. assert.strictEqual(new PushAccumulator().getFactory(), PushAccumulator);
  24. }
  25. },
  26. "#processInternal()": {
  27. "should processInternal no documents and return []": function testprocessInternal_None(){
  28. var accumulator = createAccumulator();
  29. assert.deepEqual(accumulator.getValue(), []);
  30. },
  31. "should processInternal a 1 and return [1]": function testprocessInternal_One(){
  32. var accumulator = createAccumulator();
  33. accumulator.processInternal(1);
  34. assert.deepEqual(accumulator.getValue(), [1]);
  35. },
  36. "should processInternal a 1 and a 2 and return [1,2]": function testprocessInternal_OneTwo(){
  37. var accumulator = createAccumulator();
  38. accumulator.processInternal(1);
  39. accumulator.processInternal(2);
  40. assert.deepEqual(accumulator.getValue(), [1,2]);
  41. },
  42. "should processInternal a 1 and a null and return [1,null]": function testprocessInternal_OneNull(){
  43. var accumulator = createAccumulator();
  44. accumulator.processInternal(1);
  45. accumulator.processInternal(null);
  46. assert.deepEqual(accumulator.getValue(), [1, null]);
  47. },
  48. "should processInternal a 1 and an undefined and return [1]": function testprocessInternal_OneUndefined(){
  49. var accumulator = createAccumulator();
  50. accumulator.processInternal(1);
  51. accumulator.processInternal(undefined);
  52. assert.deepEqual(accumulator.getValue(), [1]);
  53. },
  54. "should processInternal a 1 and a 0 and return [1,0]": function testprocessInternal_OneZero(){
  55. var accumulator = createAccumulator();
  56. accumulator.processInternal(1);
  57. accumulator.processInternal(0);
  58. assert.deepEqual(accumulator.getValue(), [1, 0]);
  59. }
  60. }
  61. }
  62. };
  63. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);