GettingAllDocsTests.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 { ObjectId } = require('mongodb')
  16. const async = require('async')
  17. const DocstoreApp = require('./helpers/DocstoreApp')
  18. const DocstoreClient = require('./helpers/DocstoreClient')
  19. describe('Getting all docs', function () {
  20. beforeEach(function (done) {
  21. this.project_id = ObjectId()
  22. this.docs = [
  23. {
  24. _id: ObjectId(),
  25. lines: ['one', 'two', 'three'],
  26. ranges: { mock: 'one' },
  27. rev: 2
  28. },
  29. {
  30. _id: ObjectId(),
  31. lines: ['aaa', 'bbb', 'ccc'],
  32. ranges: { mock: 'two' },
  33. rev: 4
  34. },
  35. {
  36. _id: ObjectId(),
  37. lines: ['111', '222', '333'],
  38. ranges: { mock: 'three' },
  39. rev: 6
  40. }
  41. ]
  42. this.deleted_doc = {
  43. _id: ObjectId(),
  44. lines: ['deleted'],
  45. ranges: { mock: 'four' },
  46. rev: 8
  47. }
  48. const version = 42
  49. const jobs = Array.from(this.docs).map((doc) =>
  50. ((doc) => {
  51. return (callback) => {
  52. return DocstoreClient.createDoc(
  53. this.project_id,
  54. doc._id,
  55. doc.lines,
  56. version,
  57. doc.ranges,
  58. callback
  59. )
  60. }
  61. })(doc)
  62. )
  63. jobs.push((cb) => {
  64. return DocstoreClient.createDoc(
  65. this.project_id,
  66. this.deleted_doc._id,
  67. this.deleted_doc.lines,
  68. version,
  69. this.deleted_doc.ranges,
  70. (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. })