GettingAllDocsTests.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. {
  26. _id: ObjectId(),
  27. lines: ['one', 'two', 'three'],
  28. ranges: { mock: 'one' },
  29. rev: 2
  30. },
  31. {
  32. _id: ObjectId(),
  33. lines: ['aaa', 'bbb', 'ccc'],
  34. ranges: { mock: 'two' },
  35. rev: 4
  36. },
  37. {
  38. _id: ObjectId(),
  39. lines: ['111', '222', '333'],
  40. ranges: { mock: 'three' },
  41. rev: 6
  42. }
  43. ]
  44. this.deleted_doc = {
  45. _id: ObjectId(),
  46. lines: ['deleted'],
  47. ranges: { mock: 'four' },
  48. rev: 8
  49. }
  50. const version = 42
  51. const jobs = Array.from(this.docs).map((doc) =>
  52. ((doc) => {
  53. return (callback) => {
  54. return DocstoreClient.createDoc(
  55. this.project_id,
  56. doc._id,
  57. doc.lines,
  58. version,
  59. doc.ranges,
  60. callback
  61. )
  62. }
  63. })(doc)
  64. )
  65. jobs.push((cb) => {
  66. return DocstoreClient.createDoc(
  67. this.project_id,
  68. this.deleted_doc._id,
  69. this.deleted_doc.lines,
  70. version,
  71. this.deleted_doc.ranges,
  72. (err) => {
  73. return DocstoreClient.deleteDoc(
  74. this.project_id,
  75. this.deleted_doc._id,
  76. cb
  77. )
  78. }
  79. )
  80. })
  81. jobs.unshift((cb) => DocstoreApp.ensureRunning(cb))
  82. return async.series(jobs, done)
  83. })
  84. it('getAllDocs should return all the (non-deleted) docs', function (done) {
  85. return DocstoreClient.getAllDocs(this.project_id, (error, res, docs) => {
  86. if (error != null) {
  87. throw error
  88. }
  89. docs.length.should.equal(this.docs.length)
  90. for (let i = 0; i < docs.length; i++) {
  91. const doc = docs[i]
  92. doc.lines.should.deep.equal(this.docs[i].lines)
  93. }
  94. return done()
  95. })
  96. })
  97. return it('getAllRanges should return all the (non-deleted) doc ranges', function (done) {
  98. return DocstoreClient.getAllRanges(this.project_id, (error, res, docs) => {
  99. if (error != null) {
  100. throw error
  101. }
  102. docs.length.should.equal(this.docs.length)
  103. for (let i = 0; i < docs.length; i++) {
  104. const doc = docs[i]
  105. doc.ranges.should.deep.equal(this.docs[i].ranges)
  106. }
  107. return done()
  108. })
  109. })
  110. })