TestBase.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. var TestBase = (function() {
  2. var klass = function TestBase(overrides) {
  3. //NOTE: DEVIATION FROM MONGO: using this base class to make things easier to initialize
  4. for (var key in overrides){
  5. this[key] = overrides[key];
  6. }
  7. },
  8. proto = klass.prototype;
  9. proto.createSource = function() {
  10. //TODO: Fix this once we know proper API
  11. this._source = CursorDocumentSource.create();
  12. };
  13. proto.source = function() {
  14. return this._source;
  15. };
  16. proto.createProject = function(projection) {
  17. projection = projection || {a:true};
  18. var spec = {$project:projection};
  19. this._project = ProjectDocumentSource(spec /*,ctx()*/);
  20. this.checkJsonRepresentation(spec);
  21. this._project.setSource(this.source());
  22. };
  23. proto.project = function() {
  24. return this._project;
  25. };
  26. proto.assertExhausted = function() {
  27. var self = this;
  28. self._project.getNext(function(err, input1) {
  29. assert.strictEqual(input, DocumentSource.EOF);
  30. self._project.getNext(function(err, input2) {
  31. assert.strictEqual(input2, DocumentSource.EOF);
  32. self._project.getNext(function(err, input3) {
  33. assert.strictEqual(input3, DocumentSource.EOF);
  34. });
  35. });
  36. });
  37. };
  38. proto.checkJsonRepresentation = function() {
  39. var arr = [];
  40. this._project.serializeToArray(arr);
  41. var generatedSpec = arr[0];
  42. assert.deepEqual(generatedSpec, spec);
  43. };
  44. return klass;
  45. })();
  46. module.exports = TestBase;