GettingDocsFromArchiveTest.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. * DS101: Remove unnecessary use of Array.from
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * DS207: Consider shorter variations of null checks
  13. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  14. */
  15. process.env.BACKEND = 'gcs'
  16. const Settings = require('@overleaf/settings')
  17. const { expect } = require('chai')
  18. const { db, ObjectId } = require('../../../app/js/mongodb')
  19. const async = require('async')
  20. const DocstoreApp = require('./helpers/DocstoreApp')
  21. const DocstoreClient = require('./helpers/DocstoreClient')
  22. const { Storage } = require('@google-cloud/storage')
  23. const Persistor = require('../../../app/js/PersistorManager')
  24. const Streamifier = require('streamifier')
  25. function uploadContent(path, json, callback) {
  26. const stream = Streamifier.createReadStream(JSON.stringify(json))
  27. Persistor.sendStream(Settings.docstore.bucket, path, stream)
  28. .then(() => callback())
  29. .catch(callback)
  30. }
  31. describe('Getting A Doc from Archive', function () {
  32. before(function (done) {
  33. return DocstoreApp.ensureRunning(done)
  34. })
  35. before(async function () {
  36. const storage = new Storage(Settings.docstore.gcs.endpoint)
  37. await storage.createBucket(Settings.docstore.bucket)
  38. await storage.createBucket(`${Settings.docstore.bucket}-deleted`)
  39. })
  40. describe('archiving a single doc', function () {
  41. before(function (done) {
  42. this.project_id = ObjectId()
  43. this.timeout(1000 * 30)
  44. this.doc = {
  45. _id: ObjectId(),
  46. lines: ['foo', 'bar'],
  47. ranges: {},
  48. version: 2,
  49. }
  50. DocstoreClient.createDoc(
  51. this.project_id,
  52. this.doc._id,
  53. this.doc.lines,
  54. this.doc.version,
  55. this.doc.ranges,
  56. error => {
  57. if (error) {
  58. return done(error)
  59. }
  60. DocstoreClient.archiveDocById(
  61. this.project_id,
  62. this.doc._id,
  63. (error, res) => {
  64. this.res = res
  65. if (error) {
  66. return done(error)
  67. }
  68. done()
  69. }
  70. )
  71. }
  72. )
  73. })
  74. it('should successully archive the doc', function (done) {
  75. this.res.statusCode.should.equal(204)
  76. done()
  77. })
  78. it('should get the doc lines and version', function (done) {
  79. return DocstoreClient.peekDoc(
  80. this.project_id,
  81. this.doc._id,
  82. {},
  83. (error, res, doc) => {
  84. res.statusCode.should.equal(200)
  85. doc.lines.should.deep.equal(this.doc.lines)
  86. doc.version.should.equal(this.doc.version)
  87. doc.ranges.should.deep.equal(this.doc.ranges)
  88. return done()
  89. }
  90. )
  91. })
  92. })
  93. })