LimitDocumentSource.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. var assert = require("assert"),
  2. LimitDocumentSource = require("../../../../lib/pipeline/documentSources/LimitDocumentSource");
  3. module.exports = {
  4. "LimitDocumentSource": {
  5. "constructor()": {
  6. "should not throw Error when constructing without args": function testConstructor(){
  7. assert.doesNotThrow(function(){
  8. new LimitDocumentSource();
  9. });
  10. }
  11. },
  12. "#getSourceName()": {
  13. "should return the correct source name; $limit": function testSourceName(){
  14. var lds = new LimitDocumentSource();
  15. assert.strictEqual(lds.getSourceName(), "$limit");
  16. }
  17. },
  18. "#getFactory()": {
  19. "should return the constructor for this class": function factoryIsConstructor(){
  20. assert.strictEqual(new LimitDocumentSource().getFactory(), LimitDocumentSource);
  21. }
  22. },
  23. /*
  24. "#coalesce()": {
  25. "should return false if nextSource is not $skip": function dontSkip(){
  26. },
  27. "should return true if nextSource is $skip": function changeLimit(){
  28. }
  29. },
  30. "#eof()": {
  31. "should return true if there are no more sources": function noSources(){
  32. },
  33. "should return true if limit is hit": function hitLimit(){
  34. }
  35. },
  36. "#getCurrent()": {
  37. "should return the current document source": function currSource(){
  38. var lds = new LimitDocumentSource();
  39. lds.limit = 1;
  40. lds.pSource = { item:1 };
  41. assert.strictEqual(lds.getCurrent(), { item:1 });
  42. }
  43. },
  44. "#advance()": {
  45. "should return true for moving to the next source": function nextSource(){
  46. },
  47. "should return false for no sources remaining": function noMoar(){
  48. }
  49. },
  50. */
  51. "#sourceToJson()": {
  52. "should create an object with a key $limit and the value equal to the limit": function sourceToJsonTest(){
  53. var lds = new LimitDocumentSource();
  54. lds.limit = 9;
  55. var t = {};
  56. lds.sourceToJson(t, false);
  57. assert.deepEqual(t, { "$limit": 9 });
  58. }
  59. },
  60. "#createFromJson()": {
  61. "should return a new LimitDocumentSource object from an input number": function createTest(){
  62. var lds = new LimitDocumentSource();
  63. var t = lds.createFromJson(5);
  64. assert.strictEqual(t, LimitDocumentSource);
  65. assert.strictEqual(t.limit, 5);
  66. }
  67. }
  68. }
  69. };
  70. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).run(process.exit);