GettingDocsTests.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. * DS102: Remove unnecessary code created because of implicit returns
  9. * DS207: Consider shorter variations of null checks
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const sinon = require('sinon')
  13. const { ObjectId } = require('mongodb')
  14. const DocstoreApp = require('./helpers/DocstoreApp')
  15. const DocstoreClient = require('./helpers/DocstoreClient')
  16. describe('Getting a doc', function () {
  17. beforeEach(function (done) {
  18. this.project_id = ObjectId()
  19. this.doc_id = ObjectId()
  20. this.lines = ['original', 'lines']
  21. this.version = 42
  22. this.ranges = {
  23. changes: [
  24. {
  25. id: ObjectId().toString(),
  26. op: { i: 'foo', p: 3 },
  27. meta: {
  28. user_id: ObjectId().toString(),
  29. ts: new Date().toString(),
  30. },
  31. },
  32. ],
  33. }
  34. return DocstoreApp.ensureRunning(() => {
  35. return DocstoreClient.createDoc(
  36. this.project_id,
  37. this.doc_id,
  38. this.lines,
  39. this.version,
  40. this.ranges,
  41. error => {
  42. if (error != null) {
  43. throw error
  44. }
  45. return done()
  46. }
  47. )
  48. })
  49. })
  50. describe('when the doc exists', function () {
  51. return it('should get the doc lines and version', function (done) {
  52. return DocstoreClient.getDoc(
  53. this.project_id,
  54. this.doc_id,
  55. {},
  56. (error, res, doc) => {
  57. if (error) return done(error)
  58. doc.lines.should.deep.equal(this.lines)
  59. doc.version.should.equal(this.version)
  60. doc.ranges.should.deep.equal(this.ranges)
  61. return done()
  62. }
  63. )
  64. })
  65. })
  66. describe('when the doc does not exist', function () {
  67. return it('should return a 404', function (done) {
  68. const missingDocId = ObjectId()
  69. return DocstoreClient.getDoc(
  70. this.project_id,
  71. missingDocId,
  72. {},
  73. (error, res, doc) => {
  74. if (error) return done(error)
  75. res.statusCode.should.equal(404)
  76. return done()
  77. }
  78. )
  79. })
  80. })
  81. return describe('when the doc is a deleted doc', function () {
  82. beforeEach(function (done) {
  83. this.deleted_doc_id = ObjectId()
  84. return DocstoreClient.createDoc(
  85. this.project_id,
  86. this.deleted_doc_id,
  87. this.lines,
  88. this.version,
  89. this.ranges,
  90. error => {
  91. if (error != null) {
  92. throw error
  93. }
  94. return DocstoreClient.deleteDoc(
  95. this.project_id,
  96. this.deleted_doc_id,
  97. done
  98. )
  99. }
  100. )
  101. })
  102. it('should return the doc', function (done) {
  103. return DocstoreClient.getDoc(
  104. this.project_id,
  105. this.deleted_doc_id,
  106. { include_deleted: true },
  107. (error, res, doc) => {
  108. if (error) return done(error)
  109. doc.lines.should.deep.equal(this.lines)
  110. doc.version.should.equal(this.version)
  111. doc.ranges.should.deep.equal(this.ranges)
  112. doc.deleted.should.equal(true)
  113. return done()
  114. }
  115. )
  116. })
  117. return it('should return a 404 when the query string is not set', function (done) {
  118. return DocstoreClient.getDoc(
  119. this.project_id,
  120. this.deleted_doc_id,
  121. {},
  122. (error, res, doc) => {
  123. if (error) return done(error)
  124. res.statusCode.should.equal(404)
  125. return done()
  126. }
  127. )
  128. })
  129. })
  130. })