DocumentSource.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. "#documentFromJsonWithDeps()": {
  33. "should be able to convert a document to its projected form": function() {
  34. var deps = {'a': true, 'b': true},
  35. doc = {a:23, b:64, c:92};
  36. var proj = DocumentSource.documentFromJsonWithDeps(doc, deps);
  37. assert.deepEqual({a:23,b:64}, proj);
  38. }
  39. }
  40. }
  41. };
  42. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run();