LastAccumulator.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. "use strict";
  2. var assert = require("assert"),
  3. LastAccumulator = require("../../../../lib/pipeline/accumulators/LastAccumulator");
  4. function createAccumulator(){
  5. return new LastAccumulator();
  6. }
  7. module.exports = {
  8. "LastAccumulator": {
  9. "constructor()": {
  10. "should not throw Error when constructing without args": function testConstructor(){
  11. assert.doesNotThrow(function(){
  12. new LastAccumulator();
  13. });
  14. }
  15. },
  16. "#getOpName()": {
  17. "should return the correct op name; $last": function testOpName(){
  18. assert.strictEqual(new LastAccumulator().getOpName(), "$last");
  19. }
  20. },
  21. "#processInternal()": {
  22. "should evaluate no documents": function testStuff(){
  23. var lastAccumulator = createAccumulator();
  24. assert.strictEqual(lastAccumulator.getValue(), undefined);
  25. },
  26. "should evaluate one document and retains its value": function testStuff(){
  27. var lastAccumulator = createAccumulator();
  28. lastAccumulator.processInternal(5);
  29. assert.strictEqual(lastAccumulator.getValue(), 5);
  30. },
  31. "should evaluate one document with the field missing retains undefined": function testStuff(){
  32. var lastAccumulator = createAccumulator();
  33. lastAccumulator.processInternal();
  34. assert.strictEqual(lastAccumulator.getValue(), undefined);
  35. },
  36. "should evaluate two documents and retains the value in the last": function testStuff(){
  37. var lastAccumulator = createAccumulator();
  38. lastAccumulator.processInternal(5);
  39. lastAccumulator.processInternal(7);
  40. assert.strictEqual(lastAccumulator.getValue(), 7);
  41. },
  42. "should evaluate two documents and retains the undefined value in the last": function testStuff(){
  43. var lastAccumulator = createAccumulator();
  44. lastAccumulator.processInternal(5);
  45. lastAccumulator.processInternal();
  46. assert.strictEqual(lastAccumulator.getValue(), undefined);
  47. }
  48. }
  49. }
  50. };
  51. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);