mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
[misc] run format_fix and lint:fix
This commit is contained in:
parent
679ea1616c
commit
540b52c128
23 changed files with 394 additions and 387 deletions
|
@ -13,7 +13,7 @@ const bodyParser = require('body-parser')
|
||||||
const {
|
const {
|
||||||
celebrate: validate,
|
celebrate: validate,
|
||||||
Joi,
|
Joi,
|
||||||
errors: handleValidationErrors
|
errors: handleValidationErrors,
|
||||||
} = require('celebrate')
|
} = require('celebrate')
|
||||||
const mongodb = require('./app/js/mongodb')
|
const mongodb = require('./app/js/mongodb')
|
||||||
const Errors = require('./app/js/Errors')
|
const Errors = require('./app/js/Errors')
|
||||||
|
@ -67,8 +67,8 @@ app.patch(
|
||||||
body: {
|
body: {
|
||||||
deleted: Joi.boolean(),
|
deleted: Joi.boolean(),
|
||||||
name: Joi.string().when('deleted', { is: true, then: Joi.required() }),
|
name: Joi.string().when('deleted', { is: true, then: Joi.required() }),
|
||||||
deletedAt: Joi.date().when('deleted', { is: true, then: Joi.required() })
|
deletedAt: Joi.date().when('deleted', { is: true, then: Joi.required() }),
|
||||||
}
|
},
|
||||||
}),
|
}),
|
||||||
HttpController.patchDoc
|
HttpController.patchDoc
|
||||||
)
|
)
|
||||||
|
@ -111,7 +111,7 @@ if (!module.parent) {
|
||||||
return logger.info(`Docstore starting up, listening on ${host}:${port}`)
|
return logger.info(`Docstore starting up, listening on ${host}:${port}`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
logger.fatal({ err }, 'Cannot connect to mongo. Exiting.')
|
logger.fatal({ err }, 'Cannot connect to mongo. Exiting.')
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
})
|
})
|
||||||
|
|
|
@ -30,8 +30,8 @@ module.exports = {
|
||||||
unArchiveAllDocs,
|
unArchiveAllDocs,
|
||||||
unarchiveDoc,
|
unarchiveDoc,
|
||||||
destroyAllDocs,
|
destroyAllDocs,
|
||||||
destroyDoc
|
destroyDoc,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
async function archiveAllDocs(projectId) {
|
async function archiveAllDocs(projectId) {
|
||||||
|
@ -44,8 +44,8 @@ async function archiveAllDocs(projectId) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
await pMap(docs, (doc) => archiveDoc(projectId, doc), {
|
await pMap(docs, doc => archiveDoc(projectId, doc), {
|
||||||
concurrency: PARALLEL_JOBS
|
concurrency: PARALLEL_JOBS,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ async function archiveDocById(projectId, docId) {
|
||||||
lines: true,
|
lines: true,
|
||||||
ranges: true,
|
ranges: true,
|
||||||
rev: true,
|
rev: true,
|
||||||
inS3: true
|
inS3: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
|
@ -83,7 +83,7 @@ async function archiveDoc(projectId, doc) {
|
||||||
const json = JSON.stringify({
|
const json = JSON.stringify({
|
||||||
lines: doc.lines,
|
lines: doc.lines,
|
||||||
ranges: doc.ranges,
|
ranges: doc.ranges,
|
||||||
schema_v: 1
|
schema_v: 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
// this should never happen, but protects against memory-corruption errors that
|
// this should never happen, but protects against memory-corruption errors that
|
||||||
|
@ -97,7 +97,7 @@ async function archiveDoc(projectId, doc) {
|
||||||
const md5 = crypto.createHash('md5').update(json).digest('hex')
|
const md5 = crypto.createHash('md5').update(json).digest('hex')
|
||||||
const stream = Streamifier.createReadStream(json)
|
const stream = Streamifier.createReadStream(json)
|
||||||
await PersistorManager.sendStream(settings.docstore.bucket, key, stream, {
|
await PersistorManager.sendStream(settings.docstore.bucket, key, stream, {
|
||||||
sourceMd5: md5
|
sourceMd5: md5,
|
||||||
})
|
})
|
||||||
await MongoManager.markDocAsArchived(doc._id, doc.rev)
|
await MongoManager.markDocAsArchived(doc._id, doc.rev)
|
||||||
}
|
}
|
||||||
|
@ -119,8 +119,8 @@ async function unArchiveAllDocs(projectId) {
|
||||||
if (!docs || docs.length === 0) {
|
if (!docs || docs.length === 0) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
await pMap(docs, (doc) => unarchiveDoc(projectId, doc._id), {
|
await pMap(docs, doc => unarchiveDoc(projectId, doc._id), {
|
||||||
concurrency: PARALLEL_JOBS
|
concurrency: PARALLEL_JOBS,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ async function unarchiveDoc(projectId, docId) {
|
||||||
throw new Errors.Md5MismatchError('md5 mismatch when downloading doc', {
|
throw new Errors.Md5MismatchError('md5 mismatch when downloading doc', {
|
||||||
key,
|
key,
|
||||||
sourceMd5,
|
sourceMd5,
|
||||||
md5
|
md5,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,8 +195,8 @@ async function destroyAllDocs(projectId) {
|
||||||
if (!docs || docs.length === 0) {
|
if (!docs || docs.length === 0) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
await pMap(docs, (doc) => destroyDoc(projectId, doc._id), {
|
await pMap(docs, doc => destroyDoc(projectId, doc._id), {
|
||||||
concurrency: PARALLEL_JOBS
|
concurrency: PARALLEL_JOBS,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ async function destroyDoc(projectId, docId) {
|
||||||
'removing doc from mongo and persistor'
|
'removing doc from mongo and persistor'
|
||||||
)
|
)
|
||||||
const doc = await MongoManager.findDoc(projectId, docId, {
|
const doc = await MongoManager.findDoc(projectId, docId, {
|
||||||
inS3: 1
|
inS3: 1,
|
||||||
})
|
})
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
throw new Errors.NotFoundError('Doc not found in Mongo')
|
throw new Errors.NotFoundError('Doc not found in Mongo')
|
||||||
|
@ -243,7 +243,7 @@ async function destroyArchiveWithRetry(projectId, docId) {
|
||||||
async function _streamToString(stream) {
|
async function _streamToString(stream) {
|
||||||
const chunks = []
|
const chunks = []
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
stream.on('data', (chunk) => chunks.push(chunk))
|
stream.on('data', chunk => chunks.push(chunk))
|
||||||
stream.on('error', reject)
|
stream.on('error', reject)
|
||||||
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')))
|
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')))
|
||||||
})
|
})
|
||||||
|
|
|
@ -38,10 +38,11 @@ module.exports = DocManager = {
|
||||||
return callback('must include inS3 when getting doc')
|
return callback('must include inS3 when getting doc')
|
||||||
}
|
}
|
||||||
|
|
||||||
return MongoManager.findDoc(project_id, doc_id, filter, function (
|
return MongoManager.findDoc(
|
||||||
err,
|
project_id,
|
||||||
doc
|
doc_id,
|
||||||
) {
|
filter,
|
||||||
|
function (err, doc) {
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
} else if (doc == null) {
|
} else if (doc == null) {
|
||||||
|
@ -60,36 +61,44 @@ module.exports = DocManager = {
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (filter.version) {
|
if (filter.version) {
|
||||||
return MongoManager.getDocVersion(doc_id, function (error, version) {
|
return MongoManager.getDocVersion(
|
||||||
|
doc_id,
|
||||||
|
function (error, version) {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
}
|
}
|
||||||
doc.version = version
|
doc.version = version
|
||||||
return callback(err, doc)
|
return callback(err, doc)
|
||||||
})
|
}
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
return callback(err, doc)
|
return callback(err, doc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
isDocDeleted(projectId, docId, callback) {
|
isDocDeleted(projectId, docId, callback) {
|
||||||
MongoManager.findDoc(projectId, docId, { deleted: true }, function (
|
MongoManager.findDoc(
|
||||||
err,
|
projectId,
|
||||||
doc
|
docId,
|
||||||
) {
|
{ deleted: true },
|
||||||
|
function (err, doc) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
return callback(
|
return callback(
|
||||||
new Errors.NotFoundError(`No such project/doc: ${projectId}/${docId}`)
|
new Errors.NotFoundError(
|
||||||
|
`No such project/doc: ${projectId}/${docId}`
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// `doc.deleted` is `undefined` for non deleted docs
|
// `doc.deleted` is `undefined` for non deleted docs
|
||||||
callback(null, Boolean(doc.deleted))
|
callback(null, Boolean(doc.deleted))
|
||||||
})
|
}
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
getFullDoc(project_id, doc_id, callback) {
|
getFullDoc(project_id, doc_id, callback) {
|
||||||
|
@ -105,7 +114,7 @@ module.exports = DocManager = {
|
||||||
deleted: true,
|
deleted: true,
|
||||||
version: true,
|
version: true,
|
||||||
ranges: true,
|
ranges: true,
|
||||||
inS3: true
|
inS3: true,
|
||||||
},
|
},
|
||||||
function (err, doc) {
|
function (err, doc) {
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
|
@ -181,7 +190,7 @@ module.exports = DocManager = {
|
||||||
lines: true,
|
lines: true,
|
||||||
version: true,
|
version: true,
|
||||||
ranges: true,
|
ranges: true,
|
||||||
inS3: true
|
inS3: true,
|
||||||
},
|
},
|
||||||
function (err, doc) {
|
function (err, doc) {
|
||||||
let updateLines, updateRanges, updateVersion
|
let updateLines, updateRanges, updateVersion
|
||||||
|
@ -244,7 +253,7 @@ module.exports = DocManager = {
|
||||||
project_id,
|
project_id,
|
||||||
doc_id,
|
doc_id,
|
||||||
oldVersion: doc != null ? doc.version : undefined,
|
oldVersion: doc != null ? doc.version : undefined,
|
||||||
newVersion: version
|
newVersion: version,
|
||||||
},
|
},
|
||||||
'updating doc version'
|
'updating doc version'
|
||||||
)
|
)
|
||||||
|
@ -290,7 +299,7 @@ module.exports = DocManager = {
|
||||||
|
|
||||||
if (meta.deleted && Settings.docstore.archiveOnSoftDelete) {
|
if (meta.deleted && Settings.docstore.archiveOnSoftDelete) {
|
||||||
// The user will not read this doc anytime soon. Flush it out of mongo.
|
// The user will not read this doc anytime soon. Flush it out of mongo.
|
||||||
DocArchive.archiveDocById(project_id, doc_id, (err) => {
|
DocArchive.archiveDocById(project_id, doc_id, err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
{ project_id, doc_id, err },
|
{ project_id, doc_id, err },
|
||||||
|
@ -302,5 +311,5 @@ module.exports = DocManager = {
|
||||||
|
|
||||||
MongoManager.patchDoc(project_id, doc_id, meta, callback)
|
MongoManager.patchDoc(project_id, doc_id, meta, callback)
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,5 @@ class Md5MismatchError extends OError {}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Md5MismatchError,
|
Md5MismatchError,
|
||||||
...Errors
|
...Errors,
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,11 +26,11 @@ module.exports = {
|
||||||
const url = `http://localhost:${port}/project/${project_id}/doc/${doc_id}`
|
const url = `http://localhost:${port}/project/${project_id}/doc/${doc_id}`
|
||||||
const lines = [
|
const lines = [
|
||||||
'smoke test - delete me',
|
'smoke test - delete me',
|
||||||
`${crypto.randomBytes(32).toString('hex')}`
|
`${crypto.randomBytes(32).toString('hex')}`,
|
||||||
]
|
]
|
||||||
const getOpts = () => ({
|
const getOpts = () => ({
|
||||||
url,
|
url,
|
||||||
timeout: 3000
|
timeout: 3000,
|
||||||
})
|
})
|
||||||
logger.log({ lines, url, doc_id, project_id }, 'running health check')
|
logger.log({ lines, url, doc_id, project_id }, 'running health check')
|
||||||
const jobs = [
|
const jobs = [
|
||||||
|
@ -60,9 +60,9 @@ module.exports = {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
(cb) => db.docs.deleteOne({ _id: doc_id, project_id }, cb),
|
cb => db.docs.deleteOne({ _id: doc_id, project_id }, cb),
|
||||||
(cb) => db.docOps.deleteOne({ doc_id }, cb)
|
cb => db.docOps.deleteOne({ doc_id }, cb),
|
||||||
]
|
]
|
||||||
return async.series(jobs, callback)
|
return async.series(jobs, callback)
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,19 +98,20 @@ module.exports = HttpController = {
|
||||||
getAllDeletedDocs(req, res, next) {
|
getAllDeletedDocs(req, res, next) {
|
||||||
const { project_id } = req.params
|
const { project_id } = req.params
|
||||||
logger.log({ project_id }, 'getting all deleted docs')
|
logger.log({ project_id }, 'getting all deleted docs')
|
||||||
DocManager.getAllDeletedDocs(project_id, { name: true }, function (
|
DocManager.getAllDeletedDocs(
|
||||||
error,
|
project_id,
|
||||||
docs
|
{ name: true },
|
||||||
) {
|
function (error, docs) {
|
||||||
if (error) {
|
if (error) {
|
||||||
return next(error)
|
return next(error)
|
||||||
}
|
}
|
||||||
res.json(
|
res.json(
|
||||||
docs.map((doc) => {
|
docs.map(doc => {
|
||||||
return { _id: doc._id.toString(), name: doc.name }
|
return { _id: doc._id.toString(), name: doc.name }
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
getAllRanges(req, res, next) {
|
getAllRanges(req, res, next) {
|
||||||
|
@ -185,7 +186,7 @@ module.exports = HttpController = {
|
||||||
}
|
}
|
||||||
return res.json({
|
return res.json({
|
||||||
modified,
|
modified,
|
||||||
rev
|
rev,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -304,5 +305,5 @@ module.exports = HttpController = {
|
||||||
return res.sendStatus(200)
|
return res.sendStatus(200)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,10 @@ module.exports = MongoManager = {
|
||||||
db.docs.findOne(
|
db.docs.findOne(
|
||||||
{
|
{
|
||||||
_id: ObjectId(doc_id.toString()),
|
_id: ObjectId(doc_id.toString()),
|
||||||
project_id: ObjectId(project_id.toString())
|
project_id: ObjectId(project_id.toString()),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
projection: filter
|
projection: filter,
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
|
@ -39,12 +39,12 @@ module.exports = MongoManager = {
|
||||||
.find(
|
.find(
|
||||||
{
|
{
|
||||||
project_id: ObjectId(project_id.toString()),
|
project_id: ObjectId(project_id.toString()),
|
||||||
deleted: true
|
deleted: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
projection: filter,
|
projection: filter,
|
||||||
sort: { deletedAt: -1 },
|
sort: { deletedAt: -1 },
|
||||||
limit: Settings.max_deleted_docs
|
limit: Settings.max_deleted_docs,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.toArray(callback)
|
.toArray(callback)
|
||||||
|
@ -56,7 +56,7 @@ module.exports = MongoManager = {
|
||||||
query.deleted = { $ne: true }
|
query.deleted = { $ne: true }
|
||||||
}
|
}
|
||||||
const queryOptions = {
|
const queryOptions = {
|
||||||
projection: filter
|
projection: filter,
|
||||||
}
|
}
|
||||||
if (options.limit) {
|
if (options.limit) {
|
||||||
queryOptions.limit = options.limit
|
queryOptions.limit = options.limit
|
||||||
|
@ -67,7 +67,7 @@ module.exports = MongoManager = {
|
||||||
getArchivedProjectDocs(project_id, maxResults, callback) {
|
getArchivedProjectDocs(project_id, maxResults, callback) {
|
||||||
const query = {
|
const query = {
|
||||||
project_id: ObjectId(project_id.toString()),
|
project_id: ObjectId(project_id.toString()),
|
||||||
inS3: true
|
inS3: true,
|
||||||
}
|
}
|
||||||
db.docs
|
db.docs
|
||||||
.find(query, { projection: { _id: 1 }, limit: maxResults })
|
.find(query, { projection: { _id: 1 }, limit: maxResults })
|
||||||
|
@ -77,7 +77,7 @@ module.exports = MongoManager = {
|
||||||
getNonArchivedProjectDocs(project_id, maxResults, callback) {
|
getNonArchivedProjectDocs(project_id, maxResults, callback) {
|
||||||
const query = {
|
const query = {
|
||||||
project_id: ObjectId(project_id.toString()),
|
project_id: ObjectId(project_id.toString()),
|
||||||
inS3: { $ne: true }
|
inS3: { $ne: true },
|
||||||
}
|
}
|
||||||
db.docs.find(query, { limit: maxResults }).toArray(callback)
|
db.docs.find(query, { limit: maxResults }).toArray(callback)
|
||||||
},
|
},
|
||||||
|
@ -86,7 +86,7 @@ module.exports = MongoManager = {
|
||||||
const query = {
|
const query = {
|
||||||
project_id: ObjectId(project_id.toString()),
|
project_id: ObjectId(project_id.toString()),
|
||||||
deleted: { $ne: true },
|
deleted: { $ne: true },
|
||||||
inS3: true
|
inS3: true,
|
||||||
}
|
}
|
||||||
db.docs
|
db.docs
|
||||||
.find(query, { projection: { _id: 1 }, limit: maxResults })
|
.find(query, { projection: { _id: 1 }, limit: maxResults })
|
||||||
|
@ -97,11 +97,11 @@ module.exports = MongoManager = {
|
||||||
const update = {
|
const update = {
|
||||||
$set: updates,
|
$set: updates,
|
||||||
$inc: {
|
$inc: {
|
||||||
rev: 1
|
rev: 1,
|
||||||
},
|
},
|
||||||
$unset: {
|
$unset: {
|
||||||
inS3: true
|
inS3: true,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
update.$set.project_id = ObjectId(project_id)
|
update.$set.project_id = ObjectId(project_id)
|
||||||
db.docs.updateOne(
|
db.docs.updateOne(
|
||||||
|
@ -116,7 +116,7 @@ module.exports = MongoManager = {
|
||||||
db.docs.updateOne(
|
db.docs.updateOne(
|
||||||
{
|
{
|
||||||
_id: ObjectId(doc_id),
|
_id: ObjectId(doc_id),
|
||||||
project_id: ObjectId(project_id)
|
project_id: ObjectId(project_id),
|
||||||
},
|
},
|
||||||
{ $set: meta },
|
{ $set: meta },
|
||||||
callback
|
callback
|
||||||
|
@ -126,14 +126,14 @@ module.exports = MongoManager = {
|
||||||
markDocAsArchived(doc_id, rev, callback) {
|
markDocAsArchived(doc_id, rev, callback) {
|
||||||
const update = {
|
const update = {
|
||||||
$set: {},
|
$set: {},
|
||||||
$unset: {}
|
$unset: {},
|
||||||
}
|
}
|
||||||
update.$set.inS3 = true
|
update.$set.inS3 = true
|
||||||
update.$unset.lines = true
|
update.$unset.lines = true
|
||||||
update.$unset.ranges = true
|
update.$unset.ranges = true
|
||||||
const query = {
|
const query = {
|
||||||
_id: doc_id,
|
_id: doc_id,
|
||||||
rev
|
rev,
|
||||||
}
|
}
|
||||||
db.docs.updateOne(query, update, callback)
|
db.docs.updateOne(query, update, callback)
|
||||||
},
|
},
|
||||||
|
@ -144,12 +144,12 @@ module.exports = MongoManager = {
|
||||||
}
|
}
|
||||||
db.docOps.findOne(
|
db.docOps.findOne(
|
||||||
{
|
{
|
||||||
doc_id: ObjectId(doc_id)
|
doc_id: ObjectId(doc_id),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
projection: {
|
projection: {
|
||||||
version: 1
|
version: 1,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
function (error, doc) {
|
function (error, doc) {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
|
@ -166,13 +166,13 @@ module.exports = MongoManager = {
|
||||||
}
|
}
|
||||||
db.docOps.updateOne(
|
db.docOps.updateOne(
|
||||||
{
|
{
|
||||||
doc_id: ObjectId(doc_id)
|
doc_id: ObjectId(doc_id),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$set: { version }
|
$set: { version },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
upsert: true
|
upsert: true,
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
|
@ -181,7 +181,7 @@ module.exports = MongoManager = {
|
||||||
destroyDoc(doc_id, callback) {
|
destroyDoc(doc_id, callback) {
|
||||||
db.docs.deleteOne(
|
db.docs.deleteOne(
|
||||||
{
|
{
|
||||||
_id: ObjectId(doc_id)
|
_id: ObjectId(doc_id),
|
||||||
},
|
},
|
||||||
function (err) {
|
function (err) {
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
|
@ -189,13 +189,13 @@ module.exports = MongoManager = {
|
||||||
}
|
}
|
||||||
db.docOps.deleteOne(
|
db.docOps.deleteOne(
|
||||||
{
|
{
|
||||||
doc_id: ObjectId(doc_id)
|
doc_id: ObjectId(doc_id),
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const methods = Object.getOwnPropertyNames(MongoManager)
|
const methods = Object.getOwnPropertyNames(MongoManager)
|
||||||
|
|
|
@ -65,5 +65,5 @@ module.exports = RangeManager = {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,5 +32,5 @@ module.exports = {
|
||||||
db,
|
db,
|
||||||
ObjectId,
|
ObjectId,
|
||||||
addCollection,
|
addCollection,
|
||||||
waitForDb
|
waitForDb,
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,15 @@ const Settings = {
|
||||||
internal: {
|
internal: {
|
||||||
docstore: {
|
docstore: {
|
||||||
port: 3016,
|
port: 3016,
|
||||||
host: process.env.LISTEN_ADDRESS || 'localhost'
|
host: process.env.LISTEN_ADDRESS || 'localhost',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
mongo: {
|
mongo: {
|
||||||
options: {
|
options: {
|
||||||
useUnifiedTopology:
|
useUnifiedTopology:
|
||||||
(process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true'
|
(process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
docstore: {
|
docstore: {
|
||||||
|
@ -23,14 +23,14 @@ const Settings = {
|
||||||
|
|
||||||
backend: process.env.BACKEND || 's3',
|
backend: process.env.BACKEND || 's3',
|
||||||
healthCheck: {
|
healthCheck: {
|
||||||
project_id: process.env.HEALTH_CHECK_PROJECT_ID
|
project_id: process.env.HEALTH_CHECK_PROJECT_ID,
|
||||||
},
|
},
|
||||||
bucket: process.env.BUCKET_NAME || process.env.AWS_BUCKET || 'bucket',
|
bucket: process.env.BUCKET_NAME || process.env.AWS_BUCKET || 'bucket',
|
||||||
gcs: {
|
gcs: {
|
||||||
unlockBeforeDelete: process.env.GCS_UNLOCK_BEFORE_DELETE === 'true',
|
unlockBeforeDelete: process.env.GCS_UNLOCK_BEFORE_DELETE === 'true',
|
||||||
deletedBucketSuffix: process.env.GCS_DELETED_BUCKET_SUFFIX,
|
deletedBucketSuffix: process.env.GCS_DELETED_BUCKET_SUFFIX,
|
||||||
deleteConcurrency: parseInt(process.env.GCS_DELETE_CONCURRENCY) || 50
|
deleteConcurrency: parseInt(process.env.GCS_DELETE_CONCURRENCY) || 50,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
max_deleted_docs: parseInt(process.env.MAX_DELETED_DOCS, 10) || 2000,
|
max_deleted_docs: parseInt(process.env.MAX_DELETED_DOCS, 10) || 2000,
|
||||||
|
@ -41,7 +41,7 @@ const Settings = {
|
||||||
unArchiveBatchSize: parseInt(process.env.UN_ARCHIVE_BATCH_SIZE, 10) || 50,
|
unArchiveBatchSize: parseInt(process.env.UN_ARCHIVE_BATCH_SIZE, 10) || 50,
|
||||||
destroyBatchSize: parseInt(process.env.DESTROY_BATCH_SIZE, 10) || 2000,
|
destroyBatchSize: parseInt(process.env.DESTROY_BATCH_SIZE, 10) || 2000,
|
||||||
destroyRetryCount: parseInt(process.env.DESTROY_RETRY_COUNT || '3', 10),
|
destroyRetryCount: parseInt(process.env.DESTROY_RETRY_COUNT || '3', 10),
|
||||||
parallelArchiveJobs: parseInt(process.env.PARALLEL_ARCHIVE_JOBS, 10) || 5
|
parallelArchiveJobs: parseInt(process.env.PARALLEL_ARCHIVE_JOBS, 10) || 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.MONGO_CONNECTION_STRING) {
|
if (process.env.MONGO_CONNECTION_STRING) {
|
||||||
|
@ -63,7 +63,7 @@ if (
|
||||||
bucket: process.env.AWS_BUCKET,
|
bucket: process.env.AWS_BUCKET,
|
||||||
endpoint: process.env.AWS_S3_ENDPOINT,
|
endpoint: process.env.AWS_S3_ENDPOINT,
|
||||||
pathStyle: process.env.AWS_S3_PATH_STYLE,
|
pathStyle: process.env.AWS_S3_PATH_STYLE,
|
||||||
partSize: parseInt(process.env.AWS_S3_PARTSIZE) || 100 * 1024 * 1024
|
partSize: parseInt(process.env.AWS_S3_PARTSIZE) || 100 * 1024 * 1024,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ if (process.env.GCS_API_ENDPOINT) {
|
||||||
Settings.docstore.gcs.endpoint = {
|
Settings.docstore.gcs.endpoint = {
|
||||||
apiEndpoint: process.env.GCS_API_ENDPOINT,
|
apiEndpoint: process.env.GCS_API_ENDPOINT,
|
||||||
apiScheme: process.env.GCS_API_SCHEME,
|
apiScheme: process.env.GCS_API_SCHEME,
|
||||||
projectId: process.env.GCS_PROJECT_ID
|
projectId: process.env.GCS_PROJECT_ID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ if (process.env.FALLBACK_BACKEND) {
|
||||||
// mapping of bucket names on the fallback, to bucket names on the primary.
|
// mapping of bucket names on the fallback, to bucket names on the primary.
|
||||||
// e.g. { myS3UserFilesBucketName: 'myGoogleUserFilesBucketName' }
|
// e.g. { myS3UserFilesBucketName: 'myGoogleUserFilesBucketName' }
|
||||||
buckets: JSON.parse(process.env.FALLBACK_BUCKET_MAPPING || '{}'),
|
buckets: JSON.parse(process.env.FALLBACK_BUCKET_MAPPING || '{}'),
|
||||||
copyOnMiss: process.env.COPY_ON_MISS === 'true'
|
copyOnMiss: process.env.COPY_ON_MISS === 'true',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,18 +49,18 @@ describe('Archiving', function () {
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['one', 'two', 'three'],
|
lines: ['one', 'two', 'three'],
|
||||||
ranges: {},
|
ranges: {},
|
||||||
version: 2
|
version: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['aaa', 'bbb', 'ccc'],
|
lines: ['aaa', 'bbb', 'ccc'],
|
||||||
ranges: {},
|
ranges: {},
|
||||||
version: 4
|
version: 4,
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
const jobs = Array.from(this.docs).map((doc) =>
|
const jobs = Array.from(this.docs).map(doc =>
|
||||||
((doc) => {
|
(doc => {
|
||||||
return (callback) => {
|
return callback => {
|
||||||
return DocstoreClient.createDoc(
|
return DocstoreClient.createDoc(
|
||||||
this.project_id,
|
this.project_id,
|
||||||
doc._id,
|
doc._id,
|
||||||
|
@ -73,7 +73,7 @@ describe('Archiving', function () {
|
||||||
})(doc)
|
})(doc)
|
||||||
)
|
)
|
||||||
|
|
||||||
return async.series(jobs, (error) => {
|
return async.series(jobs, error => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
@ -90,9 +90,9 @@ describe('Archiving', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should set inS3 and unset lines and ranges in each doc', function (done) {
|
it('should set inS3 and unset lines and ranges in each doc', function (done) {
|
||||||
const jobs = Array.from(this.docs).map((doc) =>
|
const jobs = Array.from(this.docs).map(doc =>
|
||||||
((doc) => {
|
(doc => {
|
||||||
return (callback) => {
|
return callback => {
|
||||||
return db.docs.findOne({ _id: doc._id }, (error, doc) => {
|
return db.docs.findOne({ _id: doc._id }, (error, doc) => {
|
||||||
expect(doc.lines).not.to.exist
|
expect(doc.lines).not.to.exist
|
||||||
expect(doc.ranges).not.to.exist
|
expect(doc.ranges).not.to.exist
|
||||||
|
@ -106,9 +106,9 @@ describe('Archiving', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should set the docs in s3 correctly', function (done) {
|
it('should set the docs in s3 correctly', function (done) {
|
||||||
const jobs = Array.from(this.docs).map((doc) =>
|
const jobs = Array.from(this.docs).map(doc =>
|
||||||
((doc) => {
|
(doc => {
|
||||||
return (callback) => {
|
return callback => {
|
||||||
return DocstoreClient.getS3Doc(
|
return DocstoreClient.getS3Doc(
|
||||||
this.project_id,
|
this.project_id,
|
||||||
doc._id,
|
doc._id,
|
||||||
|
@ -149,7 +149,7 @@ describe('Archiving', function () {
|
||||||
return it('should restore the docs to mongo', function (done) {
|
return it('should restore the docs to mongo', function (done) {
|
||||||
const jobs = Array.from(this.docs).map((doc, i) =>
|
const jobs = Array.from(this.docs).map((doc, i) =>
|
||||||
((doc, i) => {
|
((doc, i) => {
|
||||||
return (callback) => {
|
return callback => {
|
||||||
return db.docs.findOne({ _id: doc._id }, (error, doc) => {
|
return db.docs.findOne({ _id: doc._id }, (error, doc) => {
|
||||||
doc.lines.should.deep.equal(this.docs[i].lines)
|
doc.lines.should.deep.equal(this.docs[i].lines)
|
||||||
doc.ranges.should.deep.equal(this.docs[i].ranges)
|
doc.ranges.should.deep.equal(this.docs[i].ranges)
|
||||||
|
@ -171,7 +171,7 @@ describe('Archiving', function () {
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['one', 'two', 'three'],
|
lines: ['one', 'two', 'three'],
|
||||||
ranges: {},
|
ranges: {},
|
||||||
version: 2
|
version: 2,
|
||||||
}
|
}
|
||||||
return DocstoreClient.createDoc(
|
return DocstoreClient.createDoc(
|
||||||
this.project_id,
|
this.project_id,
|
||||||
|
@ -179,14 +179,14 @@ describe('Archiving', function () {
|
||||||
this.doc.lines,
|
this.doc.lines,
|
||||||
this.doc.version,
|
this.doc.version,
|
||||||
this.doc.ranges,
|
this.doc.ranges,
|
||||||
(error) => {
|
error => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
return DocstoreClient.deleteDoc(
|
return DocstoreClient.deleteDoc(
|
||||||
this.project_id,
|
this.project_id,
|
||||||
this.doc._id,
|
this.doc._id,
|
||||||
(error) => {
|
error => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,8 @@ describe('Archiving', function () {
|
||||||
Settings.docstore.keepSoftDeletedDocsArchived = true
|
Settings.docstore.keepSoftDeletedDocsArchived = true
|
||||||
})
|
})
|
||||||
afterEach(function restoreSetting() {
|
afterEach(function restoreSetting() {
|
||||||
Settings.docstore.keepSoftDeletedDocsArchived = keepSoftDeletedDocsArchived
|
Settings.docstore.keepSoftDeletedDocsArchived =
|
||||||
|
keepSoftDeletedDocsArchived
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('after unarchiving from a request for the project', function () {
|
describe('after unarchiving from a request for the project', function () {
|
||||||
|
@ -326,7 +327,7 @@ describe('Archiving', function () {
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['foo', 'bar'],
|
lines: ['foo', 'bar'],
|
||||||
ranges: {},
|
ranges: {},
|
||||||
version: 2
|
version: 2,
|
||||||
}
|
}
|
||||||
DocstoreClient.createDoc(
|
DocstoreClient.createDoc(
|
||||||
this.project_id,
|
this.project_id,
|
||||||
|
@ -334,7 +335,7 @@ describe('Archiving', function () {
|
||||||
this.doc.lines,
|
this.doc.lines,
|
||||||
this.doc.version,
|
this.doc.version,
|
||||||
this.doc.ranges,
|
this.doc.ranges,
|
||||||
(error) => {
|
error => {
|
||||||
if (error) {
|
if (error) {
|
||||||
return done(error)
|
return done(error)
|
||||||
}
|
}
|
||||||
|
@ -398,7 +399,7 @@ describe('Archiving', function () {
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: [big_line, big_line, big_line, big_line],
|
lines: [big_line, big_line, big_line, big_line],
|
||||||
ranges: {},
|
ranges: {},
|
||||||
version: 2
|
version: 2,
|
||||||
}
|
}
|
||||||
return DocstoreClient.createDoc(
|
return DocstoreClient.createDoc(
|
||||||
this.project_id,
|
this.project_id,
|
||||||
|
@ -406,7 +407,7 @@ describe('Archiving', function () {
|
||||||
this.doc.lines,
|
this.doc.lines,
|
||||||
this.doc.version,
|
this.doc.version,
|
||||||
this.doc.ranges,
|
this.doc.ranges,
|
||||||
(error) => {
|
error => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
@ -869,10 +870,10 @@ describe('Archiving', function () {
|
||||||
'Roses are \u001b[0;31mred\u001b[0m, violets are \u001b[0;34mblue. Hope you enjoy terminal hue',
|
'Roses are \u001b[0;31mred\u001b[0m, violets are \u001b[0;34mblue. Hope you enjoy terminal hue',
|
||||||
'But now...\u001b[20Cfor my greatest trick...\u001b[8m',
|
'But now...\u001b[20Cfor my greatest trick...\u001b[8m',
|
||||||
'The quic\b\b\b\b\b\bk brown fo\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007x... [Beeeep]',
|
'The quic\b\b\b\b\b\bk brown fo\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007x... [Beeeep]',
|
||||||
'Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗'
|
'Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗',
|
||||||
],
|
],
|
||||||
ranges: {},
|
ranges: {},
|
||||||
version: 2
|
version: 2,
|
||||||
}
|
}
|
||||||
return DocstoreClient.createDoc(
|
return DocstoreClient.createDoc(
|
||||||
this.project_id,
|
this.project_id,
|
||||||
|
@ -880,7 +881,7 @@ describe('Archiving', function () {
|
||||||
this.doc.lines,
|
this.doc.lines,
|
||||||
this.doc.version,
|
this.doc.version,
|
||||||
this.doc.ranges,
|
this.doc.ranges,
|
||||||
(error) => {
|
error => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
@ -968,17 +969,17 @@ describe('Archiving', function () {
|
||||||
op: { i: 'foo', p: 24 },
|
op: { i: 'foo', p: 24 },
|
||||||
metadata: {
|
metadata: {
|
||||||
user_id: ObjectId(),
|
user_id: ObjectId(),
|
||||||
ts: new Date('2017-01-27T16:10:44.194Z')
|
ts: new Date('2017-01-27T16:10:44.194Z'),
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: ObjectId(),
|
id: ObjectId(),
|
||||||
op: { d: 'bar', p: 50 },
|
op: { d: 'bar', p: 50 },
|
||||||
metadata: {
|
metadata: {
|
||||||
user_id: ObjectId(),
|
user_id: ObjectId(),
|
||||||
ts: new Date('2017-01-27T18:10:44.194Z')
|
ts: new Date('2017-01-27T18:10:44.194Z'),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
comments: [
|
comments: [
|
||||||
{
|
{
|
||||||
|
@ -986,12 +987,12 @@ describe('Archiving', function () {
|
||||||
op: { c: 'comment', p: 284, t: ObjectId() },
|
op: { c: 'comment', p: 284, t: ObjectId() },
|
||||||
metadata: {
|
metadata: {
|
||||||
user_id: ObjectId(),
|
user_id: ObjectId(),
|
||||||
ts: new Date('2017-01-26T14:22:04.869Z')
|
ts: new Date('2017-01-26T14:22:04.869Z'),
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
version: 2
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
version: 2,
|
||||||
}
|
}
|
||||||
return DocstoreClient.createDoc(
|
return DocstoreClient.createDoc(
|
||||||
this.project_id,
|
this.project_id,
|
||||||
|
@ -999,7 +1000,7 @@ describe('Archiving', function () {
|
||||||
this.doc.lines,
|
this.doc.lines,
|
||||||
this.doc.version,
|
this.doc.version,
|
||||||
this.doc.ranges,
|
this.doc.ranges,
|
||||||
(error) => {
|
error => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
@ -1082,7 +1083,7 @@ describe('Archiving', function () {
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['abc', 'def', 'ghi'],
|
lines: ['abc', 'def', 'ghi'],
|
||||||
ranges: {},
|
ranges: {},
|
||||||
version: 2
|
version: 2,
|
||||||
}
|
}
|
||||||
return DocstoreClient.createDoc(
|
return DocstoreClient.createDoc(
|
||||||
this.project_id,
|
this.project_id,
|
||||||
|
@ -1090,7 +1091,7 @@ describe('Archiving', function () {
|
||||||
this.doc.lines,
|
this.doc.lines,
|
||||||
this.doc.version,
|
this.doc.version,
|
||||||
this.doc.ranges,
|
this.doc.ranges,
|
||||||
(error) => {
|
error => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
@ -1178,21 +1179,21 @@ describe('Archiving', function () {
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['abc', 'def', 'ghi'],
|
lines: ['abc', 'def', 'ghi'],
|
||||||
ranges: {},
|
ranges: {},
|
||||||
version: 2
|
version: 2,
|
||||||
}
|
}
|
||||||
uploadContent(
|
uploadContent(
|
||||||
`${this.project_id}/${this.doc._id}`,
|
`${this.project_id}/${this.doc._id}`,
|
||||||
this.doc.lines,
|
this.doc.lines,
|
||||||
(error) => {
|
error => {
|
||||||
expect(error).not.to.exist
|
expect(error).not.to.exist
|
||||||
db.docs.insert(
|
db.docs.insert(
|
||||||
{
|
{
|
||||||
project_id: this.project_id,
|
project_id: this.project_id,
|
||||||
_id: this.doc._id,
|
_id: this.doc._id,
|
||||||
rev: this.doc.version,
|
rev: this.doc.version,
|
||||||
inS3: true
|
inS3: true,
|
||||||
},
|
},
|
||||||
(error) => {
|
error => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ function deleteTestSuite(deleteDoc) {
|
||||||
this.lines,
|
this.lines,
|
||||||
this.version,
|
this.version,
|
||||||
this.ranges,
|
this.ranges,
|
||||||
(error) => {
|
error => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ function deleteTestSuite(deleteDoc) {
|
||||||
|
|
||||||
it('should not export the doc to s3', function (done) {
|
it('should not export the doc to s3', function (done) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
DocstoreClient.getS3Doc(this.project_id, this.doc_id, (error) => {
|
DocstoreClient.getS3Doc(this.project_id, this.doc_id, error => {
|
||||||
expect(error).to.be.instanceOf(Errors.NotFoundError)
|
expect(error).to.be.instanceOf(Errors.NotFoundError)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
@ -311,7 +311,7 @@ describe('Delete via PATCH', function () {
|
||||||
(error, deletedDocs) => {
|
(error, deletedDocs) => {
|
||||||
if (error) return done(error)
|
if (error) return done(error)
|
||||||
expect(deletedDocs).to.deep.equal([
|
expect(deletedDocs).to.deep.equal([
|
||||||
{ _id: this.doc_id.toString(), name: 'main.tex' }
|
{ _id: this.doc_id.toString(), name: 'main.tex' },
|
||||||
])
|
])
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
|
@ -366,7 +366,7 @@ describe('Delete via PATCH', function () {
|
||||||
expect(deletedDocs).to.deep.equal([
|
expect(deletedDocs).to.deep.equal([
|
||||||
{ _id: this.doc_id3.toString(), name: 'three.tex' },
|
{ _id: this.doc_id3.toString(), name: 'three.tex' },
|
||||||
{ _id: this.doc_id2.toString(), name: 'two.tex' },
|
{ _id: this.doc_id2.toString(), name: 'two.tex' },
|
||||||
{ _id: this.doc_id.toString(), name: 'main.tex' }
|
{ _id: this.doc_id.toString(), name: 'main.tex' },
|
||||||
])
|
])
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
|
@ -391,7 +391,7 @@ describe('Delete via PATCH', function () {
|
||||||
|
|
||||||
expect(deletedDocs).to.deep.equal([
|
expect(deletedDocs).to.deep.equal([
|
||||||
{ _id: this.doc_id3.toString(), name: 'three.tex' },
|
{ _id: this.doc_id3.toString(), name: 'three.tex' },
|
||||||
{ _id: this.doc_id2.toString(), name: 'two.tex' }
|
{ _id: this.doc_id2.toString(), name: 'two.tex' },
|
||||||
// dropped main.tex
|
// dropped main.tex
|
||||||
])
|
])
|
||||||
done()
|
done()
|
||||||
|
@ -436,7 +436,7 @@ describe("Destroying a project's documents", function () {
|
||||||
|
|
||||||
return describe('when the doc is archived', function () {
|
return describe('when the doc is archived', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
return DocstoreClient.archiveAllDoc(this.project_id, (err) => {
|
return DocstoreClient.archiveAllDoc(this.project_id, err => {
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
return done(err)
|
return done(err)
|
||||||
}
|
}
|
||||||
|
@ -461,7 +461,7 @@ describe("Destroying a project's documents", function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
return it('should remove the doc contents from s3', function (done) {
|
return it('should remove the doc contents from s3', function (done) {
|
||||||
return DocstoreClient.getS3Doc(this.project_id, this.doc_id, (error) => {
|
return DocstoreClient.getS3Doc(this.project_id, this.doc_id, error => {
|
||||||
expect(error).to.be.instanceOf(Errors.NotFoundError)
|
expect(error).to.be.instanceOf(Errors.NotFoundError)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
|
@ -26,31 +26,31 @@ describe('Getting all docs', function () {
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['one', 'two', 'three'],
|
lines: ['one', 'two', 'three'],
|
||||||
ranges: { mock: 'one' },
|
ranges: { mock: 'one' },
|
||||||
rev: 2
|
rev: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['aaa', 'bbb', 'ccc'],
|
lines: ['aaa', 'bbb', 'ccc'],
|
||||||
ranges: { mock: 'two' },
|
ranges: { mock: 'two' },
|
||||||
rev: 4
|
rev: 4,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['111', '222', '333'],
|
lines: ['111', '222', '333'],
|
||||||
ranges: { mock: 'three' },
|
ranges: { mock: 'three' },
|
||||||
rev: 6
|
rev: 6,
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
this.deleted_doc = {
|
this.deleted_doc = {
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['deleted'],
|
lines: ['deleted'],
|
||||||
ranges: { mock: 'four' },
|
ranges: { mock: 'four' },
|
||||||
rev: 8
|
rev: 8,
|
||||||
}
|
}
|
||||||
const version = 42
|
const version = 42
|
||||||
const jobs = Array.from(this.docs).map((doc) =>
|
const jobs = Array.from(this.docs).map(doc =>
|
||||||
((doc) => {
|
(doc => {
|
||||||
return (callback) => {
|
return callback => {
|
||||||
return DocstoreClient.createDoc(
|
return DocstoreClient.createDoc(
|
||||||
this.project_id,
|
this.project_id,
|
||||||
doc._id,
|
doc._id,
|
||||||
|
@ -62,14 +62,14 @@ describe('Getting all docs', function () {
|
||||||
}
|
}
|
||||||
})(doc)
|
})(doc)
|
||||||
)
|
)
|
||||||
jobs.push((cb) => {
|
jobs.push(cb => {
|
||||||
return DocstoreClient.createDoc(
|
return DocstoreClient.createDoc(
|
||||||
this.project_id,
|
this.project_id,
|
||||||
this.deleted_doc._id,
|
this.deleted_doc._id,
|
||||||
this.deleted_doc.lines,
|
this.deleted_doc.lines,
|
||||||
version,
|
version,
|
||||||
this.deleted_doc.ranges,
|
this.deleted_doc.ranges,
|
||||||
(err) => {
|
err => {
|
||||||
return DocstoreClient.deleteDoc(
|
return DocstoreClient.deleteDoc(
|
||||||
this.project_id,
|
this.project_id,
|
||||||
this.deleted_doc._id,
|
this.deleted_doc._id,
|
||||||
|
@ -78,7 +78,7 @@ describe('Getting all docs', function () {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
jobs.unshift((cb) => DocstoreApp.ensureRunning(cb))
|
jobs.unshift(cb => DocstoreApp.ensureRunning(cb))
|
||||||
return async.series(jobs, done)
|
return async.series(jobs, done)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,10 @@ describe('Getting a doc', function () {
|
||||||
op: { i: 'foo', p: 3 },
|
op: { i: 'foo', p: 3 },
|
||||||
meta: {
|
meta: {
|
||||||
user_id: ObjectId().toString(),
|
user_id: ObjectId().toString(),
|
||||||
ts: new Date().toString()
|
ts: new Date().toString(),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
return DocstoreApp.ensureRunning(() => {
|
return DocstoreApp.ensureRunning(() => {
|
||||||
return DocstoreClient.createDoc(
|
return DocstoreClient.createDoc(
|
||||||
|
@ -42,7 +42,7 @@ describe('Getting a doc', function () {
|
||||||
this.lines,
|
this.lines,
|
||||||
this.version,
|
this.version,
|
||||||
this.ranges,
|
this.ranges,
|
||||||
(error) => {
|
error => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ describe('Getting a doc', function () {
|
||||||
this.lines,
|
this.lines,
|
||||||
this.version,
|
this.version,
|
||||||
this.ranges,
|
this.ranges,
|
||||||
(error) => {
|
error => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,10 @@ describe('Applying updates to a doc', function () {
|
||||||
op: { i: 'foo', p: 3 },
|
op: { i: 'foo', p: 3 },
|
||||||
meta: {
|
meta: {
|
||||||
user_id: ObjectId().toString(),
|
user_id: ObjectId().toString(),
|
||||||
ts: new Date().toString()
|
ts: new Date().toString(),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
this.newRanges = {
|
this.newRanges = {
|
||||||
changes: [
|
changes: [
|
||||||
|
@ -41,10 +41,10 @@ describe('Applying updates to a doc', function () {
|
||||||
op: { i: 'bar', p: 6 },
|
op: { i: 'bar', p: 6 },
|
||||||
meta: {
|
meta: {
|
||||||
user_id: ObjectId().toString(),
|
user_id: ObjectId().toString(),
|
||||||
ts: new Date().toString()
|
ts: new Date().toString(),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
this.version = 42
|
this.version = 42
|
||||||
return DocstoreApp.ensureRunning(() => {
|
return DocstoreApp.ensureRunning(() => {
|
||||||
|
@ -54,7 +54,7 @@ describe('Applying updates to a doc', function () {
|
||||||
this.originalLines,
|
this.originalLines,
|
||||||
this.version,
|
this.version,
|
||||||
this.originalRanges,
|
this.originalRanges,
|
||||||
(error) => {
|
error => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,10 +32,7 @@ module.exports = {
|
||||||
this.initing = true
|
this.initing = true
|
||||||
this.callbacks.push(callback)
|
this.callbacks.push(callback)
|
||||||
waitForDb().then(() => {
|
waitForDb().then(() => {
|
||||||
return app.listen(
|
return app.listen(settings.internal.docstore.port, 'localhost', error => {
|
||||||
settings.internal.docstore.port,
|
|
||||||
'localhost',
|
|
||||||
(error) => {
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
@ -47,8 +44,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
})()
|
})()
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ const Persistor = require('../../../../app/js/PersistorManager')
|
||||||
async function streamToString(stream) {
|
async function streamToString(stream) {
|
||||||
const chunks = []
|
const chunks = []
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
stream.on('data', (chunk) => chunks.push(chunk))
|
stream.on('data', chunk => chunks.push(chunk))
|
||||||
stream.on('error', reject)
|
stream.on('error', reject)
|
||||||
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')))
|
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')))
|
||||||
})
|
})
|
||||||
|
@ -54,7 +54,7 @@ module.exports = DocstoreClient = {
|
||||||
{
|
{
|
||||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
|
||||||
json: true,
|
json: true,
|
||||||
qs
|
qs,
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
|
@ -64,7 +64,7 @@ module.exports = DocstoreClient = {
|
||||||
request.get(
|
request.get(
|
||||||
{
|
{
|
||||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}/deleted`,
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}/deleted`,
|
||||||
json: true
|
json: true,
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
|
@ -77,7 +77,7 @@ module.exports = DocstoreClient = {
|
||||||
return request.get(
|
return request.get(
|
||||||
{
|
{
|
||||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc`,
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc`,
|
||||||
json: true
|
json: true,
|
||||||
},
|
},
|
||||||
(req, res, body) => {
|
(req, res, body) => {
|
||||||
callback(req, res, body)
|
callback(req, res, body)
|
||||||
|
@ -89,7 +89,7 @@ module.exports = DocstoreClient = {
|
||||||
request.get(
|
request.get(
|
||||||
{
|
{
|
||||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc-deleted`,
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc-deleted`,
|
||||||
json: true
|
json: true,
|
||||||
},
|
},
|
||||||
(error, res, body) => {
|
(error, res, body) => {
|
||||||
if (error) return callback(error)
|
if (error) return callback(error)
|
||||||
|
@ -108,7 +108,7 @@ module.exports = DocstoreClient = {
|
||||||
return request.get(
|
return request.get(
|
||||||
{
|
{
|
||||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/ranges`,
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/ranges`,
|
||||||
json: true
|
json: true,
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
|
@ -124,8 +124,8 @@ module.exports = DocstoreClient = {
|
||||||
json: {
|
json: {
|
||||||
lines,
|
lines,
|
||||||
version,
|
version,
|
||||||
ranges
|
ranges,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
|
@ -165,7 +165,7 @@ module.exports = DocstoreClient = {
|
||||||
request.patch(
|
request.patch(
|
||||||
{
|
{
|
||||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
|
||||||
json: { name, deleted: true, deletedAt }
|
json: { name, deleted: true, deletedAt },
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
|
@ -177,7 +177,7 @@ module.exports = DocstoreClient = {
|
||||||
}
|
}
|
||||||
return request.post(
|
return request.post(
|
||||||
{
|
{
|
||||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/archive`
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/archive`,
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
|
@ -189,7 +189,7 @@ module.exports = DocstoreClient = {
|
||||||
}
|
}
|
||||||
return request.post(
|
return request.post(
|
||||||
{
|
{
|
||||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}/archive`
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}/archive`,
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
|
@ -201,7 +201,7 @@ module.exports = DocstoreClient = {
|
||||||
}
|
}
|
||||||
return request.post(
|
return request.post(
|
||||||
{
|
{
|
||||||
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/destroy`
|
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/destroy`,
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
|
@ -213,9 +213,9 @@ module.exports = DocstoreClient = {
|
||||||
settings.docstore.bucket,
|
settings.docstore.bucket,
|
||||||
`${project_id}/${doc_id}`
|
`${project_id}/${doc_id}`
|
||||||
)
|
)
|
||||||
.then((data) => {
|
.then(data => {
|
||||||
callback(null, JSON.parse(data))
|
callback(null, JSON.parse(data))
|
||||||
})
|
})
|
||||||
.catch(callback)
|
.catch(callback)
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,16 +17,16 @@ const stubs = {
|
||||||
warn: sandbox.stub(),
|
warn: sandbox.stub(),
|
||||||
err: sandbox.stub(),
|
err: sandbox.stub(),
|
||||||
error: sandbox.stub(),
|
error: sandbox.stub(),
|
||||||
fatal: sandbox.stub()
|
fatal: sandbox.stub(),
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// SandboxedModule configuration
|
// SandboxedModule configuration
|
||||||
SandboxedModule.configure({
|
SandboxedModule.configure({
|
||||||
requires: {
|
requires: {
|
||||||
'logger-sharelatex': stubs.logger
|
'logger-sharelatex': stubs.logger,
|
||||||
},
|
},
|
||||||
globals: { Buffer, JSON, console, process }
|
globals: { Buffer, JSON, console, process },
|
||||||
})
|
})
|
||||||
|
|
||||||
exports.mochaHooks = {
|
exports.mochaHooks = {
|
||||||
|
@ -36,5 +36,5 @@ exports.mochaHooks = {
|
||||||
|
|
||||||
afterEach() {
|
afterEach() {
|
||||||
sandbox.reset()
|
sandbox.reset()
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,23 +27,23 @@ describe('DocArchiveManager', function () {
|
||||||
md5Sum = 'decafbad'
|
md5Sum = 'decafbad'
|
||||||
|
|
||||||
RangeManager = {
|
RangeManager = {
|
||||||
jsonRangesToMongo: sinon.stub().returns({ mongo: 'ranges' })
|
jsonRangesToMongo: sinon.stub().returns({ mongo: 'ranges' }),
|
||||||
}
|
}
|
||||||
Settings = {
|
Settings = {
|
||||||
docstore: {
|
docstore: {
|
||||||
bucket: 'wombat'
|
bucket: 'wombat',
|
||||||
},
|
},
|
||||||
parallelArchiveJobs: 3,
|
parallelArchiveJobs: 3,
|
||||||
destroyBatchSize: 10,
|
destroyBatchSize: 10,
|
||||||
destroyRetryCount: 3
|
destroyRetryCount: 3,
|
||||||
}
|
}
|
||||||
HashDigest = sinon.stub().returns(md5Sum)
|
HashDigest = sinon.stub().returns(md5Sum)
|
||||||
HashUpdate = sinon.stub().returns({ digest: HashDigest })
|
HashUpdate = sinon.stub().returns({ digest: HashDigest })
|
||||||
Crypto = {
|
Crypto = {
|
||||||
createHash: sinon.stub().returns({ update: HashUpdate })
|
createHash: sinon.stub().returns({ update: HashUpdate }),
|
||||||
}
|
}
|
||||||
Streamifier = {
|
Streamifier = {
|
||||||
createReadStream: sinon.stub().returns({ stream: 'readStream' })
|
createReadStream: sinon.stub().returns({ stream: 'readStream' }),
|
||||||
}
|
}
|
||||||
|
|
||||||
projectId = ObjectId()
|
projectId = ObjectId()
|
||||||
|
@ -51,75 +51,75 @@ describe('DocArchiveManager', function () {
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
inS3: true,
|
inS3: true,
|
||||||
rev: 2
|
rev: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
inS3: true,
|
inS3: true,
|
||||||
rev: 4
|
rev: 4,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
inS3: true,
|
inS3: true,
|
||||||
rev: 6
|
rev: 6,
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
mongoDocs = [
|
mongoDocs = [
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['one', 'two', 'three'],
|
lines: ['one', 'two', 'three'],
|
||||||
rev: 2
|
rev: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['aaa', 'bbb', 'ccc'],
|
lines: ['aaa', 'bbb', 'ccc'],
|
||||||
rev: 4
|
rev: 4,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
inS3: true,
|
inS3: true,
|
||||||
rev: 6
|
rev: 6,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
inS3: true,
|
inS3: true,
|
||||||
rev: 6
|
rev: 6,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['111', '222', '333'],
|
lines: ['111', '222', '333'],
|
||||||
rev: 6
|
rev: 6,
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
docJson = JSON.stringify({
|
docJson = JSON.stringify({
|
||||||
lines: mongoDocs[0].lines,
|
lines: mongoDocs[0].lines,
|
||||||
ranges: mongoDocs[0].ranges,
|
ranges: mongoDocs[0].ranges,
|
||||||
schema_v: 1
|
schema_v: 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
stream = {
|
stream = {
|
||||||
on: sinon.stub(),
|
on: sinon.stub(),
|
||||||
resume: sinon.stub()
|
resume: sinon.stub(),
|
||||||
}
|
}
|
||||||
stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8'))
|
stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8'))
|
||||||
stream.on.withArgs('end').yields()
|
stream.on.withArgs('end').yields()
|
||||||
|
|
||||||
readStream = {
|
readStream = {
|
||||||
stream: 'readStream'
|
stream: 'readStream',
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistorManager = {
|
PersistorManager = {
|
||||||
getObjectStream: sinon.stub().resolves(stream),
|
getObjectStream: sinon.stub().resolves(stream),
|
||||||
sendStream: sinon.stub().resolves(),
|
sendStream: sinon.stub().resolves(),
|
||||||
getObjectMd5Hash: sinon.stub().resolves(md5Sum),
|
getObjectMd5Hash: sinon.stub().resolves(md5Sum),
|
||||||
deleteObject: sinon.stub().resolves()
|
deleteObject: sinon.stub().resolves(),
|
||||||
}
|
}
|
||||||
|
|
||||||
const getNonArchivedProjectDocs = sinon.stub()
|
const getNonArchivedProjectDocs = sinon.stub()
|
||||||
getNonArchivedProjectDocs
|
getNonArchivedProjectDocs
|
||||||
.onCall(0)
|
.onCall(0)
|
||||||
.resolves(mongoDocs.filter((doc) => !doc.inS3))
|
.resolves(mongoDocs.filter(doc => !doc.inS3))
|
||||||
getNonArchivedProjectDocs.onCall(1).resolves([])
|
getNonArchivedProjectDocs.onCall(1).resolves([])
|
||||||
|
|
||||||
const getArchivedProjectDocs = sinon.stub()
|
const getArchivedProjectDocs = sinon.stub()
|
||||||
|
@ -135,8 +135,8 @@ describe('DocArchiveManager', function () {
|
||||||
getNonArchivedProjectDocs,
|
getNonArchivedProjectDocs,
|
||||||
getArchivedProjectDocs,
|
getArchivedProjectDocs,
|
||||||
findDoc: sinon.stub().rejects(new Errors.NotFoundError()),
|
findDoc: sinon.stub().rejects(new Errors.NotFoundError()),
|
||||||
destroyDoc: sinon.stub().resolves()
|
destroyDoc: sinon.stub().resolves(),
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
for (const mongoDoc of mongoDocs.concat(archivedDocs)) {
|
for (const mongoDoc of mongoDocs.concat(archivedDocs)) {
|
||||||
MongoManager.promises.findDoc
|
MongoManager.promises.findDoc
|
||||||
|
@ -152,8 +152,8 @@ describe('DocArchiveManager', function () {
|
||||||
'./MongoManager': MongoManager,
|
'./MongoManager': MongoManager,
|
||||||
'./RangeManager': RangeManager,
|
'./RangeManager': RangeManager,
|
||||||
'./PersistorManager': PersistorManager,
|
'./PersistorManager': PersistorManager,
|
||||||
'./Errors': Errors
|
'./Errors': Errors,
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ describe('DocArchiveManager', function () {
|
||||||
const json = JSON.stringify({
|
const json = JSON.stringify({
|
||||||
lines: mongoDocs[0].lines,
|
lines: mongoDocs[0].lines,
|
||||||
ranges: mongoDocs[0].ranges,
|
ranges: mongoDocs[0].ranges,
|
||||||
schema_v: 1
|
schema_v: 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
await DocArchiveManager.promises.archiveDoc(projectId, mongoDocs[0])
|
await DocArchiveManager.promises.archiveDoc(projectId, mongoDocs[0])
|
||||||
|
@ -277,7 +277,7 @@ describe('DocArchiveManager', function () {
|
||||||
expect(
|
expect(
|
||||||
MongoManager.promises.upsertIntoDocCollection
|
MongoManager.promises.upsertIntoDocCollection
|
||||||
).to.have.been.calledWith(projectId, docId, {
|
).to.have.been.calledWith(projectId, docId, {
|
||||||
lines: mongoDocs[0].lines
|
lines: mongoDocs[0].lines,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -295,7 +295,7 @@ describe('DocArchiveManager', function () {
|
||||||
describe('when the doc has the old schema', function () {
|
describe('when the doc has the old schema', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mongoDoc = {
|
mongoDoc = {
|
||||||
lines: ['doc', 'lines']
|
lines: ['doc', 'lines'],
|
||||||
}
|
}
|
||||||
s3Doc = ['doc', 'lines']
|
s3Doc = ['doc', 'lines']
|
||||||
docJson = JSON.stringify(s3Doc)
|
docJson = JSON.stringify(s3Doc)
|
||||||
|
@ -315,11 +315,11 @@ describe('DocArchiveManager', function () {
|
||||||
s3Doc = {
|
s3Doc = {
|
||||||
lines: ['doc', 'lines'],
|
lines: ['doc', 'lines'],
|
||||||
ranges: { json: 'ranges' },
|
ranges: { json: 'ranges' },
|
||||||
schema_v: 1
|
schema_v: 1,
|
||||||
}
|
}
|
||||||
mongoDoc = {
|
mongoDoc = {
|
||||||
lines: ['doc', 'lines'],
|
lines: ['doc', 'lines'],
|
||||||
ranges: { mongo: 'ranges' }
|
ranges: { mongo: 'ranges' },
|
||||||
}
|
}
|
||||||
docJson = JSON.stringify(s3Doc)
|
docJson = JSON.stringify(s3Doc)
|
||||||
stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8'))
|
stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8'))
|
||||||
|
@ -337,10 +337,10 @@ describe('DocArchiveManager', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
s3Doc = {
|
s3Doc = {
|
||||||
lines: ['doc', 'lines'],
|
lines: ['doc', 'lines'],
|
||||||
schema_v: 1
|
schema_v: 1,
|
||||||
}
|
}
|
||||||
mongoDoc = {
|
mongoDoc = {
|
||||||
lines: ['doc', 'lines']
|
lines: ['doc', 'lines'],
|
||||||
}
|
}
|
||||||
docJson = JSON.stringify(s3Doc)
|
docJson = JSON.stringify(s3Doc)
|
||||||
stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8'))
|
stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8'))
|
||||||
|
@ -358,7 +358,7 @@ describe('DocArchiveManager', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
s3Doc = {
|
s3Doc = {
|
||||||
lines: ['doc', 'lines'],
|
lines: ['doc', 'lines'],
|
||||||
schema_v: 2
|
schema_v: 2,
|
||||||
}
|
}
|
||||||
docJson = JSON.stringify(s3Doc)
|
docJson = JSON.stringify(s3Doc)
|
||||||
stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8'))
|
stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8'))
|
||||||
|
|
|
@ -29,11 +29,11 @@ describe('DocManager', function () {
|
||||||
jsonRangesToMongo(r) {
|
jsonRangesToMongo(r) {
|
||||||
return r
|
return r
|
||||||
},
|
},
|
||||||
shouldUpdateRanges: sinon.stub().returns(false)
|
shouldUpdateRanges: sinon.stub().returns(false),
|
||||||
}),
|
}),
|
||||||
'@overleaf/settings': (this.settings = { docstore: {} }),
|
'@overleaf/settings': (this.settings = { docstore: {} }),
|
||||||
'./Errors': Errors
|
'./Errors': Errors,
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
this.doc_id = ObjectId().toString()
|
this.doc_id = ObjectId().toString()
|
||||||
this.project_id = ObjectId().toString()
|
this.project_id = ObjectId().toString()
|
||||||
|
@ -47,7 +47,7 @@ describe('DocManager', function () {
|
||||||
this.DocManager._getDoc = sinon.stub()
|
this.DocManager._getDoc = sinon.stub()
|
||||||
return (this.doc = {
|
return (this.doc = {
|
||||||
_id: this.doc_id,
|
_id: this.doc_id,
|
||||||
lines: ['2134']
|
lines: ['2134'],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ describe('DocManager', function () {
|
||||||
deleted: true,
|
deleted: true,
|
||||||
version: true,
|
version: true,
|
||||||
ranges: true,
|
ranges: true,
|
||||||
inS3: true
|
inS3: true,
|
||||||
})
|
})
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
return done()
|
return done()
|
||||||
|
@ -102,7 +102,7 @@ describe('DocManager', function () {
|
||||||
this.DocManager._getDoc
|
this.DocManager._getDoc
|
||||||
.calledWith(this.project_id, this.doc_id, {
|
.calledWith(this.project_id, this.doc_id, {
|
||||||
lines: true,
|
lines: true,
|
||||||
inS3: true
|
inS3: true,
|
||||||
})
|
})
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
return done()
|
return done()
|
||||||
|
@ -129,7 +129,7 @@ describe('DocManager', function () {
|
||||||
this.doc = {
|
this.doc = {
|
||||||
_id: this.doc_id,
|
_id: this.doc_id,
|
||||||
project_id: this.project_id,
|
project_id: this.project_id,
|
||||||
lines: ['mock-lines']
|
lines: ['mock-lines'],
|
||||||
}
|
}
|
||||||
this.version = 42
|
this.version = 42
|
||||||
this.MongoManager.findDoc = sinon.stub()
|
this.MongoManager.findDoc = sinon.stub()
|
||||||
|
@ -148,7 +148,7 @@ describe('DocManager', function () {
|
||||||
this.project_id,
|
this.project_id,
|
||||||
this.doc_id,
|
this.doc_id,
|
||||||
{ inS3: false },
|
{ inS3: false },
|
||||||
(err) => {
|
err => {
|
||||||
expect(err).to.exist
|
expect(err).to.exist
|
||||||
return done()
|
return done()
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ describe('DocManager', function () {
|
||||||
this.project_id,
|
this.project_id,
|
||||||
this.doc_id,
|
this.doc_id,
|
||||||
undefined,
|
undefined,
|
||||||
(err) => {
|
err => {
|
||||||
this.MongoManager.findDoc.called.should.equal(false)
|
this.MongoManager.findDoc.called.should.equal(false)
|
||||||
expect(err).to.exist
|
expect(err).to.exist
|
||||||
return done()
|
return done()
|
||||||
|
@ -173,7 +173,7 @@ describe('DocManager', function () {
|
||||||
this.project_id,
|
this.project_id,
|
||||||
this.doc_id,
|
this.doc_id,
|
||||||
{ inS3: true },
|
{ inS3: true },
|
||||||
(err) => {
|
err => {
|
||||||
expect(err).to.not.exist
|
expect(err).to.not.exist
|
||||||
return done()
|
return done()
|
||||||
}
|
}
|
||||||
|
@ -250,7 +250,7 @@ describe('DocManager', function () {
|
||||||
_id: this.doc_id,
|
_id: this.doc_id,
|
||||||
project_id: this.project_id,
|
project_id: this.project_id,
|
||||||
lines: ['mock-lines'],
|
lines: ['mock-lines'],
|
||||||
inS3: true
|
inS3: true,
|
||||||
}
|
}
|
||||||
this.MongoManager.findDoc.yields(null, this.doc)
|
this.MongoManager.findDoc.yields(null, this.doc)
|
||||||
this.DocArchiveManager.unarchiveDoc = (
|
this.DocArchiveManager.unarchiveDoc = (
|
||||||
|
@ -316,8 +316,8 @@ describe('DocManager', function () {
|
||||||
{
|
{
|
||||||
_id: this.doc_id,
|
_id: this.doc_id,
|
||||||
project_id: this.project_id,
|
project_id: this.project_id,
|
||||||
lines: ['mock-lines']
|
lines: ['mock-lines'],
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
this.MongoManager.getProjectsDocs = sinon
|
this.MongoManager.getProjectsDocs = sinon
|
||||||
.stub()
|
.stub()
|
||||||
|
@ -499,7 +499,7 @@ describe('DocManager', function () {
|
||||||
sinon.match({
|
sinon.match({
|
||||||
project_id: this.project_id,
|
project_id: this.project_id,
|
||||||
doc_id: this.doc_id,
|
doc_id: this.doc_id,
|
||||||
err: this.err
|
err: this.err,
|
||||||
}),
|
}),
|
||||||
'archiving a single doc in the background failed'
|
'archiving a single doc in the background failed'
|
||||||
)
|
)
|
||||||
|
@ -545,10 +545,10 @@ describe('DocManager', function () {
|
||||||
op: { i: 'foo', p: 3 },
|
op: { i: 'foo', p: 3 },
|
||||||
meta: {
|
meta: {
|
||||||
user_id: ObjectId().toString(),
|
user_id: ObjectId().toString(),
|
||||||
ts: new Date().toString()
|
ts: new Date().toString(),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
this.newRanges = {
|
this.newRanges = {
|
||||||
changes: [
|
changes: [
|
||||||
|
@ -557,10 +557,10 @@ describe('DocManager', function () {
|
||||||
op: { i: 'bar', p: 6 },
|
op: { i: 'bar', p: 6 },
|
||||||
meta: {
|
meta: {
|
||||||
user_id: ObjectId().toString(),
|
user_id: ObjectId().toString(),
|
||||||
ts: new Date().toString()
|
ts: new Date().toString(),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
this.version = 42
|
this.version = 42
|
||||||
this.doc = {
|
this.doc = {
|
||||||
|
@ -569,7 +569,7 @@ describe('DocManager', function () {
|
||||||
lines: this.oldDocLines,
|
lines: this.oldDocLines,
|
||||||
rev: (this.rev = 5),
|
rev: (this.rev = 5),
|
||||||
version: this.version,
|
version: this.version,
|
||||||
ranges: this.originalRanges
|
ranges: this.originalRanges,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.MongoManager.upsertIntoDocCollection = sinon.stub().callsArg(3)
|
this.MongoManager.upsertIntoDocCollection = sinon.stub().callsArg(3)
|
||||||
|
@ -598,7 +598,7 @@ describe('DocManager', function () {
|
||||||
lines: true,
|
lines: true,
|
||||||
version: true,
|
version: true,
|
||||||
ranges: true,
|
ranges: true,
|
||||||
inS3: true
|
inS3: true,
|
||||||
})
|
})
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
@ -844,7 +844,7 @@ describe('DocManager', function () {
|
||||||
return this.MongoManager.upsertIntoDocCollection
|
return this.MongoManager.upsertIntoDocCollection
|
||||||
.calledWith(this.project_id, this.doc_id, {
|
.calledWith(this.project_id, this.doc_id, {
|
||||||
lines: this.newDocLines,
|
lines: this.newDocLines,
|
||||||
ranges: this.originalRanges
|
ranges: this.originalRanges,
|
||||||
})
|
})
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
|
|
@ -21,21 +21,21 @@ const { ObjectId } = require('mongodb')
|
||||||
describe('HttpController', function () {
|
describe('HttpController', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
const settings = {
|
const settings = {
|
||||||
max_doc_length: 2 * 1024 * 1024
|
max_doc_length: 2 * 1024 * 1024,
|
||||||
}
|
}
|
||||||
this.HttpController = SandboxedModule.require(modulePath, {
|
this.HttpController = SandboxedModule.require(modulePath, {
|
||||||
requires: {
|
requires: {
|
||||||
'./DocManager': (this.DocManager = {}),
|
'./DocManager': (this.DocManager = {}),
|
||||||
'./DocArchiveManager': (this.DocArchiveManager = {}),
|
'./DocArchiveManager': (this.DocArchiveManager = {}),
|
||||||
'@overleaf/settings': settings,
|
'@overleaf/settings': settings,
|
||||||
'./HealthChecker': {}
|
'./HealthChecker': {},
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
this.res = {
|
this.res = {
|
||||||
send: sinon.stub(),
|
send: sinon.stub(),
|
||||||
sendStatus: sinon.stub(),
|
sendStatus: sinon.stub(),
|
||||||
json: sinon.stub(),
|
json: sinon.stub(),
|
||||||
setHeader: sinon.stub()
|
setHeader: sinon.stub(),
|
||||||
}
|
}
|
||||||
this.res.status = sinon.stub().returns(this.res)
|
this.res.status = sinon.stub().returns(this.res)
|
||||||
this.req = { query: {} }
|
this.req = { query: {} }
|
||||||
|
@ -46,14 +46,14 @@ describe('HttpController', function () {
|
||||||
_id: this.doc_id,
|
_id: this.doc_id,
|
||||||
lines: ['mock', 'lines', ' here', '', '', ' spaces '],
|
lines: ['mock', 'lines', ' here', '', '', ' spaces '],
|
||||||
version: 42,
|
version: 42,
|
||||||
rev: 5
|
rev: 5,
|
||||||
}
|
}
|
||||||
return (this.deletedDoc = {
|
return (this.deletedDoc = {
|
||||||
deleted: true,
|
deleted: true,
|
||||||
_id: this.doc_id,
|
_id: this.doc_id,
|
||||||
lines: ['mock', 'lines', ' here', '', '', ' spaces '],
|
lines: ['mock', 'lines', ' here', '', '', ' spaces '],
|
||||||
version: 42,
|
version: 42,
|
||||||
rev: 5
|
rev: 5,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ describe('HttpController', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.req.params = {
|
this.req.params = {
|
||||||
project_id: this.project_id,
|
project_id: this.project_id,
|
||||||
doc_id: this.doc_id
|
doc_id: this.doc_id,
|
||||||
}
|
}
|
||||||
this.DocManager.getFullDoc = sinon
|
this.DocManager.getFullDoc = sinon
|
||||||
.stub()
|
.stub()
|
||||||
|
@ -82,7 +82,7 @@ describe('HttpController', function () {
|
||||||
_id: this.doc_id,
|
_id: this.doc_id,
|
||||||
lines: this.doc.lines,
|
lines: this.doc.lines,
|
||||||
rev: this.doc.rev,
|
rev: this.doc.rev,
|
||||||
version: this.doc.version
|
version: this.doc.version,
|
||||||
})
|
})
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
@ -92,7 +92,7 @@ describe('HttpController', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.req.params = {
|
this.req.params = {
|
||||||
project_id: this.project_id,
|
project_id: this.project_id,
|
||||||
doc_id: this.doc_id
|
doc_id: this.doc_id,
|
||||||
}
|
}
|
||||||
return (this.DocManager.getFullDoc = sinon
|
return (this.DocManager.getFullDoc = sinon
|
||||||
.stub()
|
.stub()
|
||||||
|
@ -120,7 +120,7 @@ describe('HttpController', function () {
|
||||||
lines: this.doc.lines,
|
lines: this.doc.lines,
|
||||||
rev: this.doc.rev,
|
rev: this.doc.rev,
|
||||||
deleted: true,
|
deleted: true,
|
||||||
version: this.doc.version
|
version: this.doc.version,
|
||||||
})
|
})
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
@ -131,7 +131,7 @@ describe('HttpController', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.req.params = {
|
this.req.params = {
|
||||||
project_id: this.project_id,
|
project_id: this.project_id,
|
||||||
doc_id: this.doc_id
|
doc_id: this.doc_id,
|
||||||
}
|
}
|
||||||
this.DocManager.getDocLines = sinon.stub().callsArgWith(2, null, this.doc)
|
this.DocManager.getDocLines = sinon.stub().callsArgWith(2, null, this.doc)
|
||||||
return this.HttpController.getRawDoc(this.req, this.res, this.next)
|
return this.HttpController.getRawDoc(this.req, this.res, this.next)
|
||||||
|
@ -165,13 +165,13 @@ describe('HttpController', function () {
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['mock', 'lines', 'one'],
|
lines: ['mock', 'lines', 'one'],
|
||||||
rev: 2
|
rev: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['mock', 'lines', 'two'],
|
lines: ['mock', 'lines', 'two'],
|
||||||
rev: 4
|
rev: 4,
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
this.DocManager.getAllNonDeletedDocs = sinon
|
this.DocManager.getAllNonDeletedDocs = sinon
|
||||||
.stub()
|
.stub()
|
||||||
|
@ -191,13 +191,13 @@ describe('HttpController', function () {
|
||||||
{
|
{
|
||||||
_id: this.docs[0]._id.toString(),
|
_id: this.docs[0]._id.toString(),
|
||||||
lines: this.docs[0].lines,
|
lines: this.docs[0].lines,
|
||||||
rev: this.docs[0].rev
|
rev: this.docs[0].rev,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: this.docs[1]._id.toString(),
|
_id: this.docs[1]._id.toString(),
|
||||||
lines: this.docs[1].lines,
|
lines: this.docs[1].lines,
|
||||||
rev: this.docs[1].rev
|
rev: this.docs[1].rev,
|
||||||
}
|
},
|
||||||
])
|
])
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
@ -210,14 +210,14 @@ describe('HttpController', function () {
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['mock', 'lines', 'one'],
|
lines: ['mock', 'lines', 'one'],
|
||||||
rev: 2
|
rev: 2,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
lines: ['mock', 'lines', 'two'],
|
lines: ['mock', 'lines', 'two'],
|
||||||
rev: 4
|
rev: 4,
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
this.DocManager.getAllNonDeletedDocs = sinon
|
this.DocManager.getAllNonDeletedDocs = sinon
|
||||||
.stub()
|
.stub()
|
||||||
|
@ -231,13 +231,13 @@ describe('HttpController', function () {
|
||||||
{
|
{
|
||||||
_id: this.docs[0]._id.toString(),
|
_id: this.docs[0]._id.toString(),
|
||||||
lines: this.docs[0].lines,
|
lines: this.docs[0].lines,
|
||||||
rev: this.docs[0].rev
|
rev: this.docs[0].rev,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: this.docs[2]._id.toString(),
|
_id: this.docs[2]._id.toString(),
|
||||||
lines: this.docs[2].lines,
|
lines: this.docs[2].lines,
|
||||||
rev: this.docs[2].rev
|
rev: this.docs[2].rev,
|
||||||
}
|
},
|
||||||
])
|
])
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
@ -247,7 +247,7 @@ describe('HttpController', function () {
|
||||||
.calledWith(
|
.calledWith(
|
||||||
{
|
{
|
||||||
err: sinon.match.has('message', 'null doc'),
|
err: sinon.match.has('message', 'null doc'),
|
||||||
project_id: this.project_id
|
project_id: this.project_id,
|
||||||
},
|
},
|
||||||
'encountered null doc'
|
'encountered null doc'
|
||||||
)
|
)
|
||||||
|
@ -263,12 +263,12 @@ describe('HttpController', function () {
|
||||||
this.docs = [
|
this.docs = [
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
ranges: { mock_ranges: 'one' }
|
ranges: { mock_ranges: 'one' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: ObjectId(),
|
_id: ObjectId(),
|
||||||
ranges: { mock_ranges: 'two' }
|
ranges: { mock_ranges: 'two' },
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
this.DocManager.getAllNonDeletedDocs = sinon
|
this.DocManager.getAllNonDeletedDocs = sinon
|
||||||
.stub()
|
.stub()
|
||||||
|
@ -287,12 +287,12 @@ describe('HttpController', function () {
|
||||||
.calledWith([
|
.calledWith([
|
||||||
{
|
{
|
||||||
_id: this.docs[0]._id.toString(),
|
_id: this.docs[0]._id.toString(),
|
||||||
ranges: this.docs[0].ranges
|
ranges: this.docs[0].ranges,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
_id: this.docs[1]._id.toString(),
|
_id: this.docs[1]._id.toString(),
|
||||||
ranges: this.docs[1].ranges
|
ranges: this.docs[1].ranges,
|
||||||
}
|
},
|
||||||
])
|
])
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
@ -303,7 +303,7 @@ describe('HttpController', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
return (this.req.params = {
|
return (this.req.params = {
|
||||||
project_id: this.project_id,
|
project_id: this.project_id,
|
||||||
doc_id: this.doc_id
|
doc_id: this.doc_id,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ describe('HttpController', function () {
|
||||||
this.req.body = {
|
this.req.body = {
|
||||||
lines: (this.lines = ['hello', 'world']),
|
lines: (this.lines = ['hello', 'world']),
|
||||||
version: (this.version = 42),
|
version: (this.version = 42),
|
||||||
ranges: (this.ranges = { changes: 'mock' })
|
ranges: (this.ranges = { changes: 'mock' }),
|
||||||
}
|
}
|
||||||
this.DocManager.updateDoc = sinon
|
this.DocManager.updateDoc = sinon
|
||||||
.stub()
|
.stub()
|
||||||
|
@ -344,7 +344,7 @@ describe('HttpController', function () {
|
||||||
this.req.body = {
|
this.req.body = {
|
||||||
lines: (this.lines = ['hello', 'world']),
|
lines: (this.lines = ['hello', 'world']),
|
||||||
version: (this.version = 42),
|
version: (this.version = 42),
|
||||||
ranges: {}
|
ranges: {},
|
||||||
}
|
}
|
||||||
this.DocManager.updateDoc = sinon
|
this.DocManager.updateDoc = sinon
|
||||||
.stub()
|
.stub()
|
||||||
|
@ -412,7 +412,7 @@ describe('HttpController', function () {
|
||||||
this.req.body = {
|
this.req.body = {
|
||||||
lines: (this.lines = Array(2049).fill('a'.repeat(1024))),
|
lines: (this.lines = Array(2049).fill('a'.repeat(1024))),
|
||||||
version: (this.version = 42),
|
version: (this.version = 42),
|
||||||
ranges: (this.ranges = { changes: 'mock' })
|
ranges: (this.ranges = { changes: 'mock' }),
|
||||||
}
|
}
|
||||||
return this.HttpController.updateDoc(this.req, this.res, this.next)
|
return this.HttpController.updateDoc(this.req, this.res, this.next)
|
||||||
})
|
})
|
||||||
|
@ -431,7 +431,7 @@ describe('HttpController', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.req.params = {
|
this.req.params = {
|
||||||
project_id: this.project_id,
|
project_id: this.project_id,
|
||||||
doc_id: this.doc_id
|
doc_id: this.doc_id,
|
||||||
}
|
}
|
||||||
this.req.body = { name: 'foo.tex' }
|
this.req.body = { name: 'foo.tex' }
|
||||||
this.DocManager.patchDoc = sinon.stub().yields(null)
|
this.DocManager.patchDoc = sinon.stub().yields(null)
|
||||||
|
|
|
@ -24,11 +24,11 @@ describe('MongoManager', function () {
|
||||||
requires: {
|
requires: {
|
||||||
'./mongodb': {
|
'./mongodb': {
|
||||||
db: (this.db = { docs: {}, docOps: {} }),
|
db: (this.db = { docs: {}, docOps: {} }),
|
||||||
ObjectId
|
ObjectId,
|
||||||
},
|
},
|
||||||
'@overleaf/metrics': { timeAsyncMethod: sinon.stub() },
|
'@overleaf/metrics': { timeAsyncMethod: sinon.stub() },
|
||||||
'@overleaf/settings': { max_deleted_docs: 42 }
|
'@overleaf/settings': { max_deleted_docs: 42 },
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
this.project_id = ObjectId().toString()
|
this.project_id = ObjectId().toString()
|
||||||
this.doc_id = ObjectId().toString()
|
this.doc_id = ObjectId().toString()
|
||||||
|
@ -54,10 +54,10 @@ describe('MongoManager', function () {
|
||||||
.calledWith(
|
.calledWith(
|
||||||
{
|
{
|
||||||
_id: ObjectId(this.doc_id),
|
_id: ObjectId(this.doc_id),
|
||||||
project_id: ObjectId(this.project_id)
|
project_id: ObjectId(this.project_id),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
projection: this.filter
|
projection: this.filter,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
|
@ -85,10 +85,10 @@ describe('MongoManager', function () {
|
||||||
this.db.docs.updateOne.should.have.been.calledWith(
|
this.db.docs.updateOne.should.have.been.calledWith(
|
||||||
{
|
{
|
||||||
_id: ObjectId(this.doc_id),
|
_id: ObjectId(this.doc_id),
|
||||||
project_id: ObjectId(this.project_id)
|
project_id: ObjectId(this.project_id),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$set: this.meta
|
$set: this.meta,
|
||||||
},
|
},
|
||||||
this.callback
|
this.callback
|
||||||
)
|
)
|
||||||
|
@ -105,7 +105,7 @@ describe('MongoManager', function () {
|
||||||
this.db.docs.find = sinon.stub().returns({
|
this.db.docs.find = sinon.stub().returns({
|
||||||
toArray: sinon
|
toArray: sinon
|
||||||
.stub()
|
.stub()
|
||||||
.callsArgWith(0, null, [this.doc, this.doc3, this.doc4])
|
.callsArgWith(0, null, [this.doc, this.doc3, this.doc4]),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -124,10 +124,10 @@ describe('MongoManager', function () {
|
||||||
.calledWith(
|
.calledWith(
|
||||||
{
|
{
|
||||||
project_id: ObjectId(this.project_id),
|
project_id: ObjectId(this.project_id),
|
||||||
deleted: { $ne: true }
|
deleted: { $ne: true },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
projection: this.filter
|
projection: this.filter,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
|
@ -154,10 +154,10 @@ describe('MongoManager', function () {
|
||||||
return this.db.docs.find
|
return this.db.docs.find
|
||||||
.calledWith(
|
.calledWith(
|
||||||
{
|
{
|
||||||
project_id: ObjectId(this.project_id)
|
project_id: ObjectId(this.project_id),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
projection: this.filter
|
projection: this.filter,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
|
@ -178,7 +178,7 @@ describe('MongoManager', function () {
|
||||||
this.doc2 = { _id: '2', name: 'mock-doc2.tex' }
|
this.doc2 = { _id: '2', name: 'mock-doc2.tex' }
|
||||||
this.doc3 = { _id: '3', name: 'mock-doc3.tex' }
|
this.doc3 = { _id: '3', name: 'mock-doc3.tex' }
|
||||||
this.db.docs.find = sinon.stub().returns({
|
this.db.docs.find = sinon.stub().returns({
|
||||||
toArray: sinon.stub().yields(null, [this.doc1, this.doc2, this.doc3])
|
toArray: sinon.stub().yields(null, [this.doc1, this.doc2, this.doc3]),
|
||||||
})
|
})
|
||||||
this.callback.callsFake(done)
|
this.callback.callsFake(done)
|
||||||
this.MongoManager.getProjectsDeletedDocs(
|
this.MongoManager.getProjectsDeletedDocs(
|
||||||
|
@ -192,7 +192,7 @@ describe('MongoManager', function () {
|
||||||
this.db.docs.find
|
this.db.docs.find
|
||||||
.calledWith({
|
.calledWith({
|
||||||
project_id: ObjectId(this.project_id),
|
project_id: ObjectId(this.project_id),
|
||||||
deleted: true
|
deleted: true,
|
||||||
})
|
})
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
@ -202,7 +202,7 @@ describe('MongoManager', function () {
|
||||||
.calledWith(sinon.match.any, {
|
.calledWith(sinon.match.any, {
|
||||||
projection: this.filter,
|
projection: this.filter,
|
||||||
sort: { deletedAt: -1 },
|
sort: { deletedAt: -1 },
|
||||||
limit: 42
|
limit: 42,
|
||||||
})
|
})
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
@ -225,7 +225,7 @@ describe('MongoManager', function () {
|
||||||
this.project_id,
|
this.project_id,
|
||||||
this.doc_id,
|
this.doc_id,
|
||||||
{ lines: this.lines },
|
{ lines: this.lines },
|
||||||
(err) => {
|
err => {
|
||||||
const args = this.db.docs.updateOne.args[0]
|
const args = this.db.docs.updateOne.args[0]
|
||||||
assert.deepEqual(args[0], { _id: ObjectId(this.doc_id) })
|
assert.deepEqual(args[0], { _id: ObjectId(this.doc_id) })
|
||||||
assert.equal(args[1].$set.lines, this.lines)
|
assert.equal(args[1].$set.lines, this.lines)
|
||||||
|
@ -241,7 +241,7 @@ describe('MongoManager', function () {
|
||||||
this.project_id,
|
this.project_id,
|
||||||
this.doc_id,
|
this.doc_id,
|
||||||
{ lines: this.lines },
|
{ lines: this.lines },
|
||||||
(err) => {
|
err => {
|
||||||
err.should.equal(this.stubbedErr)
|
err.should.equal(this.stubbedErr)
|
||||||
return done()
|
return done()
|
||||||
}
|
}
|
||||||
|
@ -258,13 +258,13 @@ describe('MongoManager', function () {
|
||||||
|
|
||||||
it('should destroy the doc', function () {
|
it('should destroy the doc', function () {
|
||||||
return sinon.assert.calledWith(this.db.docs.deleteOne, {
|
return sinon.assert.calledWith(this.db.docs.deleteOne, {
|
||||||
_id: ObjectId('123456789012')
|
_id: ObjectId('123456789012'),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return it('should destroy the docOps', function () {
|
return it('should destroy the docOps', function () {
|
||||||
return sinon.assert.calledWith(this.db.docOps.deleteOne, {
|
return sinon.assert.calledWith(this.db.docOps.deleteOne, {
|
||||||
doc_id: ObjectId('123456789012')
|
doc_id: ObjectId('123456789012'),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -282,7 +282,7 @@ describe('MongoManager', function () {
|
||||||
.calledWith(
|
.calledWith(
|
||||||
{ doc_id: ObjectId(this.doc_id) },
|
{ doc_id: ObjectId(this.doc_id) },
|
||||||
{
|
{
|
||||||
projection: { version: 1 }
|
projection: { version: 1 },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
|
@ -320,15 +320,15 @@ describe('MongoManager', function () {
|
||||||
return this.db.docOps.updateOne
|
return this.db.docOps.updateOne
|
||||||
.calledWith(
|
.calledWith(
|
||||||
{
|
{
|
||||||
doc_id: ObjectId(this.doc_id)
|
doc_id: ObjectId(this.doc_id),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
version: this.version
|
version: this.version,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
upsert: true
|
upsert: true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
|
|
|
@ -25,9 +25,9 @@ describe('RangeManager', function () {
|
||||||
return (this.RangeManager = SandboxedModule.require(modulePath, {
|
return (this.RangeManager = SandboxedModule.require(modulePath, {
|
||||||
requires: {
|
requires: {
|
||||||
'./mongodb': {
|
'./mongodb': {
|
||||||
ObjectId
|
ObjectId,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -45,16 +45,16 @@ describe('RangeManager', function () {
|
||||||
op: { i: 'foo', p: 3 },
|
op: { i: 'foo', p: 3 },
|
||||||
metadata: {
|
metadata: {
|
||||||
user_id,
|
user_id,
|
||||||
ts
|
ts,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
comments: [
|
comments: [
|
||||||
{
|
{
|
||||||
id: comment_id,
|
id: comment_id,
|
||||||
op: { c: 'foo', p: 3, t: thread_id }
|
op: { c: 'foo', p: 3, t: thread_id },
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}).should.deep.equal({
|
}).should.deep.equal({
|
||||||
changes: [
|
changes: [
|
||||||
{
|
{
|
||||||
|
@ -62,16 +62,16 @@ describe('RangeManager', function () {
|
||||||
op: { i: 'foo', p: 3 },
|
op: { i: 'foo', p: 3 },
|
||||||
metadata: {
|
metadata: {
|
||||||
user_id: ObjectId(user_id),
|
user_id: ObjectId(user_id),
|
||||||
ts: new Date(ts)
|
ts: new Date(ts),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
comments: [
|
comments: [
|
||||||
{
|
{
|
||||||
id: ObjectId(comment_id),
|
id: ObjectId(comment_id),
|
||||||
op: { c: 'foo', p: 3, t: ObjectId(thread_id) }
|
op: { c: 'foo', p: 3, t: ObjectId(thread_id) },
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -84,29 +84,29 @@ describe('RangeManager', function () {
|
||||||
{
|
{
|
||||||
id: change_id,
|
id: change_id,
|
||||||
metadata: {
|
metadata: {
|
||||||
user_id
|
user_id,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
comments: [
|
comments: [
|
||||||
{
|
{
|
||||||
id: comment_id
|
id: comment_id,
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}).should.deep.equal({
|
}).should.deep.equal({
|
||||||
changes: [
|
changes: [
|
||||||
{
|
{
|
||||||
id: change_id,
|
id: change_id,
|
||||||
metadata: {
|
metadata: {
|
||||||
user_id
|
user_id,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
comments: [
|
comments: [
|
||||||
{
|
{
|
||||||
id: comment_id
|
id: comment_id,
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -123,16 +123,16 @@ describe('RangeManager', function () {
|
||||||
op: { i: 'foo', p: 3 },
|
op: { i: 'foo', p: 3 },
|
||||||
metadata: {
|
metadata: {
|
||||||
user_id,
|
user_id,
|
||||||
ts
|
ts,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
comments: [
|
comments: [
|
||||||
{
|
{
|
||||||
id: comment_id,
|
id: comment_id,
|
||||||
op: { c: 'foo', p: 3, t: thread_id }
|
op: { c: 'foo', p: 3, t: thread_id },
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
const ranges1_copy = JSON.parse(JSON.stringify(ranges1)) // jsonRangesToMongo modifies in place
|
const ranges1_copy = JSON.parse(JSON.stringify(ranges1)) // jsonRangesToMongo modifies in place
|
||||||
const ranges2 = JSON.parse(
|
const ranges2 = JSON.parse(
|
||||||
|
@ -151,16 +151,16 @@ describe('RangeManager', function () {
|
||||||
op: { i: 'foo', p: 3 },
|
op: { i: 'foo', p: 3 },
|
||||||
metadata: {
|
metadata: {
|
||||||
user_id: ObjectId(),
|
user_id: ObjectId(),
|
||||||
ts: new Date()
|
ts: new Date(),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
comments: [
|
comments: [
|
||||||
{
|
{
|
||||||
id: ObjectId(),
|
id: ObjectId(),
|
||||||
op: { c: 'foo', p: 3, t: ObjectId() }
|
op: { c: 'foo', p: 3, t: ObjectId() },
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
return (this.ranges_copy = this.RangeManager.jsonRangesToMongo(
|
return (this.ranges_copy = this.RangeManager.jsonRangesToMongo(
|
||||||
JSON.parse(JSON.stringify(this.ranges))
|
JSON.parse(JSON.stringify(this.ranges))
|
||||||
|
|
Loading…
Reference in a new issue