MatchDocumentSource.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 t = MatchDocumentSource.createFromJson({ someval:{$exists:true} });
  43. assert.strictEqual(t instanceof MatchDocumentSource, true);
  44. }
  45. }
  46. }
  47. };
  48. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);