GettingDocsTests.js 3.5 KB

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