DocumentSource.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. var assert = require("assert"),
  3. DocumentSource = require("../../../../lib/pipeline/documentSources/DocumentSource");
  4. module.exports = {
  5. "DocumentSource": {
  6. "depsToProjection": {
  7. "should be able to convert dependencies to a projection": function(){
  8. var array = {'a':1,'b':1},
  9. expected = '{"_id":0,"a":1,"b":1}',
  10. proj = DocumentSource.depsToProjection(array);
  11. assert.equal(expected, JSON.stringify(proj));
  12. },
  13. "should be able to convert dependencies with subfields to a projection": function(){
  14. var array = {'a':1,'a.b':1},
  15. expected = '{"_id":0,"a":1}',
  16. proj = DocumentSource.depsToProjection(array);
  17. assert.equal(expected, JSON.stringify(proj));
  18. },
  19. "should be able to convert dependencies with _id to a projection": function(){
  20. var array = {"_id":1,'a':1,'b':1},
  21. expected = '{"a":1,"b":1,"_id":1}',
  22. proj = DocumentSource.depsToProjection(array);
  23. assert.equal(expected, JSON.stringify(proj));
  24. },
  25. "should be able to convert dependencies with id and subfields to a projection": function(){
  26. var array = {'_id.a':1,'b':1},
  27. expected = '{"_id":1,"b":1}',
  28. proj = DocumentSource.depsToProjection(array);
  29. assert.equal(expected, JSON.stringify(proj));
  30. },
  31. }
  32. }
  33. };
  34. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run();