|
|
@@ -1,16 +1,3 @@
|
|
|
-/* eslint-disable
|
|
|
- no-unused-vars,
|
|
|
-*/
|
|
|
-// TODO: This file was created by bulk-decaffeinate.
|
|
|
-// Fix any style issues and re-enable lint.
|
|
|
-/*
|
|
|
- * decaffeinate suggestions:
|
|
|
- * DS101: Remove unnecessary use of Array.from
|
|
|
- * DS102: Remove unnecessary code created because of implicit returns
|
|
|
- * DS207: Consider shorter variations of null checks
|
|
|
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
- */
|
|
|
-
|
|
|
const Settings = require('@overleaf/settings')
|
|
|
const { expect } = require('chai')
|
|
|
const { db, ObjectId } = require('../../../app/js/mongodb')
|
|
|
@@ -20,17 +7,16 @@ const DocstoreClient = require('./helpers/DocstoreClient')
|
|
|
const { Storage } = require('@google-cloud/storage')
|
|
|
const Persistor = require('../../../app/js/PersistorManager')
|
|
|
const { ReadableString } = require('@overleaf/stream-utils')
|
|
|
+const { callbackify } = require('node:util')
|
|
|
|
|
|
-function uploadContent(path, json, callback) {
|
|
|
+async function uploadContent(path, json) {
|
|
|
const stream = new ReadableString(JSON.stringify(json))
|
|
|
- Persistor.sendStream(Settings.docstore.bucket, path, stream)
|
|
|
- .then(() => callback())
|
|
|
- .catch(callback)
|
|
|
+ await Persistor.sendStream(Settings.docstore.bucket, path, stream)
|
|
|
}
|
|
|
|
|
|
describe('Archiving', function () {
|
|
|
- before(function (done) {
|
|
|
- return DocstoreApp.ensureRunning(done)
|
|
|
+ before(async function () {
|
|
|
+ await DocstoreApp.ensureRunning()
|
|
|
})
|
|
|
|
|
|
before(async function () {
|
|
|
@@ -65,118 +51,100 @@ describe('Archiving', function () {
|
|
|
version: 4,
|
|
|
},
|
|
|
]
|
|
|
- const jobs = Array.from(this.docs).map(doc =>
|
|
|
- (doc => {
|
|
|
- return callback => {
|
|
|
- return DocstoreClient.createDoc(
|
|
|
- this.project_id,
|
|
|
- doc._id,
|
|
|
- doc.lines,
|
|
|
- doc.version,
|
|
|
- doc.ranges,
|
|
|
- callback
|
|
|
- )
|
|
|
- }
|
|
|
+ const jobs = this.docs.map(doc =>
|
|
|
+ (doc => callback => {
|
|
|
+ callbackify(DocstoreClient.createDoc)(
|
|
|
+ this.project_id,
|
|
|
+ doc._id,
|
|
|
+ doc.lines,
|
|
|
+ doc.version,
|
|
|
+ doc.ranges,
|
|
|
+ callback
|
|
|
+ )
|
|
|
})(doc)
|
|
|
)
|
|
|
|
|
|
- return async.series(jobs, error => {
|
|
|
+ async.series(jobs, error => {
|
|
|
if (error != null) {
|
|
|
throw error
|
|
|
}
|
|
|
- return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
|
|
|
- if (error) return done(error)
|
|
|
- this.res = res
|
|
|
- return done()
|
|
|
- })
|
|
|
+ DocstoreClient.archiveAllDoc(this.project_id)
|
|
|
+ .then(res => {
|
|
|
+ this.res = res
|
|
|
+ done()
|
|
|
+ })
|
|
|
+ .catch(done)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('should archive all the docs', function (done) {
|
|
|
- this.res.statusCode.should.equal(204)
|
|
|
- return done()
|
|
|
+ it('should archive all the docs', function () {
|
|
|
+ this.res.status.should.equal(204)
|
|
|
})
|
|
|
|
|
|
it('should set inS3 and unset lines and ranges in each doc', function (done) {
|
|
|
- const jobs = Array.from(this.docs).map(doc =>
|
|
|
- (doc => {
|
|
|
- return callback => {
|
|
|
- return db.docs.findOne({ _id: doc._id }, (error, doc) => {
|
|
|
+ const jobs = this.docs.map(doc =>
|
|
|
+ (
|
|
|
+ doc => callback =>
|
|
|
+ db.docs.findOne({ _id: doc._id }, (error, doc) => {
|
|
|
if (error) return callback(error)
|
|
|
expect(doc.lines).not.to.exist
|
|
|
expect(doc.ranges).not.to.exist
|
|
|
doc.inS3.should.equal(true)
|
|
|
- return callback()
|
|
|
+ callback()
|
|
|
})
|
|
|
- }
|
|
|
- })(doc)
|
|
|
+ )(doc)
|
|
|
)
|
|
|
- return async.series(jobs, done)
|
|
|
+ async.series(jobs, done)
|
|
|
})
|
|
|
|
|
|
it('should set the docs in s3 correctly', function (done) {
|
|
|
- const jobs = Array.from(this.docs).map(doc =>
|
|
|
- (doc => {
|
|
|
- return callback => {
|
|
|
- return DocstoreClient.getS3Doc(
|
|
|
- this.project_id,
|
|
|
- doc._id,
|
|
|
- (error, s3Doc) => {
|
|
|
- if (error) return callback(error)
|
|
|
+ const jobs = this.docs.map(doc =>
|
|
|
+ (
|
|
|
+ doc => callback =>
|
|
|
+ DocstoreClient.getS3Doc(this.project_id, doc._id)
|
|
|
+ .then(s3Doc => {
|
|
|
s3Doc.lines.should.deep.equal(doc.lines)
|
|
|
s3Doc.ranges.should.deep.equal(doc.ranges)
|
|
|
callback()
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
- })(doc)
|
|
|
+ })
|
|
|
+ .catch(callback)
|
|
|
+ )(doc)
|
|
|
)
|
|
|
- return async.series(jobs, done)
|
|
|
+ async.series(jobs, done)
|
|
|
})
|
|
|
|
|
|
- return describe('after unarchiving from a request for the project', function () {
|
|
|
- before(function (done) {
|
|
|
- return DocstoreClient.getAllDocs(
|
|
|
- this.project_id,
|
|
|
- (error, res, fetchedDocs) => {
|
|
|
- this.fetched_docs = fetchedDocs
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
+ describe('after unarchiving from a request for the project', function () {
|
|
|
+ before(async function () {
|
|
|
+ this.fetched_docs = await DocstoreClient.getAllDocs(this.project_id)
|
|
|
})
|
|
|
|
|
|
- it('should return the docs', function (done) {
|
|
|
+ it('should return the docs', function () {
|
|
|
for (let i = 0; i < this.fetched_docs.length; i++) {
|
|
|
const doc = this.fetched_docs[i]
|
|
|
doc.lines.should.deep.equal(this.docs[i].lines)
|
|
|
}
|
|
|
- return done()
|
|
|
})
|
|
|
|
|
|
- return it('should restore the docs to mongo', function (done) {
|
|
|
- const jobs = Array.from(this.docs).map((doc, i) =>
|
|
|
- ((doc, i) => {
|
|
|
- return callback => {
|
|
|
- return db.docs.findOne({ _id: doc._id }, (error, doc) => {
|
|
|
+ it('should restore the docs to mongo', function (done) {
|
|
|
+ const jobs = this.docs.map((doc, i) =>
|
|
|
+ (
|
|
|
+ (doc, i) => callback =>
|
|
|
+ db.docs.findOne({ _id: doc._id }, (error, doc) => {
|
|
|
if (error) return callback(error)
|
|
|
doc.lines.should.deep.equal(this.docs[i].lines)
|
|
|
doc.ranges.should.deep.equal(this.docs[i].ranges)
|
|
|
expect(doc.inS3).not.to.exist
|
|
|
- return callback()
|
|
|
+ callback()
|
|
|
})
|
|
|
- }
|
|
|
- })(doc, i)
|
|
|
+ )(doc, i)
|
|
|
)
|
|
|
- return async.series(jobs, done)
|
|
|
+ async.series(jobs, done)
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('a deleted doc', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
+ beforeEach(async function () {
|
|
|
this.project_id = new ObjectId()
|
|
|
this.doc = {
|
|
|
_id: new ObjectId(),
|
|
|
@@ -184,102 +152,51 @@ describe('Archiving', function () {
|
|
|
ranges: {},
|
|
|
version: 2,
|
|
|
}
|
|
|
- return DocstoreClient.createDoc(
|
|
|
+
|
|
|
+ await DocstoreClient.createDoc(
|
|
|
this.project_id,
|
|
|
this.doc._id,
|
|
|
this.doc.lines,
|
|
|
this.doc.version,
|
|
|
- this.doc.ranges,
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return DocstoreClient.deleteDoc(
|
|
|
- this.project_id,
|
|
|
- this.doc._id,
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return DocstoreClient.archiveAllDoc(
|
|
|
- this.project_id,
|
|
|
- (error, res) => {
|
|
|
- this.res = res
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
+ this.doc.ranges
|
|
|
)
|
|
|
+ await DocstoreClient.deleteDoc(this.project_id, this.doc._id)
|
|
|
+ this.res = await DocstoreClient.archiveAllDoc(this.project_id)
|
|
|
})
|
|
|
|
|
|
- it('should successully archive the docs', function (done) {
|
|
|
- this.res.statusCode.should.equal(204)
|
|
|
- return done()
|
|
|
+ it('should successully archive the docs', function () {
|
|
|
+ this.res.status.should.equal(204)
|
|
|
})
|
|
|
|
|
|
- it('should set inS3 and unset lines and ranges in each doc', function (done) {
|
|
|
- return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- expect(doc.lines).not.to.exist
|
|
|
- expect(doc.ranges).not.to.exist
|
|
|
- doc.inS3.should.equal(true)
|
|
|
- doc.deleted.should.equal(true)
|
|
|
- return done()
|
|
|
- })
|
|
|
+ it('should set inS3 and unset lines and ranges in each doc', async function () {
|
|
|
+ const doc = await db.docs.findOne({ _id: this.doc._id })
|
|
|
+ expect(doc.lines).not.to.exist
|
|
|
+ expect(doc.ranges).not.to.exist
|
|
|
+ doc.inS3.should.equal(true)
|
|
|
+ doc.deleted.should.equal(true)
|
|
|
})
|
|
|
|
|
|
- it('should set the doc in s3 correctly', function (done) {
|
|
|
- return DocstoreClient.getS3Doc(
|
|
|
- this.project_id,
|
|
|
- this.doc._id,
|
|
|
- (error, s3Doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- s3Doc.lines.should.deep.equal(this.doc.lines)
|
|
|
- s3Doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
+ it('should set the doc in s3 correctly', async function () {
|
|
|
+ const s3Doc = await DocstoreClient.getS3Doc(this.project_id, this.doc._id)
|
|
|
+ s3Doc.lines.should.deep.equal(this.doc.lines)
|
|
|
+ s3Doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
})
|
|
|
|
|
|
describe('after unarchiving from a request for the project', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
- return DocstoreClient.getAllDocs(
|
|
|
- this.project_id,
|
|
|
- (error, res, fetchedDocs) => {
|
|
|
- this.fetched_docs = fetchedDocs
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
+ beforeEach(async function () {
|
|
|
+ this.fetched_docs = await DocstoreClient.getAllDocs(this.project_id)
|
|
|
})
|
|
|
|
|
|
- it('should not included the deleted', function (done) {
|
|
|
+ it('should not included the deleted', function () {
|
|
|
this.fetched_docs.length.should.equal(0)
|
|
|
- return done()
|
|
|
})
|
|
|
|
|
|
- return it('should restore the doc to mongo', function (done) {
|
|
|
- return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- doc.lines.should.deep.equal(this.doc.lines)
|
|
|
- doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
- expect(doc.inS3).not.to.exist
|
|
|
- doc.deleted.should.equal(true)
|
|
|
- return done()
|
|
|
- })
|
|
|
+ it('should restore the doc to mongo', async function () {
|
|
|
+ const doc = await db.docs.findOne({ _id: this.doc._id })
|
|
|
+ doc.lines.should.deep.equal(this.doc.lines)
|
|
|
+ doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
+ expect(doc.inS3).not.to.exist
|
|
|
+ doc.deleted.should.equal(true)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -296,42 +213,27 @@ describe('Archiving', function () {
|
|
|
})
|
|
|
|
|
|
describe('after unarchiving from a request for the project', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
- DocstoreClient.getAllDocs(
|
|
|
- this.project_id,
|
|
|
- (error, res, fetchedDocs) => {
|
|
|
- this.fetched_docs = fetchedDocs
|
|
|
- if (error) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
+ beforeEach(async function () {
|
|
|
+ this.fetched_docs = await DocstoreClient.getAllDocs(this.project_id)
|
|
|
})
|
|
|
|
|
|
- it('should not included the deleted', function (done) {
|
|
|
+ it('should not included the deleted', function () {
|
|
|
this.fetched_docs.length.should.equal(0)
|
|
|
- done()
|
|
|
})
|
|
|
|
|
|
- it('should not have restored the deleted doc to mongo', function (done) {
|
|
|
- db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
|
|
- if (error) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- expect(doc.lines).to.not.exist
|
|
|
- expect(doc.ranges).to.not.exist
|
|
|
- expect(doc.inS3).to.equal(true)
|
|
|
- expect(doc.deleted).to.equal(true)
|
|
|
- done()
|
|
|
- })
|
|
|
+ it('should not have restored the deleted doc to mongo', async function () {
|
|
|
+ const doc = await db.docs.findOne({ _id: this.doc._id })
|
|
|
+ expect(doc.lines).to.not.exist
|
|
|
+ expect(doc.ranges).to.not.exist
|
|
|
+ expect(doc.inS3).to.equal(true)
|
|
|
+ expect(doc.deleted).to.equal(true)
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('archiving a single doc', function () {
|
|
|
- before(function (done) {
|
|
|
+ before(async function () {
|
|
|
this.project_id = new ObjectId()
|
|
|
this.timeout(1000 * 30)
|
|
|
this.doc = {
|
|
|
@@ -340,62 +242,36 @@ describe('Archiving', function () {
|
|
|
ranges: {},
|
|
|
version: 2,
|
|
|
}
|
|
|
- DocstoreClient.createDoc(
|
|
|
+ await DocstoreClient.createDoc(
|
|
|
this.project_id,
|
|
|
this.doc._id,
|
|
|
this.doc.lines,
|
|
|
this.doc.version,
|
|
|
- this.doc.ranges,
|
|
|
- error => {
|
|
|
- if (error) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- DocstoreClient.archiveDoc(
|
|
|
- this.project_id,
|
|
|
- this.doc._id,
|
|
|
- (error, res) => {
|
|
|
- this.res = res
|
|
|
- if (error) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
+ this.doc.ranges
|
|
|
)
|
|
|
+ this.res = await DocstoreClient.archiveDoc(this.project_id, this.doc._id)
|
|
|
})
|
|
|
|
|
|
- it('should successully archive the doc', function (done) {
|
|
|
- this.res.statusCode.should.equal(204)
|
|
|
- done()
|
|
|
+ it('should successully archive the doc', function () {
|
|
|
+ this.res.status.should.equal(204)
|
|
|
})
|
|
|
|
|
|
- it('should set inS3 and unset lines and ranges in the doc', function (done) {
|
|
|
- db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
|
|
- if (error) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- expect(doc.lines).not.to.exist
|
|
|
- expect(doc.ranges).not.to.exist
|
|
|
- doc.inS3.should.equal(true)
|
|
|
- done()
|
|
|
- })
|
|
|
+ it('should set inS3 and unset lines and ranges in the doc', async function () {
|
|
|
+ const doc = await db.docs.findOne({ _id: this.doc._id })
|
|
|
+ expect(doc.lines).not.to.exist
|
|
|
+ expect(doc.ranges).not.to.exist
|
|
|
+ doc.inS3.should.equal(true)
|
|
|
})
|
|
|
|
|
|
- it('should set the doc in s3 correctly', function (done) {
|
|
|
- DocstoreClient.getS3Doc(this.project_id, this.doc._id, (error, s3Doc) => {
|
|
|
- if (error) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- s3Doc.lines.should.deep.equal(this.doc.lines)
|
|
|
- s3Doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
- done()
|
|
|
- })
|
|
|
+ it('should set the doc in s3 correctly', async function () {
|
|
|
+ const s3Doc = await DocstoreClient.getS3Doc(this.project_id, this.doc._id)
|
|
|
+ s3Doc.lines.should.deep.equal(this.doc.lines)
|
|
|
+ s3Doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('a doc with large lines', function () {
|
|
|
- before(function (done) {
|
|
|
+ before(async function () {
|
|
|
this.project_id = new ObjectId()
|
|
|
this.timeout(1000 * 30)
|
|
|
const quarterMegInBytes = 250000
|
|
|
@@ -408,89 +284,49 @@ describe('Archiving', function () {
|
|
|
ranges: {},
|
|
|
version: 2,
|
|
|
}
|
|
|
- return DocstoreClient.createDoc(
|
|
|
+ await DocstoreClient.createDoc(
|
|
|
this.project_id,
|
|
|
this.doc._id,
|
|
|
this.doc.lines,
|
|
|
this.doc.version,
|
|
|
- this.doc.ranges,
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
|
|
|
- this.res = res
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return done()
|
|
|
- })
|
|
|
- }
|
|
|
+ this.doc.ranges
|
|
|
)
|
|
|
+ this.res = await DocstoreClient.archiveAllDoc(this.project_id)
|
|
|
})
|
|
|
|
|
|
- it('should successully archive the docs', function (done) {
|
|
|
- this.res.statusCode.should.equal(204)
|
|
|
- return done()
|
|
|
+ it('should successully archive the docs', function () {
|
|
|
+ this.res.status.should.equal(204)
|
|
|
})
|
|
|
|
|
|
- it('should set inS3 and unset lines and ranges in each doc', function (done) {
|
|
|
- return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- expect(doc.lines).not.to.exist
|
|
|
- expect(doc.ranges).not.to.exist
|
|
|
- doc.inS3.should.equal(true)
|
|
|
- return done()
|
|
|
- })
|
|
|
+ it('should set inS3 and unset lines and ranges in each doc', async function () {
|
|
|
+ const doc = await db.docs.findOne({ _id: this.doc._id })
|
|
|
+ expect(doc.lines).not.to.exist
|
|
|
+ expect(doc.ranges).not.to.exist
|
|
|
+ doc.inS3.should.equal(true)
|
|
|
})
|
|
|
|
|
|
- it('should set the doc in s3 correctly', function (done) {
|
|
|
- return DocstoreClient.getS3Doc(
|
|
|
- this.project_id,
|
|
|
- this.doc._id,
|
|
|
- (error, s3Doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- s3Doc.lines.should.deep.equal(this.doc.lines)
|
|
|
- s3Doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
+ it('should set the doc in s3 correctly', async function () {
|
|
|
+ const s3Doc = await DocstoreClient.getS3Doc(this.project_id, this.doc._id)
|
|
|
+ s3Doc.lines.should.deep.equal(this.doc.lines)
|
|
|
+ s3Doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
})
|
|
|
|
|
|
- return describe('after unarchiving from a request for the project', function () {
|
|
|
- before(function (done) {
|
|
|
- return DocstoreClient.getAllDocs(
|
|
|
- this.project_id,
|
|
|
- (error, res, fetchedDocs) => {
|
|
|
- this.fetched_docs = fetchedDocs
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
+ describe('after unarchiving from a request for the project', function () {
|
|
|
+ before(async function () {
|
|
|
+ this.fetched_docs = await DocstoreClient.getAllDocs(this.project_id)
|
|
|
})
|
|
|
|
|
|
- return it('should restore the doc to mongo', function (done) {
|
|
|
- return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- doc.lines.should.deep.equal(this.doc.lines)
|
|
|
- doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
- expect(doc.inS3).not.to.exist
|
|
|
- return done()
|
|
|
- })
|
|
|
+ it('should restore the doc to mongo', async function () {
|
|
|
+ const doc = await db.docs.findOne({ _id: this.doc._id })
|
|
|
+ doc.lines.should.deep.equal(this.doc.lines)
|
|
|
+ doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
+ expect(doc.inS3).not.to.exist
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('a doc with naughty strings', function () {
|
|
|
- before(function (done) {
|
|
|
+ before(async function () {
|
|
|
this.project_id = new ObjectId()
|
|
|
this.doc = {
|
|
|
_id: new ObjectId(),
|
|
|
@@ -882,89 +718,48 @@ describe('Archiving', function () {
|
|
|
ranges: {},
|
|
|
version: 2,
|
|
|
}
|
|
|
- return DocstoreClient.createDoc(
|
|
|
+ await DocstoreClient.createDoc(
|
|
|
this.project_id,
|
|
|
this.doc._id,
|
|
|
this.doc.lines,
|
|
|
this.doc.version,
|
|
|
- this.doc.ranges,
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
|
|
|
- this.res = res
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return done()
|
|
|
- })
|
|
|
- }
|
|
|
+ this.doc.ranges
|
|
|
)
|
|
|
+ this.res = await DocstoreClient.archiveAllDoc(this.project_id)
|
|
|
})
|
|
|
|
|
|
- it('should successully archive the docs', function (done) {
|
|
|
- this.res.statusCode.should.equal(204)
|
|
|
- return done()
|
|
|
+ it('should successully archive the docs', function () {
|
|
|
+ this.res.status.should.equal(204)
|
|
|
})
|
|
|
|
|
|
- it('should set inS3 and unset lines and ranges in each doc', function (done) {
|
|
|
- return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- expect(doc.lines).not.to.exist
|
|
|
- expect(doc.ranges).not.to.exist
|
|
|
- doc.inS3.should.equal(true)
|
|
|
- return done()
|
|
|
- })
|
|
|
+ it('should set inS3 and unset lines and ranges in each doc', async function () {
|
|
|
+ const doc = await db.docs.findOne({ _id: this.doc._id })
|
|
|
+ expect(doc.lines).not.to.exist
|
|
|
+ expect(doc.ranges).not.to.exist
|
|
|
+ doc.inS3.should.equal(true)
|
|
|
})
|
|
|
|
|
|
- it('should set the doc in s3 correctly', function (done) {
|
|
|
- return DocstoreClient.getS3Doc(
|
|
|
- this.project_id,
|
|
|
- this.doc._id,
|
|
|
- (error, s3Doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- s3Doc.lines.should.deep.equal(this.doc.lines)
|
|
|
- s3Doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
+ it('should set the doc in s3 correctly', async function () {
|
|
|
+ const s3Doc = await DocstoreClient.getS3Doc(this.project_id, this.doc._id)
|
|
|
+ s3Doc.lines.should.deep.equal(this.doc.lines)
|
|
|
+ s3Doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
})
|
|
|
|
|
|
- return describe('after unarchiving from a request for the project', function () {
|
|
|
- before(function (done) {
|
|
|
- return DocstoreClient.getAllDocs(
|
|
|
- this.project_id,
|
|
|
- (error, res, fetchedDocs) => {
|
|
|
- this.fetched_docs = fetchedDocs
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
+ describe('after unarchiving from a request for the project', function () {
|
|
|
+ before(async function () {
|
|
|
+ this.fetched_docs = await DocstoreClient.getAllDocs(this.project_id)
|
|
|
})
|
|
|
|
|
|
- return it('should restore the doc to mongo', function (done) {
|
|
|
- return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- doc.lines.should.deep.equal(this.doc.lines)
|
|
|
- doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
- expect(doc.inS3).not.to.exist
|
|
|
- return done()
|
|
|
- })
|
|
|
+ it('should restore the doc to mongo', async function () {
|
|
|
+ const doc = await db.docs.findOne({ _id: this.doc._id })
|
|
|
+ doc.lines.should.deep.equal(this.doc.lines)
|
|
|
+ doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('a doc with ranges', function () {
|
|
|
- before(function (done) {
|
|
|
+ before(async function () {
|
|
|
this.project_id = new ObjectId()
|
|
|
this.doc = {
|
|
|
_id: new ObjectId(),
|
|
|
@@ -1010,90 +805,50 @@ describe('Archiving', function () {
|
|
|
},
|
|
|
],
|
|
|
}
|
|
|
- return DocstoreClient.createDoc(
|
|
|
+ await DocstoreClient.createDoc(
|
|
|
this.project_id,
|
|
|
this.doc._id,
|
|
|
this.doc.lines,
|
|
|
this.doc.version,
|
|
|
- this.doc.ranges,
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
|
|
|
- this.res = res
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return done()
|
|
|
- })
|
|
|
- }
|
|
|
+ this.doc.ranges
|
|
|
)
|
|
|
+ this.res = await DocstoreClient.archiveAllDoc(this.project_id)
|
|
|
})
|
|
|
|
|
|
- it('should successully archive the docs', function (done) {
|
|
|
- this.res.statusCode.should.equal(204)
|
|
|
- return done()
|
|
|
+ it('should successully archive the docs', function () {
|
|
|
+ this.res.status.should.equal(204)
|
|
|
})
|
|
|
|
|
|
- it('should set inS3 and unset lines and ranges in each doc', function (done) {
|
|
|
- return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- expect(doc.lines).not.to.exist
|
|
|
- expect(doc.ranges).not.to.exist
|
|
|
- doc.inS3.should.equal(true)
|
|
|
- return done()
|
|
|
- })
|
|
|
+ it('should set inS3 and unset lines and ranges in each doc', async function () {
|
|
|
+ const doc = await db.docs.findOne({ _id: this.doc._id })
|
|
|
+ expect(doc.lines).not.to.exist
|
|
|
+ expect(doc.ranges).not.to.exist
|
|
|
+ doc.inS3.should.equal(true)
|
|
|
})
|
|
|
|
|
|
- it('should set the doc in s3 correctly', function (done) {
|
|
|
- return DocstoreClient.getS3Doc(
|
|
|
- this.project_id,
|
|
|
- this.doc._id,
|
|
|
- (error, s3Doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- s3Doc.lines.should.deep.equal(this.doc.lines)
|
|
|
- const ranges = JSON.parse(JSON.stringify(this.fixedRanges)) // ObjectId -> String
|
|
|
- s3Doc.ranges.should.deep.equal(ranges)
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
+ it('should set the doc in s3 correctly', async function () {
|
|
|
+ const s3Doc = await DocstoreClient.getS3Doc(this.project_id, this.doc._id)
|
|
|
+ s3Doc.lines.should.deep.equal(this.doc.lines)
|
|
|
+ const ranges = JSON.parse(JSON.stringify(this.fixedRanges)) // ObjectId -> String
|
|
|
+ s3Doc.ranges.should.deep.equal(ranges)
|
|
|
})
|
|
|
|
|
|
- return describe('after unarchiving from a request for the project', function () {
|
|
|
- before(function (done) {
|
|
|
- return DocstoreClient.getAllDocs(
|
|
|
- this.project_id,
|
|
|
- (error, res, fetchedDocs) => {
|
|
|
- this.fetched_docs = fetchedDocs
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
+ describe('after unarchiving from a request for the project', function () {
|
|
|
+ before(async function () {
|
|
|
+ this.fetched_docs = await DocstoreClient.getAllDocs(this.project_id)
|
|
|
})
|
|
|
|
|
|
- return it('should restore the doc to mongo', function (done) {
|
|
|
- return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- doc.lines.should.deep.equal(this.doc.lines)
|
|
|
- doc.ranges.should.deep.equal(this.fixedRanges)
|
|
|
- expect(doc.inS3).not.to.exist
|
|
|
- return done()
|
|
|
- })
|
|
|
+ it('should restore the doc to mongo', async function () {
|
|
|
+ const doc = await db.docs.findOne({ _id: this.doc._id })
|
|
|
+ doc.lines.should.deep.equal(this.doc.lines)
|
|
|
+ doc.ranges.should.deep.equal(this.fixedRanges)
|
|
|
+ expect(doc.inS3).not.to.exist
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('a doc that is archived twice', function () {
|
|
|
- before(function (done) {
|
|
|
+ before(async function () {
|
|
|
this.project_id = new ObjectId()
|
|
|
this.doc = {
|
|
|
_id: new ObjectId(),
|
|
|
@@ -1101,95 +856,50 @@ describe('Archiving', function () {
|
|
|
ranges: {},
|
|
|
version: 2,
|
|
|
}
|
|
|
- return DocstoreClient.createDoc(
|
|
|
+ await DocstoreClient.createDoc(
|
|
|
this.project_id,
|
|
|
this.doc._id,
|
|
|
this.doc.lines,
|
|
|
this.doc.version,
|
|
|
- this.doc.ranges,
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return DocstoreClient.archiveAllDoc(this.project_id, (error, res) => {
|
|
|
- this.res = res
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- this.res.statusCode.should.equal(204)
|
|
|
- return DocstoreClient.archiveAllDoc(
|
|
|
- this.project_id,
|
|
|
- (error, res1) => {
|
|
|
- this.res = res1
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- this.res.statusCode.should.equal(204)
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
- }
|
|
|
+ this.doc.ranges
|
|
|
)
|
|
|
+
|
|
|
+ this.res = await DocstoreClient.archiveAllDoc(this.project_id)
|
|
|
+ this.res.status.should.equal(204)
|
|
|
+
|
|
|
+ this.res = await DocstoreClient.archiveAllDoc(this.project_id)
|
|
|
+ this.res.status.should.equal(204)
|
|
|
})
|
|
|
|
|
|
- it('should set inS3 and unset lines and ranges in each doc', function (done) {
|
|
|
- return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- expect(doc.lines).not.to.exist
|
|
|
- expect(doc.ranges).not.to.exist
|
|
|
- doc.inS3.should.equal(true)
|
|
|
- return done()
|
|
|
- })
|
|
|
+ it('should set inS3 and unset lines and ranges in each doc', async function () {
|
|
|
+ const doc = await db.docs.findOne({ _id: this.doc._id })
|
|
|
+ expect(doc.lines).not.to.exist
|
|
|
+ expect(doc.ranges).not.to.exist
|
|
|
+ doc.inS3.should.equal(true)
|
|
|
})
|
|
|
|
|
|
- it('should set the doc in s3 correctly', function (done) {
|
|
|
- return DocstoreClient.getS3Doc(
|
|
|
- this.project_id,
|
|
|
- this.doc._id,
|
|
|
- (error, s3Doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- s3Doc.lines.should.deep.equal(this.doc.lines)
|
|
|
- s3Doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
+ it('should set the doc in s3 correctly', async function () {
|
|
|
+ const s3Doc = await DocstoreClient.getS3Doc(this.project_id, this.doc._id)
|
|
|
+ s3Doc.lines.should.deep.equal(this.doc.lines)
|
|
|
+ s3Doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
})
|
|
|
|
|
|
- return describe('after unarchiving from a request for the project', function () {
|
|
|
- before(function (done) {
|
|
|
- return DocstoreClient.getAllDocs(
|
|
|
- this.project_id,
|
|
|
- (error, res, fetchedDocs) => {
|
|
|
- this.fetched_docs = fetchedDocs
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
+ describe('after unarchiving from a request for the project', function () {
|
|
|
+ before(async function () {
|
|
|
+ this.fetched_docs = await DocstoreClient.getAllDocs(this.project_id)
|
|
|
})
|
|
|
|
|
|
- return it('should restore the doc to mongo', function (done) {
|
|
|
- return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- doc.lines.should.deep.equal(this.doc.lines)
|
|
|
- doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
- expect(doc.inS3).not.to.exist
|
|
|
- return done()
|
|
|
- })
|
|
|
+ it('should restore the doc to mongo', async function () {
|
|
|
+ const doc = await db.docs.findOne({ _id: this.doc._id })
|
|
|
+ doc.lines.should.deep.equal(this.doc.lines)
|
|
|
+ doc.ranges.should.deep.equal(this.doc.ranges)
|
|
|
+ expect(doc.inS3).not.to.exist
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- return describe('a doc with the old schema (just an array of lines)', function () {
|
|
|
- before(function (done) {
|
|
|
+ describe('a doc with the old schema (just an array of lines)', function () {
|
|
|
+ before(async function () {
|
|
|
this.project_id = new ObjectId()
|
|
|
this.doc = {
|
|
|
_id: new ObjectId(),
|
|
|
@@ -1197,52 +907,24 @@ describe('Archiving', function () {
|
|
|
ranges: {},
|
|
|
version: 2,
|
|
|
}
|
|
|
- uploadContent(
|
|
|
- `${this.project_id}/${this.doc._id}`,
|
|
|
- this.doc.lines,
|
|
|
- error => {
|
|
|
- expect(error).not.to.exist
|
|
|
- db.docs.insertOne(
|
|
|
- {
|
|
|
- project_id: this.project_id,
|
|
|
- _id: this.doc._id,
|
|
|
- rev: this.doc.version,
|
|
|
- inS3: true,
|
|
|
- },
|
|
|
- error => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- DocstoreClient.getAllDocs(
|
|
|
- this.project_id,
|
|
|
- (error, res, fetchedDocs) => {
|
|
|
- this.fetched_docs = fetchedDocs
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
- )
|
|
|
+ await uploadContent(`${this.project_id}/${this.doc._id}`, this.doc.lines)
|
|
|
+ await db.docs.insertOne({
|
|
|
+ project_id: this.project_id,
|
|
|
+ _id: this.doc._id,
|
|
|
+ rev: this.doc.version,
|
|
|
+ inS3: true,
|
|
|
+ })
|
|
|
+ this.fetched_docs = await DocstoreClient.getAllDocs(this.project_id)
|
|
|
})
|
|
|
|
|
|
- it('should restore the doc to mongo', function (done) {
|
|
|
- return db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
|
|
- if (error != null) {
|
|
|
- throw error
|
|
|
- }
|
|
|
- doc.lines.should.deep.equal(this.doc.lines)
|
|
|
- expect(doc.inS3).not.to.exist
|
|
|
- return done()
|
|
|
- })
|
|
|
+ it('should restore the doc to mongo', async function () {
|
|
|
+ const doc = await db.docs.findOne({ _id: this.doc._id })
|
|
|
+ doc.lines.should.deep.equal(this.doc.lines)
|
|
|
+ expect(doc.inS3).not.to.exist
|
|
|
})
|
|
|
|
|
|
- return it('should return the doc', function (done) {
|
|
|
+ it('should return the doc', function () {
|
|
|
this.fetched_docs[0].lines.should.deep.equal(this.doc.lines)
|
|
|
- return done()
|
|
|
})
|
|
|
})
|
|
|
})
|