GettingDocsFromArchiveTest.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. const Settings = require('@overleaf/settings')
  2. const { ObjectId } = require('../../../app/js/mongodb')
  3. const DocstoreApp = require('./helpers/DocstoreApp')
  4. const DocstoreClient = require('./helpers/DocstoreClient')
  5. const { Storage } = require('@google-cloud/storage')
  6. describe('Getting A Doc from Archive', function () {
  7. before(async function () {
  8. await DocstoreApp.ensureRunning()
  9. })
  10. before(async function () {
  11. const storage = new Storage(Settings.docstore.gcs.endpoint)
  12. await storage.createBucket(Settings.docstore.bucket)
  13. await storage.createBucket(`${Settings.docstore.bucket}-deleted`)
  14. })
  15. after(async function () {
  16. // Tear down the buckets created above
  17. const storage = new Storage(Settings.docstore.gcs.endpoint)
  18. await storage.bucket(Settings.docstore.bucket).deleteFiles()
  19. await storage.bucket(Settings.docstore.bucket).delete()
  20. await storage.bucket(`${Settings.docstore.bucket}-deleted`).deleteFiles()
  21. await storage.bucket(`${Settings.docstore.bucket}-deleted`).delete()
  22. })
  23. describe('for an archived doc', function () {
  24. before(async function () {
  25. this.project_id = new ObjectId()
  26. this.timeout(1000 * 30)
  27. this.doc = {
  28. _id: new ObjectId(),
  29. lines: ['foo', 'bar'],
  30. ranges: {},
  31. version: 2,
  32. }
  33. await DocstoreClient.createDoc(
  34. this.project_id,
  35. this.doc._id,
  36. this.doc.lines,
  37. this.doc.version,
  38. this.doc.ranges
  39. )
  40. this.res = await DocstoreClient.archiveDoc(this.project_id, this.doc._id)
  41. })
  42. it('should successully archive the doc', function () {
  43. this.res.status.should.equal(204)
  44. })
  45. it('should return the doc lines and version from persistent storage', async function () {
  46. const { res, doc } = await DocstoreClient.peekDoc(
  47. this.project_id,
  48. this.doc._id
  49. )
  50. res.status.should.equal(200)
  51. res.headers.get('x-doc-status').should.equal('archived')
  52. doc.lines.should.deep.equal(this.doc.lines)
  53. doc.version.should.equal(this.doc.version)
  54. doc.ranges.should.deep.equal(this.doc.ranges)
  55. })
  56. it('should return the doc lines and version from persistent storage on subsequent requests', async function () {
  57. const { res, doc } = await DocstoreClient.peekDoc(
  58. this.project_id,
  59. this.doc._id
  60. )
  61. res.status.should.equal(200)
  62. res.headers.get('x-doc-status').should.equal('archived')
  63. doc.lines.should.deep.equal(this.doc.lines)
  64. doc.version.should.equal(this.doc.version)
  65. doc.ranges.should.deep.equal(this.doc.ranges)
  66. })
  67. describe('for an non-archived doc', function () {
  68. before(async function () {
  69. this.project_id = new ObjectId()
  70. this.timeout(1000 * 30)
  71. this.doc = {
  72. _id: new ObjectId(),
  73. lines: ['foo', 'bar'],
  74. ranges: {},
  75. version: 2,
  76. }
  77. await DocstoreClient.createDoc(
  78. this.project_id,
  79. this.doc._id,
  80. this.doc.lines,
  81. this.doc.version,
  82. this.doc.ranges
  83. )
  84. })
  85. it('should return the doc lines and version from mongo', async function () {
  86. const { res, doc } = await DocstoreClient.peekDoc(
  87. this.project_id,
  88. this.doc._id
  89. )
  90. res.status.should.equal(200)
  91. res.headers.get('x-doc-status').should.equal('active')
  92. doc.lines.should.deep.equal(this.doc.lines)
  93. doc.version.should.equal(this.doc.version)
  94. doc.ranges.should.deep.equal(this.doc.ranges)
  95. })
  96. })
  97. })
  98. })