GettingAllDocsTests.js 3.0 KB

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