GettingDocsFromArchiveTest.js 3.5 KB

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