GettingDocsTests.js 3.6 KB

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