GettingDocsTests.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* eslint-disable
  2. camelcase,
  3. handle-callback-err,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  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 DocstoreApp = require('./helpers/DocstoreApp')
  17. const DocstoreClient = require('./helpers/DocstoreClient')
  18. describe('Getting a doc', function () {
  19. beforeEach(function (done) {
  20. this.project_id = ObjectId()
  21. this.doc_id = ObjectId()
  22. this.lines = ['original', 'lines']
  23. this.version = 42
  24. this.ranges = {
  25. changes: [
  26. {
  27. id: ObjectId().toString(),
  28. op: { i: 'foo', p: 3 },
  29. meta: {
  30. user_id: ObjectId().toString(),
  31. ts: new Date().toString()
  32. }
  33. }
  34. ]
  35. }
  36. return DocstoreApp.ensureRunning(() => {
  37. return DocstoreClient.createDoc(
  38. this.project_id,
  39. this.doc_id,
  40. this.lines,
  41. this.version,
  42. this.ranges,
  43. (error) => {
  44. if (error != null) {
  45. throw error
  46. }
  47. return done()
  48. }
  49. )
  50. })
  51. })
  52. describe('when the doc exists', function () {
  53. return it('should get the doc lines and version', function (done) {
  54. return DocstoreClient.getDoc(
  55. this.project_id,
  56. this.doc_id,
  57. {},
  58. (error, res, doc) => {
  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. 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. doc.lines.should.deep.equal(this.lines)
  109. doc.version.should.equal(this.version)
  110. doc.ranges.should.deep.equal(this.ranges)
  111. doc.deleted.should.equal(true)
  112. return done()
  113. }
  114. )
  115. })
  116. return it('should return a 404 when the query string is not set', function (done) {
  117. return DocstoreClient.getDoc(
  118. this.project_id,
  119. this.deleted_doc_id,
  120. {},
  121. (error, res, doc) => {
  122. res.statusCode.should.equal(404)
  123. return done()
  124. }
  125. )
  126. })
  127. })
  128. })