MatchDocumentSource.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. var assert = require("assert"),
  3. MatchDocumentSource = require("../../../../lib/pipeline/documentSources/MatchDocumentSource");
  4. module.exports = {
  5. "MatchDocumentSource": {
  6. "constructor()": {
  7. "should throw Error when constructing without args": function testConstructor(){
  8. assert.throws(function(){
  9. new MatchDocumentSource();
  10. });
  11. }
  12. },
  13. "#getSourceName()": {
  14. "should return the correct source name; $match": function testSourceName(){
  15. var mds = new MatchDocumentSource({ packet :{ $exists : false } });
  16. assert.strictEqual(mds.getSourceName(), "$match");
  17. }
  18. },
  19. "#accept()": {
  20. "should return true on the input document": function acceptTest(){
  21. var mds = new MatchDocumentSource({ location : { $in : ['Kentucky'] } });
  22. assert.strictEqual(mds.accept({ name: 'Adam', location: 'Kentucky'}), true);
  23. }
  24. },
  25. "#sourceToJson()": {
  26. "should append the match query to the input builder": function sourceToJsonTest(){
  27. var mds = new MatchDocumentSource({ location : { $in : ['Kentucky'] } });
  28. var t = {};
  29. mds.sourceToJson(t, false);
  30. assert.deepEqual(t, { "$match" : { location : { $in : ['Kentucky'] } }});
  31. }
  32. },
  33. "#toMatcherJson()": {
  34. "should append the match query to an object suitable for creating a new matcher": function convertTest(){
  35. var mds = new MatchDocumentSource({ location : { $in : ['Kentucky'] } });
  36. var t = {};
  37. mds.toMatcherJson(t);
  38. assert.deepEqual(t, { location : { $in : ['Kentucky'] } });
  39. }
  40. },
  41. "#createFromJson()": {
  42. "should return a new MatchDocumentSource object from an input object": function createTest(){
  43. var t = MatchDocumentSource.createFromJson({ someval:{$exists:true} });
  44. assert.strictEqual(t instanceof MatchDocumentSource, true);
  45. }
  46. }
  47. }
  48. };
  49. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);