GettingProjectDocsTests.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 { expect } = require('chai')
  16. const MockWebApi = require('./helpers/MockWebApi')
  17. const DocUpdaterClient = require('./helpers/DocUpdaterClient')
  18. const DocUpdaterApp = require('./helpers/DocUpdaterApp')
  19. describe('Getting documents for project', function () {
  20. before(function (done) {
  21. this.lines = ['one', 'two', 'three']
  22. this.version = 42
  23. return DocUpdaterApp.ensureRunning(done)
  24. })
  25. describe('when project state hash does not match', function () {
  26. before(function (done) {
  27. this.projectStateHash = DocUpdaterClient.randomId()
  28. ;[this.project_id, this.doc_id] = Array.from([
  29. DocUpdaterClient.randomId(),
  30. DocUpdaterClient.randomId()
  31. ])
  32. MockWebApi.insertDoc(this.project_id, this.doc_id, {
  33. lines: this.lines,
  34. version: this.version
  35. })
  36. return DocUpdaterClient.preloadDoc(
  37. this.project_id,
  38. this.doc_id,
  39. (error) => {
  40. if (error != null) {
  41. throw error
  42. }
  43. return DocUpdaterClient.getProjectDocs(
  44. this.project_id,
  45. this.projectStateHash,
  46. (error, res, returnedDocs) => {
  47. this.res = res
  48. this.returnedDocs = returnedDocs
  49. return done()
  50. }
  51. )
  52. }
  53. )
  54. })
  55. return it('should return a 409 Conflict response', function () {
  56. return this.res.statusCode.should.equal(409)
  57. })
  58. })
  59. describe('when project state hash matches', function () {
  60. before(function (done) {
  61. this.projectStateHash = DocUpdaterClient.randomId()
  62. ;[this.project_id, this.doc_id] = Array.from([
  63. DocUpdaterClient.randomId(),
  64. DocUpdaterClient.randomId()
  65. ])
  66. MockWebApi.insertDoc(this.project_id, this.doc_id, {
  67. lines: this.lines,
  68. version: this.version
  69. })
  70. return DocUpdaterClient.preloadDoc(
  71. this.project_id,
  72. this.doc_id,
  73. (error) => {
  74. if (error != null) {
  75. throw error
  76. }
  77. return DocUpdaterClient.getProjectDocs(
  78. this.project_id,
  79. this.projectStateHash,
  80. (error, res0, returnedDocs0) => {
  81. // set the hash
  82. this.res0 = res0
  83. this.returnedDocs0 = returnedDocs0
  84. return DocUpdaterClient.getProjectDocs(
  85. this.project_id,
  86. this.projectStateHash,
  87. (error, res, returnedDocs) => {
  88. // the hash should now match
  89. this.res = res
  90. this.returnedDocs = returnedDocs
  91. return done()
  92. }
  93. )
  94. }
  95. )
  96. }
  97. )
  98. })
  99. it('should return a 200 response', function () {
  100. return this.res.statusCode.should.equal(200)
  101. })
  102. return it('should return the documents', function () {
  103. return this.returnedDocs.should.deep.equal([
  104. { _id: this.doc_id, lines: this.lines, v: this.version }
  105. ])
  106. })
  107. })
  108. return describe('when the doc has been removed', function () {
  109. before(function (done) {
  110. this.projectStateHash = DocUpdaterClient.randomId()
  111. ;[this.project_id, this.doc_id] = Array.from([
  112. DocUpdaterClient.randomId(),
  113. DocUpdaterClient.randomId()
  114. ])
  115. MockWebApi.insertDoc(this.project_id, this.doc_id, {
  116. lines: this.lines,
  117. version: this.version
  118. })
  119. return DocUpdaterClient.preloadDoc(
  120. this.project_id,
  121. this.doc_id,
  122. (error) => {
  123. if (error != null) {
  124. throw error
  125. }
  126. return DocUpdaterClient.getProjectDocs(
  127. this.project_id,
  128. this.projectStateHash,
  129. (error, res0, returnedDocs0) => {
  130. // set the hash
  131. this.res0 = res0
  132. this.returnedDocs0 = returnedDocs0
  133. return DocUpdaterClient.deleteDoc(
  134. this.project_id,
  135. this.doc_id,
  136. (error, res, body) => {
  137. // delete the doc
  138. return DocUpdaterClient.getProjectDocs(
  139. this.project_id,
  140. this.projectStateHash,
  141. (error, res1, returnedDocs) => {
  142. // the hash would match, but the doc has been deleted
  143. this.res = res1
  144. this.returnedDocs = returnedDocs
  145. return done()
  146. }
  147. )
  148. }
  149. )
  150. }
  151. )
  152. }
  153. )
  154. })
  155. return it('should return a 409 Conflict response', function () {
  156. return this.res.statusCode.should.equal(409)
  157. })
  158. })
  159. })