GettingAllDocsTests.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* eslint-disable
  2. handle-callback-err,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS101: Remove unnecessary use of Array.from
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const sinon = require("sinon");
  15. const chai = require("chai");
  16. chai.should();
  17. const {ObjectId} = require("mongojs");
  18. const async = require("async");
  19. const DocstoreApp = require("./helpers/DocstoreApp");
  20. const DocstoreClient = require("./helpers/DocstoreClient");
  21. describe("Getting all docs", function() {
  22. beforeEach(function(done) {
  23. this.project_id = ObjectId();
  24. this.docs = [{
  25. _id: ObjectId(),
  26. lines: ["one", "two", "three"],
  27. ranges: {"mock": "one"},
  28. rev: 2
  29. }, {
  30. _id: ObjectId(),
  31. lines: ["aaa", "bbb", "ccc"],
  32. ranges: {"mock": "two"},
  33. rev: 4
  34. }, {
  35. _id: ObjectId(),
  36. lines: ["111", "222", "333"],
  37. ranges: {"mock": "three"},
  38. rev: 6
  39. }];
  40. this.deleted_doc = {
  41. _id: ObjectId(),
  42. lines: ["deleted"],
  43. ranges: {"mock": "four"},
  44. rev: 8
  45. };
  46. const version = 42;
  47. const jobs = Array.from(this.docs).map((doc) =>
  48. (doc => {
  49. return callback => {
  50. return DocstoreClient.createDoc(this.project_id, doc._id, doc.lines, version, doc.ranges, callback);
  51. };
  52. })(doc));
  53. jobs.push(cb => {
  54. return DocstoreClient.createDoc(this.project_id, this.deleted_doc._id, this.deleted_doc.lines, version, this.deleted_doc.ranges, err=> {
  55. return DocstoreClient.deleteDoc(this.project_id, this.deleted_doc._id, cb);
  56. });
  57. });
  58. jobs.unshift(cb => DocstoreApp.ensureRunning(cb));
  59. return async.series(jobs, done);
  60. });
  61. it("getAllDocs should return all the (non-deleted) docs", function(done) {
  62. return DocstoreClient.getAllDocs(this.project_id, (error, res, docs) => {
  63. if (error != null) { throw error; }
  64. docs.length.should.equal(this.docs.length);
  65. for (let i = 0; i < docs.length; i++) {
  66. const doc = docs[i];
  67. doc.lines.should.deep.equal(this.docs[i].lines);
  68. }
  69. return done();
  70. });
  71. });
  72. return it("getAllRanges should return all the (non-deleted) doc ranges", function(done) {
  73. return DocstoreClient.getAllRanges(this.project_id, (error, res, docs) => {
  74. if (error != null) { throw error; }
  75. docs.length.should.equal(this.docs.length);
  76. for (let i = 0; i < docs.length; i++) {
  77. const doc = docs[i];
  78. doc.ranges.should.deep.equal(this.docs[i].ranges);
  79. }
  80. return done();
  81. });
  82. });
  83. });