From 540b52c128bafd38f8d4f820a507c2099b340bd1 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 13 Jul 2021 12:04:48 +0100 Subject: [PATCH] [misc] run format_fix and lint:fix --- services/docstore/app.js | 8 +- services/docstore/app/js/DocArchiveManager.js | 28 ++--- services/docstore/app/js/DocManager.js | 103 ++++++++++-------- services/docstore/app/js/Errors.js | 2 +- services/docstore/app/js/HealthChecker.js | 10 +- services/docstore/app/js/HttpController.js | 29 ++--- services/docstore/app/js/MongoManager.js | 46 ++++---- services/docstore/app/js/RangeManager.js | 2 +- services/docstore/app/js/mongodb.js | 2 +- services/docstore/config/settings.defaults.js | 22 ++-- .../test/acceptance/js/ArchiveDocsTests.js | 85 ++++++++------- .../test/acceptance/js/DeletingDocsTests.js | 14 +-- .../test/acceptance/js/GettingAllDocsTests.js | 22 ++-- .../test/acceptance/js/GettingDocsTests.js | 12 +- .../test/acceptance/js/UpdatingDocsTests.js | 18 +-- .../test/acceptance/js/helpers/DocstoreApp.js | 30 +++-- .../acceptance/js/helpers/DocstoreClient.js | 28 ++--- services/docstore/test/setup.js | 10 +- .../test/unit/js/DocArchiveManagerTests.js | 64 +++++------ .../docstore/test/unit/js/DocManagerTests.js | 50 ++++----- .../test/unit/js/HttpControllerTests.js | 70 ++++++------ .../test/unit/js/MongoManagerTests.js | 48 ++++---- .../test/unit/js/RangeManagerTests.js | 78 ++++++------- 23 files changed, 394 insertions(+), 387 deletions(-) diff --git a/services/docstore/app.js b/services/docstore/app.js index e31775e943..7cb774b9f8 100644 --- a/services/docstore/app.js +++ b/services/docstore/app.js @@ -13,7 +13,7 @@ const bodyParser = require('body-parser') const { celebrate: validate, Joi, - errors: handleValidationErrors + errors: handleValidationErrors, } = require('celebrate') const mongodb = require('./app/js/mongodb') const Errors = require('./app/js/Errors') @@ -67,8 +67,8 @@ app.patch( body: { deleted: Joi.boolean(), 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 ) @@ -111,7 +111,7 @@ if (!module.parent) { return logger.info(`Docstore starting up, listening on ${host}:${port}`) }) }) - .catch((err) => { + .catch(err => { logger.fatal({ err }, 'Cannot connect to mongo. Exiting.') process.exit(1) }) diff --git a/services/docstore/app/js/DocArchiveManager.js b/services/docstore/app/js/DocArchiveManager.js index 807ae8b3d7..dcd713eb62 100644 --- a/services/docstore/app/js/DocArchiveManager.js +++ b/services/docstore/app/js/DocArchiveManager.js @@ -30,8 +30,8 @@ module.exports = { unArchiveAllDocs, unarchiveDoc, destroyAllDocs, - destroyDoc - } + destroyDoc, + }, } async function archiveAllDocs(projectId) { @@ -44,8 +44,8 @@ async function archiveAllDocs(projectId) { break } - await pMap(docs, (doc) => archiveDoc(projectId, doc), { - concurrency: PARALLEL_JOBS + await pMap(docs, doc => archiveDoc(projectId, doc), { + concurrency: PARALLEL_JOBS, }) } } @@ -55,7 +55,7 @@ async function archiveDocById(projectId, docId) { lines: true, ranges: true, rev: true, - inS3: true + inS3: true, }) if (!doc) { @@ -83,7 +83,7 @@ async function archiveDoc(projectId, doc) { const json = JSON.stringify({ lines: doc.lines, ranges: doc.ranges, - schema_v: 1 + schema_v: 1, }) // 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 stream = Streamifier.createReadStream(json) await PersistorManager.sendStream(settings.docstore.bucket, key, stream, { - sourceMd5: md5 + sourceMd5: md5, }) await MongoManager.markDocAsArchived(doc._id, doc.rev) } @@ -119,8 +119,8 @@ async function unArchiveAllDocs(projectId) { if (!docs || docs.length === 0) { break } - await pMap(docs, (doc) => unarchiveDoc(projectId, doc._id), { - concurrency: PARALLEL_JOBS + await pMap(docs, doc => unarchiveDoc(projectId, doc._id), { + concurrency: PARALLEL_JOBS, }) } } @@ -164,7 +164,7 @@ async function unarchiveDoc(projectId, docId) { throw new Errors.Md5MismatchError('md5 mismatch when downloading doc', { key, sourceMd5, - md5 + md5, }) } @@ -195,8 +195,8 @@ async function destroyAllDocs(projectId) { if (!docs || docs.length === 0) { break } - await pMap(docs, (doc) => destroyDoc(projectId, doc._id), { - concurrency: PARALLEL_JOBS + await pMap(docs, doc => destroyDoc(projectId, doc._id), { + concurrency: PARALLEL_JOBS, }) } } @@ -207,7 +207,7 @@ async function destroyDoc(projectId, docId) { 'removing doc from mongo and persistor' ) const doc = await MongoManager.findDoc(projectId, docId, { - inS3: 1 + inS3: 1, }) if (!doc) { throw new Errors.NotFoundError('Doc not found in Mongo') @@ -243,7 +243,7 @@ async function destroyArchiveWithRetry(projectId, docId) { async function _streamToString(stream) { const chunks = [] 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('end', () => resolve(Buffer.concat(chunks).toString('utf8'))) }) diff --git a/services/docstore/app/js/DocManager.js b/services/docstore/app/js/DocManager.js index 2951377743..0f00ce79cf 100644 --- a/services/docstore/app/js/DocManager.js +++ b/services/docstore/app/js/DocManager.js @@ -38,58 +38,67 @@ module.exports = DocManager = { return callback('must include inS3 when getting doc') } - return MongoManager.findDoc(project_id, doc_id, filter, function ( - err, - doc - ) { - if (err != null) { - return callback(err) - } else if (doc == null) { - return callback( - new Errors.NotFoundError( - `No such doc: ${doc_id} in project ${project_id}` + return MongoManager.findDoc( + project_id, + doc_id, + filter, + function (err, doc) { + if (err != null) { + return callback(err) + } else if (doc == null) { + return callback( + new Errors.NotFoundError( + `No such doc: ${doc_id} in project ${project_id}` + ) ) - ) - } else if (doc != null ? doc.inS3 : undefined) { - return DocArchive.unarchiveDoc(project_id, doc_id, function (err) { - if (err != null) { - logger.err({ err, project_id, doc_id }, 'error unarchiving doc') - return callback(err) - } - return DocManager._getDoc(project_id, doc_id, filter, callback) - }) - } else { - if (filter.version) { - return MongoManager.getDocVersion(doc_id, function (error, version) { - if (error != null) { - return callback(error) + } else if (doc != null ? doc.inS3 : undefined) { + return DocArchive.unarchiveDoc(project_id, doc_id, function (err) { + if (err != null) { + logger.err({ err, project_id, doc_id }, 'error unarchiving doc') + return callback(err) } - doc.version = version - return callback(err, doc) + return DocManager._getDoc(project_id, doc_id, filter, callback) }) } else { - return callback(err, doc) + if (filter.version) { + return MongoManager.getDocVersion( + doc_id, + function (error, version) { + if (error != null) { + return callback(error) + } + doc.version = version + return callback(err, doc) + } + ) + } else { + return callback(err, doc) + } } } - }) + ) }, isDocDeleted(projectId, docId, callback) { - MongoManager.findDoc(projectId, docId, { deleted: true }, function ( - err, - doc - ) { - if (err) { - return callback(err) + MongoManager.findDoc( + projectId, + docId, + { deleted: true }, + function (err, doc) { + if (err) { + return callback(err) + } + if (!doc) { + return callback( + new Errors.NotFoundError( + `No such project/doc: ${projectId}/${docId}` + ) + ) + } + // `doc.deleted` is `undefined` for non deleted docs + callback(null, Boolean(doc.deleted)) } - if (!doc) { - return callback( - new Errors.NotFoundError(`No such project/doc: ${projectId}/${docId}`) - ) - } - // `doc.deleted` is `undefined` for non deleted docs - callback(null, Boolean(doc.deleted)) - }) + ) }, getFullDoc(project_id, doc_id, callback) { @@ -105,7 +114,7 @@ module.exports = DocManager = { deleted: true, version: true, ranges: true, - inS3: true + inS3: true, }, function (err, doc) { if (err != null) { @@ -181,7 +190,7 @@ module.exports = DocManager = { lines: true, version: true, ranges: true, - inS3: true + inS3: true, }, function (err, doc) { let updateLines, updateRanges, updateVersion @@ -244,7 +253,7 @@ module.exports = DocManager = { project_id, doc_id, oldVersion: doc != null ? doc.version : undefined, - newVersion: version + newVersion: version, }, 'updating doc version' ) @@ -290,7 +299,7 @@ module.exports = DocManager = { if (meta.deleted && Settings.docstore.archiveOnSoftDelete) { // 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) { logger.warn( { project_id, doc_id, err }, @@ -302,5 +311,5 @@ module.exports = DocManager = { MongoManager.patchDoc(project_id, doc_id, meta, callback) }) - } + }, } diff --git a/services/docstore/app/js/Errors.js b/services/docstore/app/js/Errors.js index 6a74485494..4eaa5481d3 100644 --- a/services/docstore/app/js/Errors.js +++ b/services/docstore/app/js/Errors.js @@ -6,5 +6,5 @@ class Md5MismatchError extends OError {} module.exports = { Md5MismatchError, - ...Errors + ...Errors, } diff --git a/services/docstore/app/js/HealthChecker.js b/services/docstore/app/js/HealthChecker.js index 30d82ee8a3..3271c40164 100644 --- a/services/docstore/app/js/HealthChecker.js +++ b/services/docstore/app/js/HealthChecker.js @@ -26,11 +26,11 @@ module.exports = { const url = `http://localhost:${port}/project/${project_id}/doc/${doc_id}` const lines = [ 'smoke test - delete me', - `${crypto.randomBytes(32).toString('hex')}` + `${crypto.randomBytes(32).toString('hex')}`, ] const getOpts = () => ({ url, - timeout: 3000 + timeout: 3000, }) logger.log({ lines, url, doc_id, project_id }, 'running health check') const jobs = [ @@ -60,9 +60,9 @@ module.exports = { } }) }, - (cb) => db.docs.deleteOne({ _id: doc_id, project_id }, cb), - (cb) => db.docOps.deleteOne({ doc_id }, cb) + cb => db.docs.deleteOne({ _id: doc_id, project_id }, cb), + cb => db.docOps.deleteOne({ doc_id }, cb), ] return async.series(jobs, callback) - } + }, } diff --git a/services/docstore/app/js/HttpController.js b/services/docstore/app/js/HttpController.js index 593dcc6a2f..f53c9068bc 100644 --- a/services/docstore/app/js/HttpController.js +++ b/services/docstore/app/js/HttpController.js @@ -98,19 +98,20 @@ module.exports = HttpController = { getAllDeletedDocs(req, res, next) { const { project_id } = req.params logger.log({ project_id }, 'getting all deleted docs') - DocManager.getAllDeletedDocs(project_id, { name: true }, function ( - error, - docs - ) { - if (error) { - return next(error) + DocManager.getAllDeletedDocs( + project_id, + { name: true }, + function (error, docs) { + if (error) { + return next(error) + } + res.json( + docs.map(doc => { + return { _id: doc._id.toString(), name: doc.name } + }) + ) } - res.json( - docs.map((doc) => { - return { _id: doc._id.toString(), name: doc.name } - }) - ) - }) + ) }, getAllRanges(req, res, next) { @@ -185,7 +186,7 @@ module.exports = HttpController = { } return res.json({ modified, - rev + rev, }) } ) @@ -304,5 +305,5 @@ module.exports = HttpController = { return res.sendStatus(200) } }) - } + }, } diff --git a/services/docstore/app/js/MongoManager.js b/services/docstore/app/js/MongoManager.js index 4e3f71eac8..5434db581d 100644 --- a/services/docstore/app/js/MongoManager.js +++ b/services/docstore/app/js/MongoManager.js @@ -25,10 +25,10 @@ module.exports = MongoManager = { db.docs.findOne( { _id: ObjectId(doc_id.toString()), - project_id: ObjectId(project_id.toString()) + project_id: ObjectId(project_id.toString()), }, { - projection: filter + projection: filter, }, callback ) @@ -39,12 +39,12 @@ module.exports = MongoManager = { .find( { project_id: ObjectId(project_id.toString()), - deleted: true + deleted: true, }, { projection: filter, sort: { deletedAt: -1 }, - limit: Settings.max_deleted_docs + limit: Settings.max_deleted_docs, } ) .toArray(callback) @@ -56,7 +56,7 @@ module.exports = MongoManager = { query.deleted = { $ne: true } } const queryOptions = { - projection: filter + projection: filter, } if (options.limit) { queryOptions.limit = options.limit @@ -67,7 +67,7 @@ module.exports = MongoManager = { getArchivedProjectDocs(project_id, maxResults, callback) { const query = { project_id: ObjectId(project_id.toString()), - inS3: true + inS3: true, } db.docs .find(query, { projection: { _id: 1 }, limit: maxResults }) @@ -77,7 +77,7 @@ module.exports = MongoManager = { getNonArchivedProjectDocs(project_id, maxResults, callback) { const query = { project_id: ObjectId(project_id.toString()), - inS3: { $ne: true } + inS3: { $ne: true }, } db.docs.find(query, { limit: maxResults }).toArray(callback) }, @@ -86,7 +86,7 @@ module.exports = MongoManager = { const query = { project_id: ObjectId(project_id.toString()), deleted: { $ne: true }, - inS3: true + inS3: true, } db.docs .find(query, { projection: { _id: 1 }, limit: maxResults }) @@ -97,11 +97,11 @@ module.exports = MongoManager = { const update = { $set: updates, $inc: { - rev: 1 + rev: 1, }, $unset: { - inS3: true - } + inS3: true, + }, } update.$set.project_id = ObjectId(project_id) db.docs.updateOne( @@ -116,7 +116,7 @@ module.exports = MongoManager = { db.docs.updateOne( { _id: ObjectId(doc_id), - project_id: ObjectId(project_id) + project_id: ObjectId(project_id), }, { $set: meta }, callback @@ -126,14 +126,14 @@ module.exports = MongoManager = { markDocAsArchived(doc_id, rev, callback) { const update = { $set: {}, - $unset: {} + $unset: {}, } update.$set.inS3 = true update.$unset.lines = true update.$unset.ranges = true const query = { _id: doc_id, - rev + rev, } db.docs.updateOne(query, update, callback) }, @@ -144,12 +144,12 @@ module.exports = MongoManager = { } db.docOps.findOne( { - doc_id: ObjectId(doc_id) + doc_id: ObjectId(doc_id), }, { projection: { - version: 1 - } + version: 1, + }, }, function (error, doc) { if (error != null) { @@ -166,13 +166,13 @@ module.exports = MongoManager = { } db.docOps.updateOne( { - doc_id: ObjectId(doc_id) + doc_id: ObjectId(doc_id), }, { - $set: { version } + $set: { version }, }, { - upsert: true + upsert: true, }, callback ) @@ -181,7 +181,7 @@ module.exports = MongoManager = { destroyDoc(doc_id, callback) { db.docs.deleteOne( { - _id: ObjectId(doc_id) + _id: ObjectId(doc_id), }, function (err) { if (err != null) { @@ -189,13 +189,13 @@ module.exports = MongoManager = { } db.docOps.deleteOne( { - doc_id: ObjectId(doc_id) + doc_id: ObjectId(doc_id), }, callback ) } ) - } + }, } const methods = Object.getOwnPropertyNames(MongoManager) diff --git a/services/docstore/app/js/RangeManager.js b/services/docstore/app/js/RangeManager.js index fd719e5b15..78ef59abd3 100644 --- a/services/docstore/app/js/RangeManager.js +++ b/services/docstore/app/js/RangeManager.js @@ -65,5 +65,5 @@ module.exports = RangeManager = { } catch (error) { return data } - } + }, } diff --git a/services/docstore/app/js/mongodb.js b/services/docstore/app/js/mongodb.js index 245f7ed8f7..b49eb7b80b 100644 --- a/services/docstore/app/js/mongodb.js +++ b/services/docstore/app/js/mongodb.js @@ -32,5 +32,5 @@ module.exports = { db, ObjectId, addCollection, - waitForDb + waitForDb, } diff --git a/services/docstore/config/settings.defaults.js b/services/docstore/config/settings.defaults.js index 0f1c1ab42b..391739368e 100644 --- a/services/docstore/config/settings.defaults.js +++ b/services/docstore/config/settings.defaults.js @@ -5,15 +5,15 @@ const Settings = { internal: { docstore: { port: 3016, - host: process.env.LISTEN_ADDRESS || 'localhost' - } + host: process.env.LISTEN_ADDRESS || 'localhost', + }, }, mongo: { options: { useUnifiedTopology: - (process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true' - } + (process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true', + }, }, docstore: { @@ -23,14 +23,14 @@ const Settings = { backend: process.env.BACKEND || 's3', 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', gcs: { unlockBeforeDelete: process.env.GCS_UNLOCK_BEFORE_DELETE === 'true', 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, @@ -41,7 +41,7 @@ const Settings = { unArchiveBatchSize: parseInt(process.env.UN_ARCHIVE_BATCH_SIZE, 10) || 50, destroyBatchSize: parseInt(process.env.DESTROY_BATCH_SIZE, 10) || 2000, 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) { @@ -63,7 +63,7 @@ if ( bucket: process.env.AWS_BUCKET, endpoint: process.env.AWS_S3_ENDPOINT, 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 = { apiEndpoint: process.env.GCS_API_ENDPOINT, 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. // e.g. { myS3UserFilesBucketName: 'myGoogleUserFilesBucketName' } buckets: JSON.parse(process.env.FALLBACK_BUCKET_MAPPING || '{}'), - copyOnMiss: process.env.COPY_ON_MISS === 'true' + copyOnMiss: process.env.COPY_ON_MISS === 'true', } } diff --git a/services/docstore/test/acceptance/js/ArchiveDocsTests.js b/services/docstore/test/acceptance/js/ArchiveDocsTests.js index 2a4948ba5d..2dc02152d9 100644 --- a/services/docstore/test/acceptance/js/ArchiveDocsTests.js +++ b/services/docstore/test/acceptance/js/ArchiveDocsTests.js @@ -49,18 +49,18 @@ describe('Archiving', function () { _id: ObjectId(), lines: ['one', 'two', 'three'], ranges: {}, - version: 2 + version: 2, }, { _id: ObjectId(), lines: ['aaa', 'bbb', 'ccc'], ranges: {}, - version: 4 - } + version: 4, + }, ] - const jobs = Array.from(this.docs).map((doc) => - ((doc) => { - return (callback) => { + const jobs = Array.from(this.docs).map(doc => + (doc => { + return callback => { return DocstoreClient.createDoc( this.project_id, doc._id, @@ -73,7 +73,7 @@ describe('Archiving', function () { })(doc) ) - return async.series(jobs, (error) => { + return async.series(jobs, error => { if (error != null) { throw error } @@ -90,9 +90,9 @@ describe('Archiving', function () { }) 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) => { + const jobs = Array.from(this.docs).map(doc => + (doc => { + return callback => { return db.docs.findOne({ _id: doc._id }, (error, doc) => { expect(doc.lines).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) { - const jobs = Array.from(this.docs).map((doc) => - ((doc) => { - return (callback) => { + const jobs = Array.from(this.docs).map(doc => + (doc => { + return callback => { return DocstoreClient.getS3Doc( this.project_id, doc._id, @@ -149,7 +149,7 @@ describe('Archiving', function () { return it('should restore the docs to mongo', function (done) { const jobs = Array.from(this.docs).map((doc, i) => ((doc, i) => { - return (callback) => { + return callback => { return db.docs.findOne({ _id: doc._id }, (error, doc) => { doc.lines.should.deep.equal(this.docs[i].lines) doc.ranges.should.deep.equal(this.docs[i].ranges) @@ -171,7 +171,7 @@ describe('Archiving', function () { _id: ObjectId(), lines: ['one', 'two', 'three'], ranges: {}, - version: 2 + version: 2, } return DocstoreClient.createDoc( this.project_id, @@ -179,14 +179,14 @@ describe('Archiving', function () { this.doc.lines, this.doc.version, this.doc.ranges, - (error) => { + error => { if (error != null) { throw error } return DocstoreClient.deleteDoc( this.project_id, this.doc._id, - (error) => { + error => { if (error != null) { throw error } @@ -280,7 +280,8 @@ describe('Archiving', function () { Settings.docstore.keepSoftDeletedDocsArchived = true }) afterEach(function restoreSetting() { - Settings.docstore.keepSoftDeletedDocsArchived = keepSoftDeletedDocsArchived + Settings.docstore.keepSoftDeletedDocsArchived = + keepSoftDeletedDocsArchived }) describe('after unarchiving from a request for the project', function () { @@ -326,7 +327,7 @@ describe('Archiving', function () { _id: ObjectId(), lines: ['foo', 'bar'], ranges: {}, - version: 2 + version: 2, } DocstoreClient.createDoc( this.project_id, @@ -334,7 +335,7 @@ describe('Archiving', function () { this.doc.lines, this.doc.version, this.doc.ranges, - (error) => { + error => { if (error) { return done(error) } @@ -398,7 +399,7 @@ describe('Archiving', function () { _id: ObjectId(), lines: [big_line, big_line, big_line, big_line], ranges: {}, - version: 2 + version: 2, } return DocstoreClient.createDoc( this.project_id, @@ -406,7 +407,7 @@ describe('Archiving', function () { this.doc.lines, this.doc.version, this.doc.ranges, - (error) => { + error => { if (error != null) { 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', '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]', - 'Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗' + 'Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗', ], ranges: {}, - version: 2 + version: 2, } return DocstoreClient.createDoc( this.project_id, @@ -880,7 +881,7 @@ describe('Archiving', function () { this.doc.lines, this.doc.version, this.doc.ranges, - (error) => { + error => { if (error != null) { throw error } @@ -968,17 +969,17 @@ describe('Archiving', function () { op: { i: 'foo', p: 24 }, metadata: { user_id: ObjectId(), - ts: new Date('2017-01-27T16:10:44.194Z') - } + ts: new Date('2017-01-27T16:10:44.194Z'), + }, }, { id: ObjectId(), op: { d: 'bar', p: 50 }, metadata: { user_id: ObjectId(), - ts: new Date('2017-01-27T18:10:44.194Z') - } - } + ts: new Date('2017-01-27T18:10:44.194Z'), + }, + }, ], comments: [ { @@ -986,12 +987,12 @@ describe('Archiving', function () { op: { c: 'comment', p: 284, t: ObjectId() }, metadata: { 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( this.project_id, @@ -999,7 +1000,7 @@ describe('Archiving', function () { this.doc.lines, this.doc.version, this.doc.ranges, - (error) => { + error => { if (error != null) { throw error } @@ -1082,7 +1083,7 @@ describe('Archiving', function () { _id: ObjectId(), lines: ['abc', 'def', 'ghi'], ranges: {}, - version: 2 + version: 2, } return DocstoreClient.createDoc( this.project_id, @@ -1090,7 +1091,7 @@ describe('Archiving', function () { this.doc.lines, this.doc.version, this.doc.ranges, - (error) => { + error => { if (error != null) { throw error } @@ -1178,21 +1179,21 @@ describe('Archiving', function () { _id: ObjectId(), lines: ['abc', 'def', 'ghi'], ranges: {}, - version: 2 + version: 2, } uploadContent( `${this.project_id}/${this.doc._id}`, this.doc.lines, - (error) => { + error => { expect(error).not.to.exist db.docs.insert( { project_id: this.project_id, _id: this.doc._id, rev: this.doc.version, - inS3: true + inS3: true, }, - (error) => { + error => { if (error != null) { throw error } diff --git a/services/docstore/test/acceptance/js/DeletingDocsTests.js b/services/docstore/test/acceptance/js/DeletingDocsTests.js index bc38f3fad8..4e9e987958 100644 --- a/services/docstore/test/acceptance/js/DeletingDocsTests.js +++ b/services/docstore/test/acceptance/js/DeletingDocsTests.js @@ -33,7 +33,7 @@ function deleteTestSuite(deleteDoc) { this.lines, this.version, this.ranges, - (error) => { + error => { if (error != null) { throw error } @@ -92,7 +92,7 @@ function deleteTestSuite(deleteDoc) { it('should not export the doc to s3', function (done) { 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) done() }) @@ -311,7 +311,7 @@ describe('Delete via PATCH', function () { (error, deletedDocs) => { if (error) return done(error) expect(deletedDocs).to.deep.equal([ - { _id: this.doc_id.toString(), name: 'main.tex' } + { _id: this.doc_id.toString(), name: 'main.tex' }, ]) done() } @@ -366,7 +366,7 @@ describe('Delete via PATCH', function () { expect(deletedDocs).to.deep.equal([ { _id: this.doc_id3.toString(), name: 'three.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() } @@ -391,7 +391,7 @@ describe('Delete via PATCH', function () { expect(deletedDocs).to.deep.equal([ { _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 ]) done() @@ -436,7 +436,7 @@ describe("Destroying a project's documents", function () { return describe('when the doc is archived', function () { beforeEach(function (done) { - return DocstoreClient.archiveAllDoc(this.project_id, (err) => { + return DocstoreClient.archiveAllDoc(this.project_id, err => { if (err != null) { 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 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) done() }) diff --git a/services/docstore/test/acceptance/js/GettingAllDocsTests.js b/services/docstore/test/acceptance/js/GettingAllDocsTests.js index 2d38ca5fba..76b3d70b78 100644 --- a/services/docstore/test/acceptance/js/GettingAllDocsTests.js +++ b/services/docstore/test/acceptance/js/GettingAllDocsTests.js @@ -26,31 +26,31 @@ describe('Getting all docs', function () { _id: ObjectId(), lines: ['one', 'two', 'three'], ranges: { mock: 'one' }, - rev: 2 + rev: 2, }, { _id: ObjectId(), lines: ['aaa', 'bbb', 'ccc'], ranges: { mock: 'two' }, - rev: 4 + rev: 4, }, { _id: ObjectId(), lines: ['111', '222', '333'], ranges: { mock: 'three' }, - rev: 6 - } + rev: 6, + }, ] this.deleted_doc = { _id: ObjectId(), lines: ['deleted'], ranges: { mock: 'four' }, - rev: 8 + rev: 8, } const version = 42 - const jobs = Array.from(this.docs).map((doc) => - ((doc) => { - return (callback) => { + const jobs = Array.from(this.docs).map(doc => + (doc => { + return callback => { return DocstoreClient.createDoc( this.project_id, doc._id, @@ -62,14 +62,14 @@ describe('Getting all docs', function () { } })(doc) ) - jobs.push((cb) => { + jobs.push(cb => { return DocstoreClient.createDoc( this.project_id, this.deleted_doc._id, this.deleted_doc.lines, version, this.deleted_doc.ranges, - (err) => { + err => { return DocstoreClient.deleteDoc( this.project_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) }) diff --git a/services/docstore/test/acceptance/js/GettingDocsTests.js b/services/docstore/test/acceptance/js/GettingDocsTests.js index 7847abd84a..857e0cb3ae 100644 --- a/services/docstore/test/acceptance/js/GettingDocsTests.js +++ b/services/docstore/test/acceptance/js/GettingDocsTests.js @@ -30,10 +30,10 @@ describe('Getting a doc', function () { op: { i: 'foo', p: 3 }, meta: { user_id: ObjectId().toString(), - ts: new Date().toString() - } - } - ] + ts: new Date().toString(), + }, + }, + ], } return DocstoreApp.ensureRunning(() => { return DocstoreClient.createDoc( @@ -42,7 +42,7 @@ describe('Getting a doc', function () { this.lines, this.version, this.ranges, - (error) => { + error => { if (error != null) { throw error } @@ -92,7 +92,7 @@ describe('Getting a doc', function () { this.lines, this.version, this.ranges, - (error) => { + error => { if (error != null) { throw error } diff --git a/services/docstore/test/acceptance/js/UpdatingDocsTests.js b/services/docstore/test/acceptance/js/UpdatingDocsTests.js index 45d3cb9239..eda60ae1aa 100644 --- a/services/docstore/test/acceptance/js/UpdatingDocsTests.js +++ b/services/docstore/test/acceptance/js/UpdatingDocsTests.js @@ -29,10 +29,10 @@ describe('Applying updates to a doc', function () { op: { i: 'foo', p: 3 }, meta: { user_id: ObjectId().toString(), - ts: new Date().toString() - } - } - ] + ts: new Date().toString(), + }, + }, + ], } this.newRanges = { changes: [ @@ -41,10 +41,10 @@ describe('Applying updates to a doc', function () { op: { i: 'bar', p: 6 }, meta: { user_id: ObjectId().toString(), - ts: new Date().toString() - } - } - ] + ts: new Date().toString(), + }, + }, + ], } this.version = 42 return DocstoreApp.ensureRunning(() => { @@ -54,7 +54,7 @@ describe('Applying updates to a doc', function () { this.originalLines, this.version, this.originalRanges, - (error) => { + error => { if (error != null) { throw error } diff --git a/services/docstore/test/acceptance/js/helpers/DocstoreApp.js b/services/docstore/test/acceptance/js/helpers/DocstoreApp.js index d541a8f454..4a45a7e6d6 100644 --- a/services/docstore/test/acceptance/js/helpers/DocstoreApp.js +++ b/services/docstore/test/acceptance/js/helpers/DocstoreApp.js @@ -32,23 +32,19 @@ module.exports = { this.initing = true this.callbacks.push(callback) waitForDb().then(() => { - return app.listen( - settings.internal.docstore.port, - 'localhost', - (error) => { - if (error != null) { - throw error - } - this.running = true - return (() => { - const result = [] - for (callback of Array.from(this.callbacks)) { - result.push(callback()) - } - return result - })() + return app.listen(settings.internal.docstore.port, 'localhost', error => { + if (error != null) { + throw error } - ) + this.running = true + return (() => { + const result = [] + for (callback of Array.from(this.callbacks)) { + result.push(callback()) + } + return result + })() + }) }) - } + }, } diff --git a/services/docstore/test/acceptance/js/helpers/DocstoreClient.js b/services/docstore/test/acceptance/js/helpers/DocstoreClient.js index 49b50907bb..1164540bd3 100644 --- a/services/docstore/test/acceptance/js/helpers/DocstoreClient.js +++ b/services/docstore/test/acceptance/js/helpers/DocstoreClient.js @@ -19,7 +19,7 @@ const Persistor = require('../../../../app/js/PersistorManager') async function streamToString(stream) { const chunks = [] 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('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}`, json: true, - qs + qs, }, callback ) @@ -64,7 +64,7 @@ module.exports = DocstoreClient = { request.get( { url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}/deleted`, - json: true + json: true, }, callback ) @@ -77,7 +77,7 @@ module.exports = DocstoreClient = { return request.get( { url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc`, - json: true + json: true, }, (req, res, body) => { callback(req, res, body) @@ -89,7 +89,7 @@ module.exports = DocstoreClient = { request.get( { url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc-deleted`, - json: true + json: true, }, (error, res, body) => { if (error) return callback(error) @@ -108,7 +108,7 @@ module.exports = DocstoreClient = { return request.get( { url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/ranges`, - json: true + json: true, }, callback ) @@ -124,8 +124,8 @@ module.exports = DocstoreClient = { json: { lines, version, - ranges - } + ranges, + }, }, callback ) @@ -165,7 +165,7 @@ module.exports = DocstoreClient = { request.patch( { url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`, - json: { name, deleted: true, deletedAt } + json: { name, deleted: true, deletedAt }, }, callback ) @@ -177,7 +177,7 @@ module.exports = DocstoreClient = { } 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 ) @@ -189,7 +189,7 @@ module.exports = DocstoreClient = { } 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 ) @@ -201,7 +201,7 @@ module.exports = DocstoreClient = { } 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 ) @@ -213,9 +213,9 @@ module.exports = DocstoreClient = { settings.docstore.bucket, `${project_id}/${doc_id}` ) - .then((data) => { + .then(data => { callback(null, JSON.parse(data)) }) .catch(callback) - } + }, } diff --git a/services/docstore/test/setup.js b/services/docstore/test/setup.js index f738f1c70f..fbf29a495b 100644 --- a/services/docstore/test/setup.js +++ b/services/docstore/test/setup.js @@ -17,16 +17,16 @@ const stubs = { warn: sandbox.stub(), err: sandbox.stub(), error: sandbox.stub(), - fatal: sandbox.stub() - } + fatal: sandbox.stub(), + }, } // SandboxedModule configuration SandboxedModule.configure({ requires: { - 'logger-sharelatex': stubs.logger + 'logger-sharelatex': stubs.logger, }, - globals: { Buffer, JSON, console, process } + globals: { Buffer, JSON, console, process }, }) exports.mochaHooks = { @@ -36,5 +36,5 @@ exports.mochaHooks = { afterEach() { sandbox.reset() - } + }, } diff --git a/services/docstore/test/unit/js/DocArchiveManagerTests.js b/services/docstore/test/unit/js/DocArchiveManagerTests.js index 0316343c0f..39369715d7 100644 --- a/services/docstore/test/unit/js/DocArchiveManagerTests.js +++ b/services/docstore/test/unit/js/DocArchiveManagerTests.js @@ -27,23 +27,23 @@ describe('DocArchiveManager', function () { md5Sum = 'decafbad' RangeManager = { - jsonRangesToMongo: sinon.stub().returns({ mongo: 'ranges' }) + jsonRangesToMongo: sinon.stub().returns({ mongo: 'ranges' }), } Settings = { docstore: { - bucket: 'wombat' + bucket: 'wombat', }, parallelArchiveJobs: 3, destroyBatchSize: 10, - destroyRetryCount: 3 + destroyRetryCount: 3, } HashDigest = sinon.stub().returns(md5Sum) HashUpdate = sinon.stub().returns({ digest: HashDigest }) Crypto = { - createHash: sinon.stub().returns({ update: HashUpdate }) + createHash: sinon.stub().returns({ update: HashUpdate }), } Streamifier = { - createReadStream: sinon.stub().returns({ stream: 'readStream' }) + createReadStream: sinon.stub().returns({ stream: 'readStream' }), } projectId = ObjectId() @@ -51,75 +51,75 @@ describe('DocArchiveManager', function () { { _id: ObjectId(), inS3: true, - rev: 2 + rev: 2, }, { _id: ObjectId(), inS3: true, - rev: 4 + rev: 4, }, { _id: ObjectId(), inS3: true, - rev: 6 - } + rev: 6, + }, ] mongoDocs = [ { _id: ObjectId(), lines: ['one', 'two', 'three'], - rev: 2 + rev: 2, }, { _id: ObjectId(), lines: ['aaa', 'bbb', 'ccc'], - rev: 4 + rev: 4, }, { _id: ObjectId(), inS3: true, - rev: 6 + rev: 6, }, { _id: ObjectId(), inS3: true, - rev: 6 + rev: 6, }, { _id: ObjectId(), lines: ['111', '222', '333'], - rev: 6 - } + rev: 6, + }, ] docJson = JSON.stringify({ lines: mongoDocs[0].lines, ranges: mongoDocs[0].ranges, - schema_v: 1 + schema_v: 1, }) stream = { on: sinon.stub(), - resume: sinon.stub() + resume: sinon.stub(), } stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8')) stream.on.withArgs('end').yields() readStream = { - stream: 'readStream' + stream: 'readStream', } PersistorManager = { getObjectStream: sinon.stub().resolves(stream), sendStream: sinon.stub().resolves(), getObjectMd5Hash: sinon.stub().resolves(md5Sum), - deleteObject: sinon.stub().resolves() + deleteObject: sinon.stub().resolves(), } const getNonArchivedProjectDocs = sinon.stub() getNonArchivedProjectDocs .onCall(0) - .resolves(mongoDocs.filter((doc) => !doc.inS3)) + .resolves(mongoDocs.filter(doc => !doc.inS3)) getNonArchivedProjectDocs.onCall(1).resolves([]) const getArchivedProjectDocs = sinon.stub() @@ -135,8 +135,8 @@ describe('DocArchiveManager', function () { getNonArchivedProjectDocs, getArchivedProjectDocs, findDoc: sinon.stub().rejects(new Errors.NotFoundError()), - destroyDoc: sinon.stub().resolves() - } + destroyDoc: sinon.stub().resolves(), + }, } for (const mongoDoc of mongoDocs.concat(archivedDocs)) { MongoManager.promises.findDoc @@ -152,8 +152,8 @@ describe('DocArchiveManager', function () { './MongoManager': MongoManager, './RangeManager': RangeManager, './PersistorManager': PersistorManager, - './Errors': Errors - } + './Errors': Errors, + }, }) }) @@ -184,7 +184,7 @@ describe('DocArchiveManager', function () { const json = JSON.stringify({ lines: mongoDocs[0].lines, ranges: mongoDocs[0].ranges, - schema_v: 1 + schema_v: 1, }) await DocArchiveManager.promises.archiveDoc(projectId, mongoDocs[0]) @@ -277,7 +277,7 @@ describe('DocArchiveManager', function () { expect( MongoManager.promises.upsertIntoDocCollection ).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 () { beforeEach(function () { mongoDoc = { - lines: ['doc', 'lines'] + lines: ['doc', 'lines'], } s3Doc = ['doc', 'lines'] docJson = JSON.stringify(s3Doc) @@ -315,11 +315,11 @@ describe('DocArchiveManager', function () { s3Doc = { lines: ['doc', 'lines'], ranges: { json: 'ranges' }, - schema_v: 1 + schema_v: 1, } mongoDoc = { lines: ['doc', 'lines'], - ranges: { mongo: 'ranges' } + ranges: { mongo: 'ranges' }, } docJson = JSON.stringify(s3Doc) stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8')) @@ -337,10 +337,10 @@ describe('DocArchiveManager', function () { beforeEach(function () { s3Doc = { lines: ['doc', 'lines'], - schema_v: 1 + schema_v: 1, } mongoDoc = { - lines: ['doc', 'lines'] + lines: ['doc', 'lines'], } docJson = JSON.stringify(s3Doc) stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8')) @@ -358,7 +358,7 @@ describe('DocArchiveManager', function () { beforeEach(function () { s3Doc = { lines: ['doc', 'lines'], - schema_v: 2 + schema_v: 2, } docJson = JSON.stringify(s3Doc) stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8')) diff --git a/services/docstore/test/unit/js/DocManagerTests.js b/services/docstore/test/unit/js/DocManagerTests.js index 60b3a20885..f81cc6a241 100644 --- a/services/docstore/test/unit/js/DocManagerTests.js +++ b/services/docstore/test/unit/js/DocManagerTests.js @@ -29,11 +29,11 @@ describe('DocManager', function () { jsonRangesToMongo(r) { return r }, - shouldUpdateRanges: sinon.stub().returns(false) + shouldUpdateRanges: sinon.stub().returns(false), }), '@overleaf/settings': (this.settings = { docstore: {} }), - './Errors': Errors - } + './Errors': Errors, + }, }) this.doc_id = ObjectId().toString() this.project_id = ObjectId().toString() @@ -47,7 +47,7 @@ describe('DocManager', function () { this.DocManager._getDoc = sinon.stub() return (this.doc = { _id: this.doc_id, - lines: ['2134'] + lines: ['2134'], }) }) @@ -65,7 +65,7 @@ describe('DocManager', function () { deleted: true, version: true, ranges: true, - inS3: true + inS3: true, }) .should.equal(true) return done() @@ -102,7 +102,7 @@ describe('DocManager', function () { this.DocManager._getDoc .calledWith(this.project_id, this.doc_id, { lines: true, - inS3: true + inS3: true, }) .should.equal(true) return done() @@ -129,7 +129,7 @@ describe('DocManager', function () { this.doc = { _id: this.doc_id, project_id: this.project_id, - lines: ['mock-lines'] + lines: ['mock-lines'], } this.version = 42 this.MongoManager.findDoc = sinon.stub() @@ -148,7 +148,7 @@ describe('DocManager', function () { this.project_id, this.doc_id, { inS3: false }, - (err) => { + err => { expect(err).to.exist return done() } @@ -160,7 +160,7 @@ describe('DocManager', function () { this.project_id, this.doc_id, undefined, - (err) => { + err => { this.MongoManager.findDoc.called.should.equal(false) expect(err).to.exist return done() @@ -173,7 +173,7 @@ describe('DocManager', function () { this.project_id, this.doc_id, { inS3: true }, - (err) => { + err => { expect(err).to.not.exist return done() } @@ -250,7 +250,7 @@ describe('DocManager', function () { _id: this.doc_id, project_id: this.project_id, lines: ['mock-lines'], - inS3: true + inS3: true, } this.MongoManager.findDoc.yields(null, this.doc) this.DocArchiveManager.unarchiveDoc = ( @@ -316,8 +316,8 @@ describe('DocManager', function () { { _id: this.doc_id, project_id: this.project_id, - lines: ['mock-lines'] - } + lines: ['mock-lines'], + }, ] this.MongoManager.getProjectsDocs = sinon .stub() @@ -499,7 +499,7 @@ describe('DocManager', function () { sinon.match({ project_id: this.project_id, doc_id: this.doc_id, - err: this.err + err: this.err, }), 'archiving a single doc in the background failed' ) @@ -545,10 +545,10 @@ describe('DocManager', function () { op: { i: 'foo', p: 3 }, meta: { user_id: ObjectId().toString(), - ts: new Date().toString() - } - } - ] + ts: new Date().toString(), + }, + }, + ], } this.newRanges = { changes: [ @@ -557,10 +557,10 @@ describe('DocManager', function () { op: { i: 'bar', p: 6 }, meta: { user_id: ObjectId().toString(), - ts: new Date().toString() - } - } - ] + ts: new Date().toString(), + }, + }, + ], } this.version = 42 this.doc = { @@ -569,7 +569,7 @@ describe('DocManager', function () { lines: this.oldDocLines, rev: (this.rev = 5), version: this.version, - ranges: this.originalRanges + ranges: this.originalRanges, } this.MongoManager.upsertIntoDocCollection = sinon.stub().callsArg(3) @@ -598,7 +598,7 @@ describe('DocManager', function () { lines: true, version: true, ranges: true, - inS3: true + inS3: true, }) .should.equal(true) }) @@ -844,7 +844,7 @@ describe('DocManager', function () { return this.MongoManager.upsertIntoDocCollection .calledWith(this.project_id, this.doc_id, { lines: this.newDocLines, - ranges: this.originalRanges + ranges: this.originalRanges, }) .should.equal(true) }) diff --git a/services/docstore/test/unit/js/HttpControllerTests.js b/services/docstore/test/unit/js/HttpControllerTests.js index 16b7baf5b0..e60e0e705c 100644 --- a/services/docstore/test/unit/js/HttpControllerTests.js +++ b/services/docstore/test/unit/js/HttpControllerTests.js @@ -21,21 +21,21 @@ const { ObjectId } = require('mongodb') describe('HttpController', function () { beforeEach(function () { const settings = { - max_doc_length: 2 * 1024 * 1024 + max_doc_length: 2 * 1024 * 1024, } this.HttpController = SandboxedModule.require(modulePath, { requires: { './DocManager': (this.DocManager = {}), './DocArchiveManager': (this.DocArchiveManager = {}), '@overleaf/settings': settings, - './HealthChecker': {} - } + './HealthChecker': {}, + }, }) this.res = { send: sinon.stub(), sendStatus: sinon.stub(), json: sinon.stub(), - setHeader: sinon.stub() + setHeader: sinon.stub(), } this.res.status = sinon.stub().returns(this.res) this.req = { query: {} } @@ -46,14 +46,14 @@ describe('HttpController', function () { _id: this.doc_id, lines: ['mock', 'lines', ' here', '', '', ' spaces '], version: 42, - rev: 5 + rev: 5, } return (this.deletedDoc = { deleted: true, _id: this.doc_id, lines: ['mock', 'lines', ' here', '', '', ' spaces '], version: 42, - rev: 5 + rev: 5, }) }) @@ -62,7 +62,7 @@ describe('HttpController', function () { beforeEach(function () { this.req.params = { project_id: this.project_id, - doc_id: this.doc_id + doc_id: this.doc_id, } this.DocManager.getFullDoc = sinon .stub() @@ -82,7 +82,7 @@ describe('HttpController', function () { _id: this.doc_id, lines: this.doc.lines, rev: this.doc.rev, - version: this.doc.version + version: this.doc.version, }) .should.equal(true) }) @@ -92,7 +92,7 @@ describe('HttpController', function () { beforeEach(function () { this.req.params = { project_id: this.project_id, - doc_id: this.doc_id + doc_id: this.doc_id, } return (this.DocManager.getFullDoc = sinon .stub() @@ -120,7 +120,7 @@ describe('HttpController', function () { lines: this.doc.lines, rev: this.doc.rev, deleted: true, - version: this.doc.version + version: this.doc.version, }) .should.equal(true) }) @@ -131,7 +131,7 @@ describe('HttpController', function () { beforeEach(function () { this.req.params = { 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) return this.HttpController.getRawDoc(this.req, this.res, this.next) @@ -165,13 +165,13 @@ describe('HttpController', function () { { _id: ObjectId(), lines: ['mock', 'lines', 'one'], - rev: 2 + rev: 2, }, { _id: ObjectId(), lines: ['mock', 'lines', 'two'], - rev: 4 - } + rev: 4, + }, ] this.DocManager.getAllNonDeletedDocs = sinon .stub() @@ -191,13 +191,13 @@ describe('HttpController', function () { { _id: this.docs[0]._id.toString(), lines: this.docs[0].lines, - rev: this.docs[0].rev + rev: this.docs[0].rev, }, { _id: this.docs[1]._id.toString(), lines: this.docs[1].lines, - rev: this.docs[1].rev - } + rev: this.docs[1].rev, + }, ]) .should.equal(true) }) @@ -210,14 +210,14 @@ describe('HttpController', function () { { _id: ObjectId(), lines: ['mock', 'lines', 'one'], - rev: 2 + rev: 2, }, null, { _id: ObjectId(), lines: ['mock', 'lines', 'two'], - rev: 4 - } + rev: 4, + }, ] this.DocManager.getAllNonDeletedDocs = sinon .stub() @@ -231,13 +231,13 @@ describe('HttpController', function () { { _id: this.docs[0]._id.toString(), lines: this.docs[0].lines, - rev: this.docs[0].rev + rev: this.docs[0].rev, }, { _id: this.docs[2]._id.toString(), lines: this.docs[2].lines, - rev: this.docs[2].rev - } + rev: this.docs[2].rev, + }, ]) .should.equal(true) }) @@ -247,7 +247,7 @@ describe('HttpController', function () { .calledWith( { err: sinon.match.has('message', 'null doc'), - project_id: this.project_id + project_id: this.project_id, }, 'encountered null doc' ) @@ -263,12 +263,12 @@ describe('HttpController', function () { this.docs = [ { _id: ObjectId(), - ranges: { mock_ranges: 'one' } + ranges: { mock_ranges: 'one' }, }, { _id: ObjectId(), - ranges: { mock_ranges: 'two' } - } + ranges: { mock_ranges: 'two' }, + }, ] this.DocManager.getAllNonDeletedDocs = sinon .stub() @@ -287,12 +287,12 @@ describe('HttpController', function () { .calledWith([ { _id: this.docs[0]._id.toString(), - ranges: this.docs[0].ranges + ranges: this.docs[0].ranges, }, { _id: this.docs[1]._id.toString(), - ranges: this.docs[1].ranges - } + ranges: this.docs[1].ranges, + }, ]) .should.equal(true) }) @@ -303,7 +303,7 @@ describe('HttpController', function () { beforeEach(function () { return (this.req.params = { 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 = { lines: (this.lines = ['hello', 'world']), version: (this.version = 42), - ranges: (this.ranges = { changes: 'mock' }) + ranges: (this.ranges = { changes: 'mock' }), } this.DocManager.updateDoc = sinon .stub() @@ -344,7 +344,7 @@ describe('HttpController', function () { this.req.body = { lines: (this.lines = ['hello', 'world']), version: (this.version = 42), - ranges: {} + ranges: {}, } this.DocManager.updateDoc = sinon .stub() @@ -412,7 +412,7 @@ describe('HttpController', function () { this.req.body = { lines: (this.lines = Array(2049).fill('a'.repeat(1024))), version: (this.version = 42), - ranges: (this.ranges = { changes: 'mock' }) + ranges: (this.ranges = { changes: 'mock' }), } return this.HttpController.updateDoc(this.req, this.res, this.next) }) @@ -431,7 +431,7 @@ describe('HttpController', function () { beforeEach(function () { this.req.params = { project_id: this.project_id, - doc_id: this.doc_id + doc_id: this.doc_id, } this.req.body = { name: 'foo.tex' } this.DocManager.patchDoc = sinon.stub().yields(null) diff --git a/services/docstore/test/unit/js/MongoManagerTests.js b/services/docstore/test/unit/js/MongoManagerTests.js index 1e80fd1f21..50cc8268c3 100644 --- a/services/docstore/test/unit/js/MongoManagerTests.js +++ b/services/docstore/test/unit/js/MongoManagerTests.js @@ -24,11 +24,11 @@ describe('MongoManager', function () { requires: { './mongodb': { db: (this.db = { docs: {}, docOps: {} }), - ObjectId + ObjectId, }, '@overleaf/metrics': { timeAsyncMethod: sinon.stub() }, - '@overleaf/settings': { max_deleted_docs: 42 } - } + '@overleaf/settings': { max_deleted_docs: 42 }, + }, }) this.project_id = ObjectId().toString() this.doc_id = ObjectId().toString() @@ -54,10 +54,10 @@ describe('MongoManager', function () { .calledWith( { _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) @@ -85,10 +85,10 @@ describe('MongoManager', function () { this.db.docs.updateOne.should.have.been.calledWith( { _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 ) @@ -105,7 +105,7 @@ describe('MongoManager', function () { this.db.docs.find = sinon.stub().returns({ toArray: sinon .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( { project_id: ObjectId(this.project_id), - deleted: { $ne: true } + deleted: { $ne: true }, }, { - projection: this.filter + projection: this.filter, } ) .should.equal(true) @@ -154,10 +154,10 @@ describe('MongoManager', function () { return this.db.docs.find .calledWith( { - project_id: ObjectId(this.project_id) + project_id: ObjectId(this.project_id), }, { - projection: this.filter + projection: this.filter, } ) .should.equal(true) @@ -178,7 +178,7 @@ describe('MongoManager', function () { this.doc2 = { _id: '2', name: 'mock-doc2.tex' } this.doc3 = { _id: '3', name: 'mock-doc3.tex' } 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.MongoManager.getProjectsDeletedDocs( @@ -192,7 +192,7 @@ describe('MongoManager', function () { this.db.docs.find .calledWith({ project_id: ObjectId(this.project_id), - deleted: true + deleted: true, }) .should.equal(true) }) @@ -202,7 +202,7 @@ describe('MongoManager', function () { .calledWith(sinon.match.any, { projection: this.filter, sort: { deletedAt: -1 }, - limit: 42 + limit: 42, }) .should.equal(true) }) @@ -225,7 +225,7 @@ describe('MongoManager', function () { this.project_id, this.doc_id, { lines: this.lines }, - (err) => { + err => { const args = this.db.docs.updateOne.args[0] assert.deepEqual(args[0], { _id: ObjectId(this.doc_id) }) assert.equal(args[1].$set.lines, this.lines) @@ -241,7 +241,7 @@ describe('MongoManager', function () { this.project_id, this.doc_id, { lines: this.lines }, - (err) => { + err => { err.should.equal(this.stubbedErr) return done() } @@ -258,13 +258,13 @@ describe('MongoManager', function () { it('should destroy the doc', function () { return sinon.assert.calledWith(this.db.docs.deleteOne, { - _id: ObjectId('123456789012') + _id: ObjectId('123456789012'), }) }) return it('should destroy the docOps', function () { return sinon.assert.calledWith(this.db.docOps.deleteOne, { - doc_id: ObjectId('123456789012') + doc_id: ObjectId('123456789012'), }) }) }) @@ -282,7 +282,7 @@ describe('MongoManager', function () { .calledWith( { doc_id: ObjectId(this.doc_id) }, { - projection: { version: 1 } + projection: { version: 1 }, } ) .should.equal(true) @@ -320,15 +320,15 @@ describe('MongoManager', function () { return this.db.docOps.updateOne .calledWith( { - doc_id: ObjectId(this.doc_id) + doc_id: ObjectId(this.doc_id), }, { $set: { - version: this.version - } + version: this.version, + }, }, { - upsert: true + upsert: true, } ) .should.equal(true) diff --git a/services/docstore/test/unit/js/RangeManagerTests.js b/services/docstore/test/unit/js/RangeManagerTests.js index afea8f04c6..271d9daa69 100644 --- a/services/docstore/test/unit/js/RangeManagerTests.js +++ b/services/docstore/test/unit/js/RangeManagerTests.js @@ -25,9 +25,9 @@ describe('RangeManager', function () { return (this.RangeManager = SandboxedModule.require(modulePath, { requires: { './mongodb': { - ObjectId - } - } + ObjectId, + }, + }, })) }) @@ -45,16 +45,16 @@ describe('RangeManager', function () { op: { i: 'foo', p: 3 }, metadata: { user_id, - ts - } - } + ts, + }, + }, ], comments: [ { id: comment_id, - op: { c: 'foo', p: 3, t: thread_id } - } - ] + op: { c: 'foo', p: 3, t: thread_id }, + }, + ], }).should.deep.equal({ changes: [ { @@ -62,16 +62,16 @@ describe('RangeManager', function () { op: { i: 'foo', p: 3 }, metadata: { user_id: ObjectId(user_id), - ts: new Date(ts) - } - } + ts: new Date(ts), + }, + }, ], comments: [ { 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, metadata: { - user_id - } - } + user_id, + }, + }, ], comments: [ { - id: comment_id - } - ] + id: comment_id, + }, + ], }).should.deep.equal({ changes: [ { id: change_id, metadata: { - user_id - } - } + user_id, + }, + }, ], comments: [ { - id: comment_id - } - ] + id: comment_id, + }, + ], }) }) @@ -123,16 +123,16 @@ describe('RangeManager', function () { op: { i: 'foo', p: 3 }, metadata: { user_id, - ts - } - } + ts, + }, + }, ], comments: [ { 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 ranges2 = JSON.parse( @@ -151,16 +151,16 @@ describe('RangeManager', function () { op: { i: 'foo', p: 3 }, metadata: { user_id: ObjectId(), - ts: new Date() - } - } + ts: new Date(), + }, + }, ], comments: [ { id: ObjectId(), - op: { c: 'foo', p: 3, t: ObjectId() } - } - ] + op: { c: 'foo', p: 3, t: ObjectId() }, + }, + ], } return (this.ranges_copy = this.RangeManager.jsonRangesToMongo( JSON.parse(JSON.stringify(this.ranges))