MatchDocumentSource.js 1.9 KB

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