WhereMatchExpression.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "use strict";
  2. var assert = require("assert"),
  3. WhereMatchExpression = require("../../../../lib/pipeline/matcher/WhereMatchExpression");
  4. // Mongo supplied no integration tests with WhereMatchExpression
  5. module.exports = {
  6. "WhereMatchExpression": {
  7. "should run series of tests": function (){
  8. var e = new WhereMatchExpression();
  9. // MOCK UP MISSING INTEGRATION PIECES
  10. // TODO: After all the missing elements are implemented,
  11. // most mocks will not be necessary.
  12. e._userScope = {};
  13. e._scope= {};
  14. e._ns = "ns";
  15. e._code = "code";
  16. e._scope.invoke = function(){};
  17. e.getAuthorizationSession = function(){
  18. var result = {};
  19. result.getAuthenticatedUserNamesToken = function(){};
  20. return result;
  21. };
  22. e.getAuthorizationSession.getAuthenticatedUserNamesToken = function(){};
  23. e.globalScriptEngine = {};
  24. e.globalScriptEngine.getPooledScope = function(txn, dbName, userToken){
  25. var scope = {};
  26. scope.createFunction = function( code ){
  27. var result = {};
  28. return result;
  29. };
  30. scope.obj = {}
  31. scope.fullObject = false;
  32. scope.init = function( scope){
  33. return {};
  34. }
  35. scope.invoke = function( func, it, obj, time, bl){
  36. return 0;
  37. }
  38. return scope;
  39. };
  40. var theCode = {};
  41. theCode.c_str = function(){};
  42. var scope = {};
  43. scope.getOwned = function(){ return {};};
  44. var dbName = "eagle6";
  45. // Assert we can create
  46. var s = e.init(dbName,theCode,scope);
  47. assert.strictEqual(s.code, 'OK');
  48. // Assert we get debugString
  49. var debugString = e.debugString(0);
  50. assert.strictEqual(debugString.split("\n")[1], ' dbName: eagle6');
  51. // Assert equivalent
  52. var result = e.equivalent("NotEQ");
  53. assert.strictEqual(result, false);
  54. // Assert equivalent of unknown type
  55. var other = {};
  56. other._matchType = "SOME_UNKNOWN_TYPE";
  57. var result = e.equivalent(other);
  58. assert.strictEqual(result, false);
  59. // Assert equivalent of correct type but return false because objects don't match
  60. var other = {};
  61. other._matchType = "MATCH_WHERE";
  62. var result = e.equivalent(other);
  63. assert.strictEqual(result, false);
  64. // Assert equivalent of correct type
  65. var result = e.equivalent(e);
  66. assert.strictEqual(result, true);
  67. }
  68. }
  69. };
  70. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);