Browse Source

fix formatting

Tim Alby 6 years ago
parent
commit
d3a7ffd1a9
65 changed files with 1685 additions and 1459 deletions
  1. 10 10
      services/track-changes/app.js
  2. 8 0
      services/track-changes/app.js.map
  3. 1 1
      services/track-changes/app/js/DiffGenerator.js
  4. 8 0
      services/track-changes/app/js/DiffGenerator.js.map
  5. 10 10
      services/track-changes/app/js/DiffManager.js
  6. 8 0
      services/track-changes/app/js/DiffManager.js.map
  7. 4 4
      services/track-changes/app/js/DocumentUpdaterManager.js
  8. 8 0
      services/track-changes/app/js/DocumentUpdaterManager.js.map
  9. 6 6
      services/track-changes/app/js/HealthChecker.js
  10. 10 0
      services/track-changes/app/js/HealthChecker.js.map
  11. 41 40
      services/track-changes/app/js/HttpController.js
  12. 8 0
      services/track-changes/app/js/HttpController.js.map
  13. 13 13
      services/track-changes/app/js/LockManager.js
  14. 8 0
      services/track-changes/app/js/LockManager.js.map
  15. 19 19
      services/track-changes/app/js/MongoAWS.js
  16. 8 0
      services/track-changes/app/js/MongoAWS.js.map
  17. 11 12
      services/track-changes/app/js/MongoManager.js
  18. 8 0
      services/track-changes/app/js/MongoManager.js.map
  19. 108 100
      services/track-changes/app/js/PackManager.js
  20. 8 0
      services/track-changes/app/js/PackManager.js.map
  21. 18 18
      services/track-changes/app/js/PackWorker.js
  22. 8 0
      services/track-changes/app/js/PackWorker.js.map
  23. 1 1
      services/track-changes/app/js/ProjectIterator.js
  24. 10 0
      services/track-changes/app/js/ProjectIterator.js.map
  25. 13 13
      services/track-changes/app/js/RedisManager.js
  26. 8 0
      services/track-changes/app/js/RedisManager.js.map
  27. 3 3
      services/track-changes/app/js/RestoreManager.js
  28. 10 0
      services/track-changes/app/js/RestoreManager.js.map
  29. 10 7
      services/track-changes/app/js/UpdateCompressor.js
  30. 8 0
      services/track-changes/app/js/UpdateCompressor.js.map
  31. 8 6
      services/track-changes/app/js/UpdateTrimmer.js
  32. 10 0
      services/track-changes/app/js/UpdateTrimmer.js.map
  33. 67 67
      services/track-changes/app/js/UpdatesManager.js
  34. 8 0
      services/track-changes/app/js/UpdatesManager.js.map
  35. 6 6
      services/track-changes/app/js/WebApiManager.js
  36. 8 0
      services/track-changes/app/js/WebApiManager.js.map
  37. 10 0
      services/track-changes/app/js/mongojs.js.map
  38. 388 340
      services/track-changes/app/lib/diff_match_patch.js
  39. 7 7
      services/track-changes/config/settings.defaults.js
  40. 51 51
      services/track-changes/test/acceptance/js/AppendingUpdatesTests.js
  41. 36 28
      services/track-changes/test/acceptance/js/ArchivingUpdatesTests.js
  42. 25 25
      services/track-changes/test/acceptance/js/FlushingUpdatesTests.js
  43. 6 6
      services/track-changes/test/acceptance/js/GettingADiffTests.js
  44. 10 11
      services/track-changes/test/acceptance/js/GettingUpdatesTests.js
  45. 9 9
      services/track-changes/test/acceptance/js/LockManagerTests.js
  46. 6 6
      services/track-changes/test/acceptance/js/RestoringVersions.js
  47. 3 3
      services/track-changes/test/acceptance/js/helpers/MockDocStoreApi.js
  48. 19 22
      services/track-changes/test/acceptance/js/helpers/MockDocUpdaterApi.js
  49. 4 4
      services/track-changes/test/acceptance/js/helpers/MockWebApi.js
  50. 3 3
      services/track-changes/test/acceptance/js/helpers/TrackChangesApp.js
  51. 18 18
      services/track-changes/test/acceptance/js/helpers/TrackChangesClient.js
  52. 59 59
      services/track-changes/test/unit/js/DiffGenerator/DiffGeneratorTests.js
  53. 56 57
      services/track-changes/test/unit/js/DiffManager/DiffManagerTests.js
  54. 8 8
      services/track-changes/test/unit/js/DocArchive/MongoAWS.js
  55. 25 25
      services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js
  56. 22 22
      services/track-changes/test/unit/js/HttpController/HttpControllerTests.js
  57. 61 61
      services/track-changes/test/unit/js/LockManager/LockManagerTests.js
  58. 34 34
      services/track-changes/test/unit/js/MongoManager/MongoManagerTests.js
  59. 90 90
      services/track-changes/test/unit/js/PackManager/PackManagerTests.js
  60. 20 20
      services/track-changes/test/unit/js/RedisManager/RedisManagerTests.js
  61. 7 7
      services/track-changes/test/unit/js/RestoreManager/RestoreManagerTests.js
  62. 39 39
      services/track-changes/test/unit/js/UpdateCompressor/UpdateCompressorTests.js
  63. 32 32
      services/track-changes/test/unit/js/UpdateTrimmer/UpdateTrimmerTests.js
  64. 109 109
      services/track-changes/test/unit/js/UpdatesManager/UpdatesManagerTests.js
  65. 27 27
      services/track-changes/test/unit/js/WebApiManager/WebApiManagerTests.js

+ 10 - 10
services/track-changes/app.js

@@ -16,9 +16,9 @@ if ((Settings.sentry != null ? Settings.sentry.dsn : undefined) != null) {
 }
 
 // log updates as truncated strings
-const truncateFn = updates =>
+const truncateFn = (updates) =>
   JSON.parse(
-    JSON.stringify(updates, function(key, value) {
+    JSON.stringify(updates, function (key, value) {
       let len
       if (typeof value === 'string' && (len = value.length) > 80) {
         return (
@@ -46,7 +46,7 @@ const child_process = require('child_process')
 
 const HttpController = require('./app/js/HttpController')
 const express = require('express')
-const bodyParser = require('body-parser');
+const bodyParser = require('body-parser')
 
 const app = express()
 
@@ -79,7 +79,7 @@ app.post('/check/dangling', HttpController.checkDanglingUpdates)
 
 let packWorker = null // use a single packing worker
 
-app.post('/pack', function(req, res, next) {
+app.post('/pack', function (req, res, next) {
   if (packWorker != null) {
     return res.send('pack already running')
   } else {
@@ -89,7 +89,7 @@ app.post('/pack', function(req, res, next) {
       req.query.delay || 1000,
       req.query.timeout || 30 * 60 * 1000
     ])
-    packWorker.on('exit', function(code, signal) {
+    packWorker.on('exit', function (code, signal) {
       logger.log({ code, signal }, 'history auto pack exited')
       return (packWorker = null)
     })
@@ -99,7 +99,7 @@ app.post('/pack', function(req, res, next) {
 
 app.get('/status', (req, res, next) => res.send('track-changes is alive'))
 
-app.get('/oops', function(req, res, next) {
+app.get('/oops', function (req, res, next) {
   throw new Error('dummy test error')
 })
 
@@ -107,7 +107,7 @@ app.get('/check_lock', HttpController.checkLock)
 
 app.get('/health_check', HttpController.healthCheck)
 
-app.use(function(error, req, res, next) {
+app.use(function (error, req, res, next) {
   logger.error({ err: error, req }, 'an internal error occured')
   return res.send(500)
 })
@@ -115,17 +115,17 @@ app.use(function(error, req, res, next) {
 const port =
   __guard__(
     Settings.internal != null ? Settings.internal.trackchanges : undefined,
-    x => x.port
+    (x) => x.port
   ) || 3015
 const host =
   __guard__(
     Settings.internal != null ? Settings.internal.trackchanges : undefined,
-    x1 => x1.host
+    (x1) => x1.host
   ) || 'localhost'
 
 if (!module.parent) {
   // Called directly
-  app.listen(port, host, function(error) {
+  app.listen(port, host, function (error) {
     if (error != null) {
       return logger.error(
         { err: error },

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app.js.map


+ 1 - 1
services/track-changes/app/js/DiffGenerator.js

@@ -13,7 +13,7 @@
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  */
 let DiffGenerator
-var ConsistencyError = function(message) {
+var ConsistencyError = function (message) {
   const error = new Error(message)
   error.name = 'ConsistencyError'
   error.__proto__ = ConsistencyError.prototype

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app/js/DiffGenerator.js.map


+ 10 - 10
services/track-changes/app/js/DiffManager.js

@@ -22,9 +22,9 @@ module.exports = DiffManager = {
     // Get updates last, since then they must be ahead and it
     // might be possible to rewind to the same version as the doc.
     if (callback == null) {
-      callback = function(error, content, version, updates) {}
+      callback = function (error, content, version, updates) {}
     }
-    return DocumentUpdaterManager.getDocument(project_id, doc_id, function(
+    return DocumentUpdaterManager.getDocument(project_id, doc_id, function (
       error,
       content,
       version
@@ -40,7 +40,7 @@ module.exports = DiffManager = {
         project_id,
         doc_id,
         { from: fromVersion },
-        function(error, updates) {
+        function (error, updates) {
           if (error != null) {
             return callback(error)
           }
@@ -52,13 +52,13 @@ module.exports = DiffManager = {
 
   getDiff(project_id, doc_id, fromVersion, toVersion, callback) {
     if (callback == null) {
-      callback = function(error, diff) {}
+      callback = function (error, diff) {}
     }
     return DiffManager.getDocumentBeforeVersion(
       project_id,
       doc_id,
       fromVersion,
-      function(error, startingContent, updates) {
+      function (error, startingContent, updates) {
         let diff
         if (error != null) {
           if (error.message === 'broken-history') {
@@ -94,10 +94,10 @@ module.exports = DiffManager = {
     // versions.
     let retry
     if (_callback == null) {
-      _callback = function(error, document, rewoundUpdates) {}
+      _callback = function (error, document, rewoundUpdates) {}
     }
     let retries = 3
-    const callback = function(error, ...args) {
+    const callback = function (error, ...args) {
       if (error != null) {
         if (error.retry && retries > 0) {
           logger.warn(
@@ -113,7 +113,7 @@ module.exports = DiffManager = {
       }
     }
 
-    return (retry = function() {
+    return (retry = function () {
       retries--
       return DiffManager._tryGetDocumentBeforeVersion(
         project_id,
@@ -126,7 +126,7 @@ module.exports = DiffManager = {
 
   _tryGetDocumentBeforeVersion(project_id, doc_id, version, callback) {
     if (callback == null) {
-      callback = function(error, document, rewoundUpdates) {}
+      callback = function (error, document, rewoundUpdates) {}
     }
     logger.log(
       { project_id, doc_id, version },
@@ -136,7 +136,7 @@ module.exports = DiffManager = {
       project_id,
       doc_id,
       version,
-      function(error, content, version, updates) {
+      function (error, content, version, updates) {
         let startingContent
         if (error != null) {
           return callback(error)

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app/js/DiffManager.js.map


+ 4 - 4
services/track-changes/app/js/DocumentUpdaterManager.js

@@ -19,11 +19,11 @@ const Settings = require('settings-sharelatex')
 module.exports = DocumentUpdaterManager = {
   getDocument(project_id, doc_id, callback) {
     if (callback == null) {
-      callback = function(error, content, version) {}
+      callback = function (error, content, version) {}
     }
     const url = `${Settings.apis.documentupdater.url}/project/${project_id}/doc/${doc_id}`
     logger.log({ project_id, doc_id }, 'getting doc from document updater')
-    return request.get(url, function(error, res, body) {
+    return request.get(url, function (error, res, body) {
       if (error != null) {
         return callback(error)
       }
@@ -54,7 +54,7 @@ module.exports = DocumentUpdaterManager = {
 
   setDocument(project_id, doc_id, content, user_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     const url = `${Settings.apis.documentupdater.url}/project/${project_id}/doc/${doc_id}`
     logger.log({ project_id, doc_id }, 'setting doc in document updater')
@@ -68,7 +68,7 @@ module.exports = DocumentUpdaterManager = {
           undoing: true
         }
       },
-      function(error, res, body) {
+      function (error, res, body) {
         if (error != null) {
           return callback(error)
         }

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app/js/DocumentUpdaterManager.js.map


+ 6 - 6
services/track-changes/app/js/HealthChecker.js

@@ -24,10 +24,10 @@ module.exports = {
     const url = `http://localhost:${port}/project/${project_id}`
     logger.log({ project_id }, 'running health check')
     const jobs = [
-      cb =>
+      (cb) =>
         request.get(
           { url: `http://localhost:${port}/check_lock`, timeout: 3000 },
-          function(err, res, body) {
+          function (err, res, body) {
             if (err != null) {
               logger.err(
                 { err, project_id },
@@ -41,8 +41,8 @@ module.exports = {
             }
           }
         ),
-      cb =>
-        request.post({ url: `${url}/flush`, timeout: 10000 }, function(
+      (cb) =>
+        request.post({ url: `${url}/flush`, timeout: 10000 }, function (
           err,
           res,
           body
@@ -56,8 +56,8 @@ module.exports = {
             return cb()
           }
         }),
-      cb =>
-        request.get({ url: `${url}/updates`, timeout: 10000 }, function(
+      (cb) =>
+        request.get({ url: `${url}/updates`, timeout: 10000 }, function (
           err,
           res,
           body

+ 10 - 0
services/track-changes/app/js/HealthChecker.js.map

@@ -0,0 +1,10 @@
+{
+  "version": 3,
+  "file": "HealthChecker.js",
+  "sourceRoot": "../..",
+  "sources": [
+    "app/coffee/HealthChecker.coffee"
+  ],
+  "names": [],
+  "mappings": ";AAAA;AAAA,MAAA;;EAAA,QAAA,GAAW,OAAA,CAAQ,SAAR,CAAkB,CAAC;;EAC9B,OAAA,GAAU,OAAA,CAAQ,SAAR;;EACV,KAAA,GAAQ,OAAA,CAAQ,OAAR;;EACR,QAAA,GAAW,OAAA,CAAQ,qBAAR;;EACX,IAAA,GAAO,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC;;EACtC,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EACT,WAAA,GAAc,OAAA,CAAQ,eAAR;;EAEd,MAAM,CAAC,OAAP,GACC;IAAA,KAAA,EAAQ,SAAC,QAAD;AACP,UAAA;MAAA,UAAA,GAAa,QAAA,CAAS,QAAQ,CAAC,YAAY,CAAC,WAAW,CAAC,UAA3C;MACb,GAAA,GAAM,mBAAA,GAAoB,IAApB,GAAyB,WAAzB,GAAoC;MAC1C,MAAM,CAAC,GAAP,CAAW;QAAA,UAAA,EAAW,UAAX;OAAX,EAAkC,sBAAlC;MACA,IAAA,GAAO;QACN,SAAC,EAAD;iBACC,OAAO,CAAC,GAAR,CAAY;YAAC,GAAA,EAAI,mBAAA,GAAoB,IAApB,GAAyB,aAA9B;YAA4C,OAAA,EAAQ,IAApD;WAAZ,EAAuE,SAAC,GAAD,EAAM,GAAN,EAAW,IAAX;YACtE,IAAG,WAAH;cACC,MAAM,CAAC,GAAP,CAAW;gBAAA,GAAA,EAAI,GAAJ;gBAAS,UAAA,EAAW,UAApB;eAAX,EAA2C,sCAA3C;qBACA,EAAA,CAAG,GAAH,EAFD;aAAA,MAGK,mBAAG,GAAG,CAAE,oBAAL,KAAmB,GAAtB;qBACJ,EAAA,CAAG,4BAAA,GAA6B,GAAG,CAAC,UAApC,EADI;aAAA,MAAA;qBAGJ,EAAA,CAAA,EAHI;;UAJiE,CAAvE;QADD,CADM,EAUN,SAAC,EAAD;iBACC,OAAO,CAAC,IAAR,CAAa;YAAC,GAAA,EAAO,GAAD,GAAK,QAAZ;YAAqB,OAAA,EAAQ,KAA7B;WAAb,EAAkD,SAAC,GAAD,EAAM,GAAN,EAAW,IAAX;YACjD,IAAG,WAAH;cACC,MAAM,CAAC,GAAP,CAAW;gBAAA,GAAA,EAAI,GAAJ;gBAAS,UAAA,EAAW,UAApB;eAAX,EAA2C,iCAA3C;qBACA,EAAA,CAAG,GAAH,EAFD;aAAA,MAGK,mBAAG,GAAG,CAAE,oBAAL,KAAmB,GAAtB;qBACJ,EAAA,CAAG,4BAAA,GAA6B,GAAG,CAAC,UAApC,EADI;aAAA,MAAA;qBAGJ,EAAA,CAAA,EAHI;;UAJ4C,CAAlD;QADD,CAVM,EAmBN,SAAC,EAAD;iBACC,OAAO,CAAC,GAAR,CAAY;YAAC,GAAA,EAAO,GAAD,GAAK,UAAZ;YAAuB,OAAA,EAAQ,KAA/B;WAAZ,EAAmD,SAAC,GAAD,EAAM,GAAN,EAAW,IAAX;YAClD,IAAG,WAAH;cACC,MAAM,CAAC,GAAP,CAAW;gBAAA,GAAA,EAAI,GAAJ;gBAAS,UAAA,EAAW,UAApB;eAAX,EAA2C,wCAA3C;qBACA,EAAA,CAAG,GAAH,EAFD;aAAA,MAGK,mBAAG,GAAG,CAAE,oBAAL,KAAmB,GAAtB;qBACJ,EAAA,CAAG,4BAAA,GAA6B,GAAG,CAAC,UAApC,EADI;aAAA,MAAA;qBAGJ,EAAA,CAAA,EAHI;;UAJ6C,CAAnD;QADD,CAnBM;;aA6BP,KAAK,CAAC,MAAN,CAAa,IAAb,EAAmB,QAAnB;IAjCO,CAAR;IAmCA,SAAA,EAAW,SAAC,QAAD;aACV,WAAW,CAAC,WAAZ,CAAwB,QAAxB;IADU,CAnCX;;AATD"
+}

+ 41 - 40
services/track-changes/app/js/HttpController.js

@@ -24,7 +24,7 @@ const _ = require('underscore')
 module.exports = HttpController = {
   flushDoc(req, res, next) {
     if (next == null) {
-      next = function(error) {}
+      next = function (error) {}
     }
     const { doc_id } = req.params
     const { project_id } = req.params
@@ -32,7 +32,7 @@ module.exports = HttpController = {
     return UpdatesManager.processUncompressedUpdatesWithLock(
       project_id,
       doc_id,
-      function(error) {
+      function (error) {
         if (error != null) {
           return next(error)
         }
@@ -43,13 +43,13 @@ module.exports = HttpController = {
 
   flushProject(req, res, next) {
     if (next == null) {
-      next = function(error) {}
+      next = function (error) {}
     }
     const { project_id } = req.params
     logger.log({ project_id }, 'compressing project history')
     return UpdatesManager.processUncompressedUpdatesForProject(
       project_id,
-      function(error) {
+      function (error) {
         if (error != null) {
           return next(error)
         }
@@ -61,11 +61,11 @@ module.exports = HttpController = {
   flushAll(req, res, next) {
     // limit on projects to flush or -1 for all (default)
     if (next == null) {
-      next = function(error) {}
+      next = function (error) {}
     }
     const limit = req.query.limit != null ? parseInt(req.query.limit, 10) : -1
     logger.log({ limit }, 'flushing all projects')
-    return UpdatesManager.flushAll(limit, function(error, result) {
+    return UpdatesManager.flushAll(limit, function (error, result) {
       if (error != null) {
         return next(error)
       }
@@ -92,10 +92,10 @@ module.exports = HttpController = {
 
   checkDanglingUpdates(req, res, next) {
     if (next == null) {
-      next = function(error) {}
+      next = function (error) {}
     }
     logger.log('checking dangling updates')
-    return UpdatesManager.getDanglingUpdates(function(error, result) {
+    return UpdatesManager.getDanglingUpdates(function (error, result) {
       if (error != null) {
         return next(error)
       }
@@ -110,39 +110,40 @@ module.exports = HttpController = {
 
   checkDoc(req, res, next) {
     if (next == null) {
-      next = function(error) {}
+      next = function (error) {}
     }
     const { doc_id } = req.params
     const { project_id } = req.params
     logger.log({ project_id, doc_id }, 'checking doc history')
-    return DiffManager.getDocumentBeforeVersion(project_id, doc_id, 1, function(
-      error,
-      document,
-      rewoundUpdates
-    ) {
-      if (error != null) {
-        return next(error)
-      }
-      const broken = []
-      for (const update of Array.from(rewoundUpdates)) {
-        for (const op of Array.from(update.op)) {
-          if (op.broken === true) {
-            broken.push(op)
+    return DiffManager.getDocumentBeforeVersion(
+      project_id,
+      doc_id,
+      1,
+      function (error, document, rewoundUpdates) {
+        if (error != null) {
+          return next(error)
+        }
+        const broken = []
+        for (const update of Array.from(rewoundUpdates)) {
+          for (const op of Array.from(update.op)) {
+            if (op.broken === true) {
+              broken.push(op)
+            }
           }
         }
+        if (broken.length > 0) {
+          return res.send(broken)
+        } else {
+          return res.sendStatus(204)
+        }
       }
-      if (broken.length > 0) {
-        return res.send(broken)
-      } else {
-        return res.sendStatus(204)
-      }
-    })
+    )
   },
 
   getDiff(req, res, next) {
     let from, to
     if (next == null) {
-      next = function(error) {}
+      next = function (error) {}
     }
     const { doc_id } = req.params
     const { project_id } = req.params
@@ -159,7 +160,7 @@ module.exports = HttpController = {
     }
 
     logger.log({ project_id, doc_id, from, to }, 'getting diff')
-    return DiffManager.getDiff(project_id, doc_id, from, to, function(
+    return DiffManager.getDiff(project_id, doc_id, from, to, function (
       error,
       diff
     ) {
@@ -173,7 +174,7 @@ module.exports = HttpController = {
   getUpdates(req, res, next) {
     let before, min_count
     if (next == null) {
-      next = function(error) {}
+      next = function (error) {}
     }
     const { project_id } = req.params
 
@@ -187,7 +188,7 @@ module.exports = HttpController = {
     return UpdatesManager.getSummarizedProjectUpdates(
       project_id,
       { before, min_count },
-      function(error, updates, nextBeforeTimestamp) {
+      function (error, updates, nextBeforeTimestamp) {
         if (error != null) {
           return next(error)
         }
@@ -201,7 +202,7 @@ module.exports = HttpController = {
 
   restore(req, res, next) {
     if (next == null) {
-      next = function(error) {}
+      next = function (error) {}
     }
     let { doc_id, project_id, version } = req.params
     const user_id = req.headers['x-user-id']
@@ -211,7 +212,7 @@ module.exports = HttpController = {
       doc_id,
       version,
       user_id,
-      function(error) {
+      function (error) {
         if (error != null) {
           return next(error)
         }
@@ -222,12 +223,12 @@ module.exports = HttpController = {
 
   pushDocHistory(req, res, next) {
     if (next == null) {
-      next = function(error) {}
+      next = function (error) {}
     }
     const { project_id } = req.params
     const { doc_id } = req.params
     logger.log({ project_id, doc_id }, 'pushing all finalised changes to s3')
-    return PackManager.pushOldPacks(project_id, doc_id, function(error) {
+    return PackManager.pushOldPacks(project_id, doc_id, function (error) {
       if (error != null) {
         return next(error)
       }
@@ -237,12 +238,12 @@ module.exports = HttpController = {
 
   pullDocHistory(req, res, next) {
     if (next == null) {
-      next = function(error) {}
+      next = function (error) {}
     }
     const { project_id } = req.params
     const { doc_id } = req.params
     logger.log({ project_id, doc_id }, 'pulling all packs from s3')
-    return PackManager.pullOldPacks(project_id, doc_id, function(error) {
+    return PackManager.pullOldPacks(project_id, doc_id, function (error) {
       if (error != null) {
         return next(error)
       }
@@ -251,7 +252,7 @@ module.exports = HttpController = {
   },
 
   healthCheck(req, res) {
-    return HealthChecker.check(function(err) {
+    return HealthChecker.check(function (err) {
       if (err != null) {
         logger.err({ err }, 'error performing health check')
         return res.sendStatus(500)
@@ -262,7 +263,7 @@ module.exports = HttpController = {
   },
 
   checkLock(req, res) {
-    return HealthChecker.checkLock(function(err) {
+    return HealthChecker.checkLock(function (err) {
       if (err != null) {
         logger.err({ err }, 'error performing lock check')
         return res.sendStatus(500)

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app/js/HttpController.js.map


+ 13 - 13
services/track-changes/app/js/LockManager.js

@@ -40,10 +40,10 @@ module.exports = LockManager = {
 
   tryLock(key, callback) {
     if (callback == null) {
-      callback = function(err, gotLock) {}
+      callback = function (err, gotLock) {}
     }
     const lockValue = LockManager.randomLock()
-    return rclient.set(key, lockValue, 'EX', this.LOCK_TTL, 'NX', function(
+    return rclient.set(key, lockValue, 'EX', this.LOCK_TTL, 'NX', function (
       err,
       gotLock
     ) {
@@ -61,17 +61,17 @@ module.exports = LockManager = {
   getLock(key, callback) {
     let attempt
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     const startTime = Date.now()
-    return (attempt = function() {
+    return (attempt = function () {
       if (Date.now() - startTime > LockManager.MAX_LOCK_WAIT_TIME) {
         const e = new Error('Timeout')
         e.key = key
         return callback(e)
       }
 
-      return LockManager.tryLock(key, function(error, gotLock, lockValue) {
+      return LockManager.tryLock(key, function (error, gotLock, lockValue) {
         if (error != null) {
           return callback(error)
         }
@@ -86,9 +86,9 @@ module.exports = LockManager = {
 
   checkLock(key, callback) {
     if (callback == null) {
-      callback = function(err, isFree) {}
+      callback = function (err, isFree) {}
     }
-    return rclient.exists(key, function(err, exists) {
+    return rclient.exists(key, function (err, exists) {
       if (err != null) {
         return callback(err)
       }
@@ -102,7 +102,7 @@ module.exports = LockManager = {
   },
 
   releaseLock(key, lockValue, callback) {
-    return rclient.eval(LockManager.unlockScript, 1, key, lockValue, function(
+    return rclient.eval(LockManager.unlockScript, 1, key, lockValue, function (
       err,
       result
     ) {
@@ -123,14 +123,14 @@ module.exports = LockManager = {
 
   runWithLock(key, runner, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
-    return LockManager.getLock(key, function(error, lockValue) {
+    return LockManager.getLock(key, function (error, lockValue) {
       if (error != null) {
         return callback(error)
       }
-      return runner(error1 =>
-        LockManager.releaseLock(key, lockValue, function(error2) {
+      return runner((error1) =>
+        LockManager.releaseLock(key, lockValue, function (error2) {
           error = error1 || error2
           if (error != null) {
             return callback(error)
@@ -142,7 +142,7 @@ module.exports = LockManager = {
   },
 
   healthCheck(callback) {
-    const action = releaseLock => releaseLock()
+    const action = (releaseLock) => releaseLock()
     return LockManager.runWithLock(
       `HistoryLock:HealthCheck:host=${HOST}:pid=${PID}:random=${RND}`,
       action,

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app/js/LockManager.js.map


+ 19 - 19
services/track-changes/app/js/MongoAWS.js

@@ -26,7 +26,7 @@ const Metrics = require('metrics-sharelatex')
 
 const DAYS = 24 * 3600 * 1000 // one day in milliseconds
 
-const createStream = function(streamConstructor, project_id, doc_id, pack_id) {
+const createStream = function (streamConstructor, project_id, doc_id, pack_id) {
   const AWS_CONFIG = {
     accessKeyId: settings.trackchanges.s3.key,
     secretAccessKey: settings.trackchanges.s3.secret,
@@ -43,11 +43,11 @@ const createStream = function(streamConstructor, project_id, doc_id, pack_id) {
 module.exports = MongoAWS = {
   archivePack(project_id, doc_id, pack_id, _callback) {
     if (_callback == null) {
-      _callback = function(error) {}
+      _callback = function (error) {}
     }
-    const callback = function(...args) {
+    const callback = function (...args) {
       _callback(...Array.from(args || []))
-      return (_callback = function() {})
+      return (_callback = function () {})
     }
 
     const query = {
@@ -69,7 +69,7 @@ module.exports = MongoAWS = {
 
     const upload = createStream(S3S.WriteStream, project_id, doc_id, pack_id)
 
-    return db.docHistory.findOne(query, function(err, result) {
+    return db.docHistory.findOne(query, function (err, result) {
       if (err != null) {
         return callback(err)
       }
@@ -85,7 +85,7 @@ module.exports = MongoAWS = {
         logger.error({ err: error, project_id, doc_id, pack_id }, error.message)
         return callback(error)
       }
-      return zlib.gzip(uncompressedData, function(err, buf) {
+      return zlib.gzip(uncompressedData, function (err, buf) {
         logger.log(
           {
             project_id,
@@ -99,8 +99,8 @@ module.exports = MongoAWS = {
         if (err != null) {
           return callback(err)
         }
-        upload.on('error', err => callback(err))
-        upload.on('finish', function() {
+        upload.on('error', (err) => callback(err))
+        upload.on('finish', function () {
           Metrics.inc('archive-pack')
           logger.log({ project_id, doc_id, pack_id }, 'upload to s3 completed')
           return callback(null)
@@ -113,11 +113,11 @@ module.exports = MongoAWS = {
 
   readArchivedPack(project_id, doc_id, pack_id, _callback) {
     if (_callback == null) {
-      _callback = function(error, result) {}
+      _callback = function (error, result) {}
     }
-    const callback = function(...args) {
+    const callback = function (...args) {
       _callback(...Array.from(args || []))
-      return (_callback = function() {})
+      return (_callback = function () {})
     }
 
     if (project_id == null) {
@@ -135,12 +135,12 @@ module.exports = MongoAWS = {
     const download = createStream(S3S.ReadStream, project_id, doc_id, pack_id)
 
     const inputStream = download
-      .on('open', obj => 1)
-      .on('error', err => callback(err))
+      .on('open', (obj) => 1)
+      .on('error', (err) => callback(err))
 
     const gunzip = zlib.createGunzip()
     gunzip.setEncoding('utf8')
-    gunzip.on('error', function(err) {
+    gunzip.on('error', function (err) {
       logger.log(
         { project_id, doc_id, pack_id, err },
         'error uncompressing gzip stream'
@@ -150,8 +150,8 @@ module.exports = MongoAWS = {
 
     const outputStream = inputStream.pipe(gunzip)
     const parts = []
-    outputStream.on('error', err => callback(err))
-    outputStream.on('end', function() {
+    outputStream.on('error', (err) => callback(err))
+    outputStream.on('end', function () {
       let object
       logger.log({ project_id, doc_id, pack_id }, 'download from s3 completed')
       try {
@@ -169,14 +169,14 @@ module.exports = MongoAWS = {
       }
       return callback(null, object)
     })
-    return outputStream.on('data', data => parts.push(data))
+    return outputStream.on('data', (data) => parts.push(data))
   },
 
   unArchivePack(project_id, doc_id, pack_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
-    return MongoAWS.readArchivedPack(project_id, doc_id, pack_id, function(
+    return MongoAWS.readArchivedPack(project_id, doc_id, pack_id, function (
       err,
       object
     ) {

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app/js/MongoAWS.js.map


+ 11 - 12
services/track-changes/app/js/MongoManager.js

@@ -22,13 +22,13 @@ const logger = require('logger-sharelatex')
 module.exports = MongoManager = {
   getLastCompressedUpdate(doc_id, callback) {
     if (callback == null) {
-      callback = function(error, update) {}
+      callback = function (error, update) {}
     }
     return db.docHistory
       .find({ doc_id: ObjectId(doc_id.toString()) }, { pack: { $slice: -1 } }) // only return the last entry in a pack
       .sort({ v: -1 })
       .limit(1)
-      .toArray(function(error, compressedUpdates) {
+      .toArray(function (error, compressedUpdates) {
         if (error != null) {
           return callback(error)
         }
@@ -44,9 +44,9 @@ module.exports = MongoManager = {
     // to start, we pass it back as callback(null,null,version), just
     // giving the version so we can check consistency.
     if (callback == null) {
-      callback = function(error, update, version) {}
+      callback = function (error, update, version) {}
     }
-    return MongoManager.getLastCompressedUpdate(doc_id, function(
+    return MongoManager.getLastCompressedUpdate(doc_id, function (
       error,
       update
     ) {
@@ -76,7 +76,7 @@ module.exports = MongoManager = {
           return callback(null, update, update.v)
         }
       } else {
-        return PackManager.getLastPackFromIndex(doc_id, function(error, pack) {
+        return PackManager.getLastPackFromIndex(doc_id, function (error, pack) {
           if (error != null) {
             return callback(error)
           }
@@ -94,7 +94,7 @@ module.exports = MongoManager = {
 
   backportProjectId(project_id, doc_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return db.docHistory.update(
       {
@@ -113,13 +113,13 @@ module.exports = MongoManager = {
 
   getProjectMetaData(project_id, callback) {
     if (callback == null) {
-      callback = function(error, metadata) {}
+      callback = function (error, metadata) {}
     }
     return db.projectHistoryMetaData.find(
       {
         project_id: ObjectId(project_id.toString())
       },
-      function(error, results) {
+      function (error, results) {
         if (error != null) {
           return callback(error)
         }
@@ -130,7 +130,7 @@ module.exports = MongoManager = {
 
   setProjectMetaData(project_id, metadata, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return db.projectHistoryMetaData.update(
       {
@@ -149,7 +149,7 @@ module.exports = MongoManager = {
   upgradeHistory(project_id, callback) {
     // preserve the project's existing history
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return db.docHistory.update(
       {
@@ -200,11 +200,10 @@ module.exports = MongoManager = {
     )
   }
 }
-
 ;[
   'getLastCompressedUpdate',
   'getProjectMetaData',
   'setProjectMetaData'
-].map(method =>
+].map((method) =>
   metrics.timeAsyncMethod(MongoManager, method, 'mongo.MongoManager', logger)
 )

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app/js/MongoManager.js.map


+ 108 - 100
services/track-changes/app/js/PackManager.js

@@ -74,7 +74,7 @@ module.exports = PackManager = {
     callback
   ) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     if (newUpdates.length === 0) {
       return callback()
@@ -115,7 +115,7 @@ module.exports = PackManager = {
       lastUpdate,
       updatesToFlush,
       temporary,
-      function(error) {
+      function (error) {
         if (error != null) {
           return callback(error)
         }
@@ -140,7 +140,7 @@ module.exports = PackManager = {
     callback
   ) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     if (newUpdates.length === 0) {
       return callback()
@@ -190,7 +190,7 @@ module.exports = PackManager = {
     callback
   ) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     const first = newUpdates[0]
     const last = newUpdates[newUpdates.length - 1]
@@ -218,7 +218,7 @@ module.exports = PackManager = {
       { project_id, doc_id, newUpdates },
       'inserting updates into new pack'
     )
-    return db.docHistory.save(newPack, function(err, result) {
+    return db.docHistory.save(newPack, function (err, result) {
       if (err != null) {
         return callback(err)
       }
@@ -240,7 +240,7 @@ module.exports = PackManager = {
     callback
   ) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     const first = newUpdates[0]
     const last = newUpdates[newUpdates.length - 1]
@@ -283,14 +283,14 @@ module.exports = PackManager = {
 
   getOpsByVersionRange(project_id, doc_id, fromVersion, toVersion, callback) {
     if (callback == null) {
-      callback = function(error, updates) {}
+      callback = function (error, updates) {}
     }
     return PackManager.loadPacksByVersionRange(
       project_id,
       doc_id,
       fromVersion,
       toVersion,
-      function(error) {
+      function (error) {
         const query = { doc_id: ObjectId(doc_id.toString()) }
         if (toVersion != null) {
           query.v = { $lte: toVersion }
@@ -299,34 +299,36 @@ module.exports = PackManager = {
           query.v_end = { $gte: fromVersion }
         }
         // console.log "query:", query
-        return db.docHistory.find(query).sort({ v: -1 }, function(err, result) {
-          if (err != null) {
-            return callback(err)
-          }
-          // console.log "getOpsByVersionRange:", err, result
-          const updates = []
-          const opInRange = function(op, from, to) {
-            if (fromVersion != null && op.v < fromVersion) {
-              return false
+        return db.docHistory
+          .find(query)
+          .sort({ v: -1 }, function (err, result) {
+            if (err != null) {
+              return callback(err)
             }
-            if (toVersion != null && op.v > toVersion) {
-              return false
+            // console.log "getOpsByVersionRange:", err, result
+            const updates = []
+            const opInRange = function (op, from, to) {
+              if (fromVersion != null && op.v < fromVersion) {
+                return false
+              }
+              if (toVersion != null && op.v > toVersion) {
+                return false
+              }
+              return true
             }
-            return true
-          }
-          for (const docHistory of Array.from(result)) {
-            // console.log 'adding', docHistory.pack
-            for (const op of Array.from(docHistory.pack.reverse())) {
-              if (opInRange(op, fromVersion, toVersion)) {
-                op.project_id = docHistory.project_id
-                op.doc_id = docHistory.doc_id
-                // console.log "added op", op.v, fromVersion, toVersion
-                updates.push(op)
+            for (const docHistory of Array.from(result)) {
+              // console.log 'adding', docHistory.pack
+              for (const op of Array.from(docHistory.pack.reverse())) {
+                if (opInRange(op, fromVersion, toVersion)) {
+                  op.project_id = docHistory.project_id
+                  op.doc_id = docHistory.doc_id
+                  // console.log "added op", op.v, fromVersion, toVersion
+                  updates.push(op)
+                }
               }
             }
-          }
-          return callback(null, updates)
-        })
+            return callback(null, updates)
+          })
       }
     )
   },
@@ -338,14 +340,14 @@ module.exports = PackManager = {
     toVersion,
     callback
   ) {
-    return PackManager.getIndex(doc_id, function(err, indexResult) {
+    return PackManager.getIndex(doc_id, function (err, indexResult) {
       let pack
       if (err != null) {
         return callback(err)
       }
       const indexPacks =
         (indexResult != null ? indexResult.packs : undefined) || []
-      const packInRange = function(pack, from, to) {
+      const packInRange = function (pack, from, to) {
         if (fromVersion != null && pack.v_end < fromVersion) {
           return false
         }
@@ -391,7 +393,7 @@ module.exports = PackManager = {
         }
       },
       { _id: 1 },
-      function(err, loadedPacks) {
+      function (err, loadedPacks) {
         if (err != null) {
           return callback(err)
         }
@@ -402,7 +404,7 @@ module.exports = PackManager = {
           }
           return result1
         })()
-        const loadedPackIds = Array.from(loadedPacks).map(pack =>
+        const loadedPackIds = Array.from(loadedPacks).map((pack) =>
           pack._id.toString()
         )
         const packIdsToFetch = _.difference(allPackIds, loadedPackIds)
@@ -418,7 +420,7 @@ module.exports = PackManager = {
           4,
           (pack_id, cb) =>
             MongoAWS.unArchivePack(project_id, doc_id, pack_id, cb),
-          function(err) {
+          function (err) {
             if (err != null) {
               return callback(err)
             }
@@ -436,7 +438,7 @@ module.exports = PackManager = {
     // get all the docHistory Entries
     return db.docHistory
       .find({ project_id: ObjectId(project_id) }, { pack: false })
-      .sort({ 'meta.end_ts': -1 }, function(err, packs) {
+      .sort({ 'meta.end_ts': -1 }, function (err, packs) {
         let pack
         if (err != null) {
           return callback(err)
@@ -449,7 +451,7 @@ module.exports = PackManager = {
         }
         return db.docHistoryIndex.find(
           { project_id: ObjectId(project_id) },
-          function(err, indexes) {
+          function (err, indexes) {
             if (err != null) {
               return callback(err)
             }
@@ -474,7 +476,7 @@ module.exports = PackManager = {
   },
 
   getPackById(project_id, doc_id, pack_id, callback) {
-    return db.docHistory.findOne({ _id: pack_id }, function(err, pack) {
+    return db.docHistory.findOne({ _id: pack_id }, function (err, pack) {
       if (err != null) {
         return callback(err)
       }
@@ -500,7 +502,7 @@ module.exports = PackManager = {
           query: { _id: pack._id },
           update: { $set: { expiresAt: new Date(Date.now() + 7 * DAYS) } }
         },
-        err => callback(err, pack)
+        (err) => callback(err, pack)
       )
     } else {
       return callback(null, pack)
@@ -528,7 +530,7 @@ module.exports = PackManager = {
     return db.docHistoryIndex.findOne(
       { _id: ObjectId(doc_id.toString()) },
       { packs: { $slice: -1 } },
-      function(err, indexPack) {
+      function (err, indexPack) {
         if (err != null) {
           return callback(err)
         }
@@ -541,7 +543,7 @@ module.exports = PackManager = {
   },
 
   getIndexWithKeys(doc_id, callback) {
-    return PackManager.getIndex(doc_id, function(err, index) {
+    return PackManager.getIndex(doc_id, function (err, index) {
       if (err != null) {
         return callback(err)
       }
@@ -558,7 +560,7 @@ module.exports = PackManager = {
   },
 
   initialiseIndex(project_id, doc_id, callback) {
-    return PackManager.findCompletedPacks(project_id, doc_id, function(
+    return PackManager.findCompletedPacks(project_id, doc_id, function (
       err,
       packs
     ) {
@@ -580,7 +582,7 @@ module.exports = PackManager = {
 
   updateIndex(project_id, doc_id, callback) {
     // find all packs prior to current pack
-    return PackManager.findUnindexedPacks(project_id, doc_id, function(
+    return PackManager.findUnindexedPacks(project_id, doc_id, function (
       err,
       newPacks
     ) {
@@ -594,7 +596,7 @@ module.exports = PackManager = {
         project_id,
         doc_id,
         newPacks,
-        function(err) {
+        function (err) {
           if (err != null) {
             return callback(err)
           }
@@ -615,7 +617,7 @@ module.exports = PackManager = {
     }
     return db.docHistory
       .find(query, { pack: false })
-      .sort({ v: 1 }, function(err, packs) {
+      .sort({ v: 1 }, function (err, packs) {
         if (err != null) {
           return callback(err)
         }
@@ -640,7 +642,7 @@ module.exports = PackManager = {
     }
     return db.docHistory
       .find(query, { pack: false })
-      .sort({ v: 1 }, function(err, packs) {
+      .sort({ v: 1 }, function (err, packs) {
         if (err != null) {
           return callback(err)
         }
@@ -655,11 +657,11 @@ module.exports = PackManager = {
   },
 
   findUnindexedPacks(project_id, doc_id, callback) {
-    return PackManager.getIndexWithKeys(doc_id, function(err, indexResult) {
+    return PackManager.getIndexWithKeys(doc_id, function (err, indexResult) {
       if (err != null) {
         return callback(err)
       }
-      return PackManager.findCompletedPacks(project_id, doc_id, function(
+      return PackManager.findCompletedPacks(project_id, doc_id, function (
         err,
         historyPacks
       ) {
@@ -713,7 +715,7 @@ module.exports = PackManager = {
   insertPacksIntoIndexWithLock(project_id, doc_id, newPacks, callback) {
     return LockManager.runWithLock(
       keys.historyIndexLock({ doc_id }),
-      releaseLock =>
+      (releaseLock) =>
         PackManager._insertPacksIntoIndex(
           project_id,
           doc_id,
@@ -743,14 +745,14 @@ module.exports = PackManager = {
   // Archiving packs to S3
 
   archivePack(project_id, doc_id, pack_id, callback) {
-    const clearFlagOnError = function(err, cb) {
+    const clearFlagOnError = function (err, cb) {
       if (err != null) {
         // clear the inS3 flag on error
         return PackManager.clearPackAsArchiveInProgress(
           project_id,
           doc_id,
           pack_id,
-          function(err2) {
+          function (err2) {
             if (err2 != null) {
               return cb(err2)
             }
@@ -763,30 +765,30 @@ module.exports = PackManager = {
     }
     return async.series(
       [
-        cb =>
+        (cb) =>
           PackManager.checkArchiveNotInProgress(
             project_id,
             doc_id,
             pack_id,
             cb
           ),
-        cb =>
+        (cb) =>
           PackManager.markPackAsArchiveInProgress(
             project_id,
             doc_id,
             pack_id,
             cb
           ),
-        cb =>
-          MongoAWS.archivePack(project_id, doc_id, pack_id, err =>
+        (cb) =>
+          MongoAWS.archivePack(project_id, doc_id, pack_id, (err) =>
             clearFlagOnError(err, cb)
           ),
-        cb =>
-          PackManager.checkArchivedPack(project_id, doc_id, pack_id, err =>
+        (cb) =>
+          PackManager.checkArchivedPack(project_id, doc_id, pack_id, (err) =>
             clearFlagOnError(err, cb)
           ),
-        cb => PackManager.markPackAsArchived(project_id, doc_id, pack_id, cb),
-        cb =>
+        (cb) => PackManager.markPackAsArchived(project_id, doc_id, pack_id, cb),
+        (cb) =>
           PackManager.setTTLOnArchivedPack(
             project_id,
             doc_id,
@@ -799,14 +801,14 @@ module.exports = PackManager = {
   },
 
   checkArchivedPack(project_id, doc_id, pack_id, callback) {
-    return db.docHistory.findOne({ _id: pack_id }, function(err, pack) {
+    return db.docHistory.findOne({ _id: pack_id }, function (err, pack) {
       if (err != null) {
         return callback(err)
       }
       if (pack == null) {
         return callback(new Error('pack not found'))
       }
-      return MongoAWS.readArchivedPack(project_id, doc_id, pack_id, function(
+      return MongoAWS.readArchivedPack(project_id, doc_id, pack_id, function (
         err,
         result
       ) {
@@ -845,7 +847,7 @@ module.exports = PackManager = {
   // Extra methods to test archive/unarchive for a doc_id
 
   pushOldPacks(project_id, doc_id, callback) {
-    return PackManager.findPacks(project_id, doc_id, function(err, packs) {
+    return PackManager.findPacks(project_id, doc_id, function (err, packs) {
       if (err != null) {
         return callback(err)
       }
@@ -874,8 +876,8 @@ module.exports = PackManager = {
   // Processing old packs via worker
 
   processOldPack(project_id, doc_id, pack_id, callback) {
-    const markAsChecked = err =>
-      PackManager.markPackAsChecked(project_id, doc_id, pack_id, function(
+    const markAsChecked = (err) =>
+      PackManager.markPackAsChecked(project_id, doc_id, pack_id, function (
         err2
       ) {
         if (err2 != null) {
@@ -884,7 +886,7 @@ module.exports = PackManager = {
         return callback(err)
       })
     logger.log({ project_id, doc_id }, 'processing old packs')
-    return db.docHistory.findOne({ _id: pack_id }, function(err, pack) {
+    return db.docHistory.findOne({ _id: pack_id }, function (err, pack) {
       if (err != null) {
         return markAsChecked(err)
       }
@@ -899,42 +901,45 @@ module.exports = PackManager = {
         doc_id,
         pack._id,
         pack,
-        function(err) {
+        function (err) {
           if (err != null) {
             return markAsChecked(err)
           }
-          return PackManager.updateIndexIfNeeded(project_id, doc_id, function(
+          return PackManager.updateIndexIfNeeded(project_id, doc_id, function (
             err
           ) {
             if (err != null) {
               return markAsChecked(err)
             }
-            return PackManager.findUnarchivedPacks(project_id, doc_id, function(
-              err,
-              unarchivedPacks
-            ) {
-              if (err != null) {
-                return markAsChecked(err)
-              }
-              if (
-                !(unarchivedPacks != null ? unarchivedPacks.length : undefined)
-              ) {
-                logger.log({ project_id, doc_id }, 'no packs need archiving')
-                return markAsChecked()
-              }
-              return async.eachSeries(
-                unarchivedPacks,
-                (pack, cb) =>
-                  PackManager.archivePack(project_id, doc_id, pack._id, cb),
-                function(err) {
-                  if (err != null) {
-                    return markAsChecked(err)
-                  }
-                  logger.log({ project_id, doc_id }, 'done processing')
+            return PackManager.findUnarchivedPacks(
+              project_id,
+              doc_id,
+              function (err, unarchivedPacks) {
+                if (err != null) {
+                  return markAsChecked(err)
+                }
+                if (
+                  !(unarchivedPacks != null
+                    ? unarchivedPacks.length
+                    : undefined)
+                ) {
+                  logger.log({ project_id, doc_id }, 'no packs need archiving')
                   return markAsChecked()
                 }
-              )
-            })
+                return async.eachSeries(
+                  unarchivedPacks,
+                  (pack, cb) =>
+                    PackManager.archivePack(project_id, doc_id, pack._id, cb),
+                  function (err) {
+                    if (err != null) {
+                      return markAsChecked(err)
+                    }
+                    logger.log({ project_id, doc_id }, 'done processing')
+                    return markAsChecked()
+                  }
+                )
+              }
+            )
           })
         }
       )
@@ -975,7 +980,7 @@ module.exports = PackManager = {
   markPackAsFinalisedWithLock(project_id, doc_id, pack_id, callback) {
     return LockManager.runWithLock(
       keys.historyLock({ doc_id }),
-      releaseLock =>
+      (releaseLock) =>
         PackManager._markPackAsFinalised(
           project_id,
           doc_id,
@@ -999,7 +1004,7 @@ module.exports = PackManager = {
 
   updateIndexIfNeeded(project_id, doc_id, callback) {
     logger.log({ project_id, doc_id }, 'archiving old packs')
-    return PackManager.getIndexWithKeys(doc_id, function(err, index) {
+    return PackManager.getIndexWithKeys(doc_id, function (err, index) {
       if (err != null) {
         return callback(err)
       }
@@ -1023,7 +1028,7 @@ module.exports = PackManager = {
   },
 
   findUnarchivedPacks(project_id, doc_id, callback) {
-    return PackManager.getIndex(doc_id, function(err, indexResult) {
+    return PackManager.getIndex(doc_id, function (err, indexResult) {
       if (err != null) {
         return callback(err)
       }
@@ -1055,7 +1060,10 @@ module.exports = PackManager = {
       { project_id, doc_id, pack_id },
       'checking if archive in progress'
     )
-    return PackManager.getPackFromIndex(doc_id, pack_id, function(err, result) {
+    return PackManager.getPackFromIndex(doc_id, pack_id, function (
+      err,
+      result
+    ) {
       if (err != null) {
         return callback(err)
       }
@@ -1086,7 +1094,7 @@ module.exports = PackManager = {
         fields: { 'packs.$': 1 },
         update: { $set: { 'packs.$.inS3': false } }
       },
-      function(err, result) {
+      function (err, result) {
         if (err != null) {
           return callback(err)
         }
@@ -1131,7 +1139,7 @@ module.exports = PackManager = {
         fields: { 'packs.$': 1 },
         update: { $set: { 'packs.$.inS3': true } }
       },
-      function(err, result) {
+      function (err, result) {
         if (err != null) {
           return callback(err)
         }
@@ -1150,7 +1158,7 @@ module.exports = PackManager = {
         query: { _id: pack_id },
         update: { $set: { expiresAt: new Date(Date.now() + 1 * DAYS) } }
       },
-      function(err) {
+      function (err) {
         logger.log({ project_id, doc_id, pack_id }, 'set expiry on pack')
         return callback()
       }

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app/js/PackManager.js.map


+ 18 - 18
services/track-changes/app/js/PackWorker.js

@@ -52,8 +52,8 @@ if (!source.match(/^[0-9]+$/)) {
     }
     return result1
   })()
-  pending = _.filter(result, row =>
-    __guard__(row != null ? row.doc_id : undefined, x =>
+  pending = _.filter(result, (row) =>
+    __guard__(row != null ? row.doc_id : undefined, (x) =>
       x.match(/^[a-f0-9]{24}$/)
     )
   )
@@ -62,12 +62,12 @@ if (!source.match(/^[0-9]+$/)) {
 }
 
 let shutDownRequested = false
-const shutDownTimer = setTimeout(function() {
+const shutDownTimer = setTimeout(function () {
   logger.log('pack timed out, requesting shutdown')
   // start the shutdown on the next pack
   shutDownRequested = true
   // do a hard shutdown after a further 5 minutes
-  const hardTimeout = setTimeout(function() {
+  const hardTimeout = setTimeout(function () {
     logger.error('HARD TIMEOUT in pack archive worker')
     return process.exit()
   }, 5 * 60 * 1000)
@@ -79,8 +79,8 @@ logger.log(
 )
 
 // work around for https://github.com/mafintosh/mongojs/issues/224
-db.close = function(callback) {
-  return this._getServer(function(err, server) {
+db.close = function (callback) {
+  return this._getServer(function (err, server) {
     if (err != null) {
       return callback(err)
     }
@@ -90,20 +90,20 @@ db.close = function(callback) {
   })
 }
 
-const finish = function() {
+const finish = function () {
   if (shutDownTimer != null) {
     logger.log('cancelling timeout')
     clearTimeout(shutDownTimer)
   }
   logger.log('closing db')
-  return db.close(function() {
+  return db.close(function () {
     logger.log('closing LockManager Redis Connection')
-    return LockManager.close(function() {
+    return LockManager.close(function () {
       logger.log(
         { processedCount: COUNT, allCount: TOTAL },
         'ready to exit from pack archive worker'
       )
-      const hardTimeout = setTimeout(function() {
+      const hardTimeout = setTimeout(function () {
         logger.error('hard exit from pack archive worker')
         return process.exit(1)
       }, 5 * 1000)
@@ -112,12 +112,12 @@ const finish = function() {
   })
 }
 
-process.on('exit', code => logger.log({ code }, 'pack archive worker exited'))
+process.on('exit', (code) => logger.log({ code }, 'pack archive worker exited'))
 
-const processUpdates = pending =>
+const processUpdates = (pending) =>
   async.eachSeries(
     pending,
-    function(result, callback) {
+    function (result, callback) {
       let _id
       ;({ _id, project_id, doc_id } = result)
       COUNT++
@@ -129,7 +129,7 @@ const processUpdates = pending =>
         )
         return callback()
       }
-      const handler = function(err, result) {
+      const handler = function (err, result) {
         if (err != null && err.code === 'InternalError' && err.retryable) {
           logger.warn(
             { err, result },
@@ -154,7 +154,7 @@ const processUpdates = pending =>
         return PackManager.processOldPack(project_id, doc_id, _id, handler)
       }
     },
-    function(err, results) {
+    function (err, results) {
       if (err != null && err.message !== 'shutdown') {
         logger.error({ err }, 'error in pack archive worker processUpdates')
       }
@@ -163,7 +163,7 @@ const processUpdates = pending =>
   )
 // find the packs which can be archived
 
-const ObjectIdFromDate = function(date) {
+const ObjectIdFromDate = function (date) {
   const id = Math.floor(date.getTime() / 1000).toString(16) + '0000000000000000'
   return ObjectId(id)
 }
@@ -191,13 +191,13 @@ if (pending != null) {
     .sort({
       last_checked: 1
     })
-    .limit(LIMIT, function(err, results) {
+    .limit(LIMIT, function (err, results) {
       if (err != null) {
         logger.log({ err }, 'error checking for updates')
         finish()
         return
       }
-      pending = _.uniq(results, false, result => result.doc_id.toString())
+      pending = _.uniq(results, false, (result) => result.doc_id.toString())
       TOTAL = pending.length
       logger.log(`found ${TOTAL} documents to archive`)
       return processUpdates(pending)

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app/js/PackWorker.js.map


+ 1 - 1
services/track-changes/app/js/ProjectIterator.js

@@ -62,7 +62,7 @@ module.exports = ProjectIterator = ProjectIterator = class ProjectIterator {
         nextPack.project_id,
         nextPack.doc_id,
         nextPack._id,
-        function(err, pack) {
+        function (err, pack) {
           if (err != null) {
             return callback(err)
           }

+ 10 - 0
services/track-changes/app/js/ProjectIterator.js.map

@@ -0,0 +1,10 @@
+{
+  "version": 3,
+  "file": "ProjectIterator.js",
+  "sourceRoot": "../..",
+  "sources": [
+    "app/coffee/ProjectIterator.coffee"
+  ],
+  "names": [],
+  "mappings": ";AAAA;AAAA,MAAA;;EAAA,IAAA,GAAO,OAAA,CAAQ,MAAR;;EAEP,MAAM,CAAC,OAAP,GAAiB,eAAA,GAEV;IACQ,yBAAC,KAAD,EAAQ,OAAR,EAAiB,aAAjB;AACZ,UAAA;MADoB,IAAC,CAAA,SAAD;MAAS,IAAC,CAAA,gBAAD;MAC7B,OAAA,GAAU,SAAC,CAAD,EAAG,CAAH;eAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAP,GAAgB,CAAC,CAAC,IAAI,CAAC,MAAxB,CAAA,IAAmC,CAAC,CAAC,CAAC,SAAF,GAAc,CAAC,CAAC,SAAjB;MAA5C;MACV,IAAC,CAAA,KAAD,GAAS,KAAK,CAAC,KAAN,CAAA,CAAa,CAAC,IAAd,CAAmB,OAAnB;MACT,IAAC,CAAA,KAAD,GAAS,IAAI,IAAJ,CAAS,OAAT;IAHG;;8BAKb,IAAA,GAAM,SAAC,QAAD;AAGL,UAAA;MAAA,QAAA,GAAW;MACX,MAAA,GAAS,IAAC,CAAA;MACV,KAAA,GAAQ,QAAQ,CAAC;MACjB,WAAA,GAAc;MACd,QAAA,GAAW,QAAQ,CAAC,KAAM,CAAA,CAAA;MAC1B,YAAA,uBAAe,QAAQ,CAAE,IAAI,CAAC,gBAAf,IAAyB;MACxC,QAAA,GAAW,KAAK,CAAC,IAAN,CAAA;AAOX,aAAM,gBAAA,wBAAY,QAAQ,CAAE,IAAI,CAAC,kBAAf,GAA0B,MAA5C;QAEC,QAAQ,CAAC,KAAK,CAAC,KAAf,CAAA;QACA,QAAA,GAAW,QAAQ,CAAC,KAAM,CAAA,CAAA;QAC1B,YAAA,uBAAe,QAAQ,CAAE,IAAI,CAAC,gBAAf,IAAyB;MAJzC;MAMA,IAAG,CAAC,KAAK,CAAC,KAAN,CAAA,CAAA,wBAAiB,QAAQ,CAAE,IAAI,CAAC,gBAAf,IAAyB,YAA3C,CAAA,IAA6D,kBAAhE;AAEC,eAAO,IAAC,CAAA,aAAD,CAAe,QAAQ,CAAC,UAAxB,EAAoC,QAAQ,CAAC,MAA7C,EAAqD,QAAQ,CAAC,GAA9D,EAAmE,SAAC,GAAD,EAAM,IAAN;AACzE,cAAA;UAAA,IAAwB,WAAxB;AAAA,mBAAO,QAAA,CAAS,GAAT,EAAP;;UACA,QAAQ,CAAC,KAAK,CAAC,KAAf,CAAA;AAEA;AAAA,eAAA,qCAAA;;kBAA8B,gBAAJ,IAAe,EAAE,CAAC,IAAI,CAAC,MAAR,GAAiB;;;YAEzD,EAAE,CAAC,MAAH,GAAY,QAAQ,CAAC;YACrB,EAAE,CAAC,UAAH,GAAgB,QAAQ,CAAC;YACzB,KAAK,CAAC,IAAN,CAAW,EAAX;AAJD;AAMA,iBAAO,QAAQ,CAAC,IAAT,CAAc,QAAd;QAVkE,CAAnE,EAFR;;AAeA,aAAM,kBAAA,IAAc,qBAAC,QAAQ,CAAE,IAAI,CAAC,gBAAf,GAAwB,YAAzB,CAApB;QACC,WAAW,CAAC,IAAZ,CAAiB,QAAjB;QACA,KAAK,CAAC,GAAN,CAAA;QACA,QAAA,GAAW,KAAK,CAAC,IAAN,CAAA;MAHZ;MAQA,IAAG,KAAK,CAAC,KAAN,CAAA,CAAA,IAAsB,kBAAzB;QACC,QAAQ,CAAC,KAAT,GAAiB,KADlB;;aAGA,QAAA,CAAS,IAAT,EAAe,WAAf;IAhDK;;8BAkDN,IAAA,GAAM,SAAA;AACL,aAAO,IAAC,CAAA;IADH;;;;;AA5DR"
+}

+ 13 - 13
services/track-changes/app/js/RedisManager.js

@@ -22,7 +22,7 @@ const async = require('async')
 module.exports = RedisManager = {
   getOldestDocUpdates(doc_id, batchSize, callback) {
     if (callback == null) {
-      callback = function(error, jsonUpdates) {}
+      callback = function (error, jsonUpdates) {}
     }
     const key = Keys.uncompressedHistoryOps({ doc_id })
     return rclient.lrange(key, 0, batchSize - 1, callback)
@@ -31,10 +31,10 @@ module.exports = RedisManager = {
   expandDocUpdates(jsonUpdates, callback) {
     let rawUpdates
     if (callback == null) {
-      callback = function(error, rawUpdates) {}
+      callback = function (error, rawUpdates) {}
     }
     try {
-      rawUpdates = Array.from(jsonUpdates || []).map(update =>
+      rawUpdates = Array.from(jsonUpdates || []).map((update) =>
         JSON.parse(update)
       )
     } catch (e) {
@@ -45,14 +45,14 @@ module.exports = RedisManager = {
 
   deleteAppliedDocUpdates(project_id, doc_id, docUpdates, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     const multi = rclient.multi()
     // Delete all the updates which have been applied (exact match)
     for (const update of Array.from(docUpdates || [])) {
       multi.lrem(Keys.uncompressedHistoryOps({ doc_id }), 1, update)
     }
-    return multi.exec(function(error, results) {
+    return multi.exec(function (error, results) {
       if (error != null) {
         return callback(error)
       }
@@ -61,7 +61,7 @@ module.exports = RedisManager = {
       return rclient.srem(
         Keys.docsWithHistoryOps({ project_id }),
         doc_id,
-        function(error) {
+        function (error) {
           if (error != null) {
             return callback(error)
           }
@@ -73,7 +73,7 @@ module.exports = RedisManager = {
 
   getDocIdsWithHistoryOps(project_id, callback) {
     if (callback == null) {
-      callback = function(error, doc_ids) {}
+      callback = function (error, doc_ids) {}
     }
     return rclient.smembers(Keys.docsWithHistoryOps({ project_id }), callback)
   },
@@ -93,8 +93,8 @@ module.exports = RedisManager = {
     let cursor = 0 // redis iterator
     const keySet = {} // use hash to avoid duplicate results
     // scan over all keys looking for pattern
-    var doIteration = cb =>
-      node.scan(cursor, 'MATCH', pattern, 'COUNT', 1000, function(
+    var doIteration = (cb) =>
+      node.scan(cursor, 'MATCH', pattern, 'COUNT', 1000, function (
         error,
         reply
       ) {
@@ -132,11 +132,11 @@ module.exports = RedisManager = {
 
   getProjectIdsWithHistoryOps(callback) {
     if (callback == null) {
-      callback = function(error, project_ids) {}
+      callback = function (error, project_ids) {}
     }
     return RedisManager._getKeys(
       Keys.docsWithHistoryOps({ project_id: '*' }),
-      function(error, project_keys) {
+      function (error, project_keys) {
         if (error != null) {
           return callback(error)
         }
@@ -150,11 +150,11 @@ module.exports = RedisManager = {
     // return all the docids, to find dangling history entries after
     // everything is flushed.
     if (callback == null) {
-      callback = function(error, doc_ids) {}
+      callback = function (error, doc_ids) {}
     }
     return RedisManager._getKeys(
       Keys.uncompressedHistoryOps({ doc_id: '*' }),
-      function(error, doc_keys) {
+      function (error, doc_keys) {
         if (error != null) {
           return callback(error)
         }

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app/js/RedisManager.js.map


+ 3 - 3
services/track-changes/app/js/RestoreManager.js

@@ -19,14 +19,14 @@ const logger = require('logger-sharelatex')
 module.exports = RestoreManager = {
   restoreToBeforeVersion(project_id, doc_id, version, user_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     logger.log({ project_id, doc_id, version, user_id }, 'restoring document')
     return DiffManager.getDocumentBeforeVersion(
       project_id,
       doc_id,
       version,
-      function(error, content) {
+      function (error, content) {
         if (error != null) {
           return callback(error)
         }
@@ -35,7 +35,7 @@ module.exports = RestoreManager = {
           doc_id,
           content,
           user_id,
-          function(error) {
+          function (error) {
             if (error != null) {
               return callback(error)
             }

+ 10 - 0
services/track-changes/app/js/RestoreManager.js.map

@@ -0,0 +1,10 @@
+{
+  "version": 3,
+  "file": "RestoreManager.js",
+  "sourceRoot": "../..",
+  "sources": [
+    "app/coffee/RestoreManager.coffee"
+  ],
+  "names": [],
+  "mappings": ";AAAA;AAAA,MAAA;;EAAA,sBAAA,GAAyB,OAAA,CAAQ,0BAAR;;EACzB,WAAA,GAAc,OAAA,CAAQ,eAAR;;EACd,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EAET,MAAM,CAAC,OAAP,GAAiB,cAAA,GAChB;IAAA,sBAAA,EAAwB,SAAC,UAAD,EAAa,MAAb,EAAqB,OAArB,EAA8B,OAA9B,EAAuC,QAAvC;;QAAuC,WAAW,SAAC,KAAD,GAAA;;MACzE,MAAM,CAAC,GAAP,CAAW;QAAA,UAAA,EAAY,UAAZ;QAAwB,MAAA,EAAQ,MAAhC;QAAwC,OAAA,EAAS,OAAjD;QAA0D,OAAA,EAAS,OAAnE;OAAX,EAAuF,oBAAvF;aACA,WAAW,CAAC,wBAAZ,CAAqC,UAArC,EAAiD,MAAjD,EAAyD,OAAzD,EAAkE,SAAC,KAAD,EAAQ,OAAR;QACjE,IAA0B,aAA1B;AAAA,iBAAO,QAAA,CAAS,KAAT,EAAP;;eACA,sBAAsB,CAAC,WAAvB,CAAmC,UAAnC,EAA+C,MAA/C,EAAuD,OAAvD,EAAgE,OAAhE,EAAyE,SAAC,KAAD;UACxE,IAA0B,aAA1B;AAAA,mBAAO,QAAA,CAAS,KAAT,EAAP;;iBACA,QAAA,CAAA;QAFwE,CAAzE;MAFiE,CAAlE;IAFuB,CAAxB;;AALD"
+}

+ 10 - 7
services/track-changes/app/js/UpdateCompressor.js

@@ -42,7 +42,7 @@ module.exports = UpdateCompressor = {
     const splitUpdates = []
     for (const update of Array.from(updates)) {
       // Reject any non-insert or delete ops, i.e. comments
-      const ops = update.op.filter(o => o.i != null || o.d != null)
+      const ops = update.op.filter((o) => o.i != null || o.d != null)
       if (ops.length === 0) {
         splitUpdates.push({
           op: UpdateCompressor.NOOP,
@@ -97,7 +97,7 @@ module.exports = UpdateCompressor = {
     if (
       __guard__(
         lastPreviousUpdate != null ? lastPreviousUpdate.op : undefined,
-        x => x.length
+        (x) => x.length
       ) > 1
     ) {
       // if the last previous update was an array op, don't compress onto it.
@@ -183,7 +183,8 @@ module.exports = UpdateCompressor = {
     if (
       firstOp.i != null &&
       secondOp.i != null &&
-      firstOp.p <= secondOp.p && secondOp.p <= firstOp.p + firstOp.i.length &&
+      firstOp.p <= secondOp.p &&
+      secondOp.p <= firstOp.p + firstOp.i.length &&
       firstSize + secondSize < UpdateCompressor.MAX_UPDATE_SIZE
     ) {
       return [
@@ -204,7 +205,8 @@ module.exports = UpdateCompressor = {
     } else if (
       firstOp.d != null &&
       secondOp.d != null &&
-      secondOp.p <= firstOp.p && firstOp.p <= secondOp.p + secondOp.d.length &&
+      secondOp.p <= firstOp.p &&
+      firstOp.p <= secondOp.p + secondOp.d.length &&
       firstSize + secondSize < UpdateCompressor.MAX_UPDATE_SIZE
     ) {
       return [
@@ -225,7 +227,8 @@ module.exports = UpdateCompressor = {
     } else if (
       firstOp.i != null &&
       secondOp.d != null &&
-      firstOp.p <= secondOp.p && secondOp.p <= firstOp.p + firstOp.i.length
+      firstOp.p <= secondOp.p &&
+      secondOp.p <= firstOp.p + firstOp.i.length
     ) {
       offset = secondOp.p - firstOp.p
       const insertedText = firstOp.i.slice(offset, offset + secondOp.d.length)
@@ -276,7 +279,7 @@ module.exports = UpdateCompressor = {
           }
         ]
       } else {
-        return diff_ops.map(function(op) {
+        return diff_ops.map(function (op) {
           op.p += offset
           return {
             meta: {
@@ -299,7 +302,7 @@ module.exports = UpdateCompressor = {
   UNCHANGED: 0,
   diffAsShareJsOps(before, after, callback) {
     if (callback == null) {
-      callback = function(error, ops) {}
+      callback = function (error, ops) {}
     }
     const diffs = dmp.diff_main(before, after)
     dmp.diff_cleanupSemantic(diffs)

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app/js/UpdateCompressor.js.map


+ 8 - 6
services/track-changes/app/js/UpdateTrimmer.js

@@ -20,9 +20,9 @@ const logger = require('logger-sharelatex')
 module.exports = UpdateTrimmer = {
   shouldTrimUpdates(project_id, callback) {
     if (callback == null) {
-      callback = function(error, shouldTrim) {}
+      callback = function (error, shouldTrim) {}
     }
-    return MongoManager.getProjectMetaData(project_id, function(
+    return MongoManager.getProjectMetaData(project_id, function (
       error,
       metadata
     ) {
@@ -32,7 +32,7 @@ module.exports = UpdateTrimmer = {
       if (metadata != null ? metadata.preserveHistory : undefined) {
         return callback(null, false)
       } else {
-        return WebApiManager.getProjectDetails(project_id, function(
+        return WebApiManager.getProjectDetails(project_id, function (
           error,
           details
         ) {
@@ -43,17 +43,19 @@ module.exports = UpdateTrimmer = {
           if (
             __guard__(
               details != null ? details.features : undefined,
-              x => x.versioning
+              (x) => x.versioning
             )
           ) {
             return MongoManager.setProjectMetaData(
               project_id,
               { preserveHistory: true },
-              function(error) {
+              function (error) {
                 if (error != null) {
                   return callback(error)
                 }
-                return MongoManager.upgradeHistory(project_id, function(error) {
+                return MongoManager.upgradeHistory(project_id, function (
+                  error
+                ) {
                   if (error != null) {
                     return callback(error)
                   }

+ 10 - 0
services/track-changes/app/js/UpdateTrimmer.js.map

@@ -0,0 +1,10 @@
+{
+  "version": 3,
+  "file": "UpdateTrimmer.js",
+  "sourceRoot": "../..",
+  "sources": [
+    "app/coffee/UpdateTrimmer.coffee"
+  ],
+  "names": [],
+  "mappings": ";AAAA;AAAA,MAAA;;EAAA,YAAA,GAAe,OAAA,CAAQ,gBAAR;;EACf,aAAA,GAAgB,OAAA,CAAQ,iBAAR;;EAChB,MAAA,GAAS,OAAA,CAAQ,mBAAR;;EAET,MAAM,CAAC,OAAP,GAAiB,aAAA,GAChB;IAAA,iBAAA,EAAmB,SAAC,UAAD,EAAa,QAAb;;QAAa,WAAW,SAAC,KAAD,EAAQ,UAAR,GAAA;;aAC1C,YAAY,CAAC,kBAAb,CAAgC,UAAhC,EAA4C,SAAC,KAAD,EAAQ,QAAR;QAC3C,IAA0B,aAA1B;AAAA,iBAAO,QAAA,CAAS,KAAT,EAAP;;QACA,uBAAG,QAAQ,CAAE,wBAAb;AACC,iBAAO,QAAA,CAAS,IAAT,EAAe,KAAf,EADR;SAAA,MAAA;iBAGC,aAAa,CAAC,iBAAd,CAAgC,UAAhC,EAA4C,SAAC,KAAD,EAAQ,OAAR;AAC3C,gBAAA;YAAA,IAA0B,aAA1B;AAAA,qBAAO,QAAA,CAAS,KAAT,EAAP;;YACA,MAAM,CAAC,GAAP,CAAW;cAAA,UAAA,EAAY,UAAZ;cAAwB,OAAA,EAAS,OAAjC;aAAX,EAAqD,aAArD;YACA,4DAAoB,CAAE,4BAAtB;qBACC,YAAY,CAAC,kBAAb,CAAgC,UAAhC,EAA4C;gBAAA,eAAA,EAAiB,IAAjB;eAA5C,EAAmE,SAAC,KAAD;gBAClE,IAA0B,aAA1B;AAAA,yBAAO,QAAA,CAAS,KAAT,EAAP;;uBACA,YAAY,CAAC,cAAb,CAA4B,UAA5B,EAAwC,SAAC,KAAD;kBACvC,IAA0B,aAA1B;AAAA,2BAAO,QAAA,CAAS,KAAT,EAAP;;yBACA,QAAA,CAAS,IAAT,EAAe,KAAf;gBAFuC,CAAxC;cAFkE,CAAnE,EADD;aAAA,MAAA;qBAOC,QAAA,CAAS,IAAT,EAAe,IAAf,EAPD;;UAH2C,CAA5C,EAHD;;MAF2C,CAA5C;IADkB,CAAnB;;AALD"
+}

+ 67 - 67
services/track-changes/app/js/UpdatesManager.js

@@ -38,7 +38,7 @@ module.exports = UpdatesManager = {
   ) {
     let i
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     const { length } = rawUpdates
     if (length === 0) {
@@ -50,7 +50,7 @@ module.exports = UpdatesManager = {
       const op = rawUpdates[i]
       if (i > 0) {
         const thisVersion = op != null ? op.v : undefined
-        const prevVersion = __guard__(rawUpdates[i - 1], x => x.v)
+        const prevVersion = __guard__(rawUpdates[i - 1], (x) => x.v)
         if (!(prevVersion < thisVersion)) {
           logger.error(
             {
@@ -69,7 +69,7 @@ module.exports = UpdatesManager = {
 
     // FIXME: we no longer need the lastCompressedUpdate, so change functions not to need it
     // CORRECTION:  we do use it to log the time in case of error
-    return MongoManager.peekLastCompressedUpdate(doc_id, function(
+    return MongoManager.peekLastCompressedUpdate(doc_id, function (
       error,
       lastCompressedUpdate,
       lastVersion
@@ -105,7 +105,7 @@ module.exports = UpdatesManager = {
             lastCompressedUpdate != null
               ? lastCompressedUpdate.meta
               : undefined,
-            x1 => x1.end_ts
+            (x1) => x1.end_ts
           )
           const last_timestamp = ts != null ? new Date(ts) : 'unknown time'
           error = new Error(
@@ -179,7 +179,7 @@ module.exports = UpdatesManager = {
         lastCompressedUpdate,
         compressedUpdates,
         temporary,
-        function(error, result) {
+        function (error, result) {
           if (error != null) {
             return callback(error)
           }
@@ -206,9 +206,9 @@ module.exports = UpdatesManager = {
   // Check whether the updates are temporary (per-project property)
   _prepareProjectForUpdates(project_id, callback) {
     if (callback == null) {
-      callback = function(error, temporary) {}
+      callback = function (error, temporary) {}
     }
-    return UpdateTrimmer.shouldTrimUpdates(project_id, function(
+    return UpdateTrimmer.shouldTrimUpdates(project_id, function (
       error,
       temporary
     ) {
@@ -222,9 +222,9 @@ module.exports = UpdatesManager = {
   // Check for project id on document history (per-document property)
   _prepareDocForUpdates(project_id, doc_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
-    return MongoManager.backportProjectId(project_id, doc_id, function(error) {
+    return MongoManager.backportProjectId(project_id, doc_id, function (error) {
       if (error != null) {
         return callback(error)
       }
@@ -237,18 +237,18 @@ module.exports = UpdatesManager = {
   processUncompressedUpdates(project_id, doc_id, temporary, callback) {
     // get the updates as strings from redis (so we can delete them after they are applied)
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return RedisManager.getOldestDocUpdates(
       doc_id,
       UpdatesManager.REDIS_READ_BATCH_SIZE,
-      function(error, docUpdates) {
+      function (error, docUpdates) {
         if (error != null) {
           return callback(error)
         }
         const { length } = docUpdates
         // parse the redis strings into ShareJs updates
-        return RedisManager.expandDocUpdates(docUpdates, function(
+        return RedisManager.expandDocUpdates(docUpdates, function (
           error,
           rawUpdates
         ) {
@@ -268,7 +268,7 @@ module.exports = UpdatesManager = {
             doc_id,
             rawUpdates,
             temporary,
-            function(error) {
+            function (error) {
               if (error != null) {
                 return callback(error)
               }
@@ -281,7 +281,7 @@ module.exports = UpdatesManager = {
                 project_id,
                 doc_id,
                 docUpdates,
-                function(error) {
+                function (error) {
                   if (error != null) {
                     return callback(error)
                   }
@@ -320,9 +320,9 @@ module.exports = UpdatesManager = {
   // Process updates for a doc when we flush it individually
   processUncompressedUpdatesWithLock(project_id, doc_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
-    return UpdatesManager._prepareProjectForUpdates(project_id, function(
+    return UpdatesManager._prepareProjectForUpdates(project_id, function (
       error,
       temporary
     ) {
@@ -346,9 +346,9 @@ module.exports = UpdatesManager = {
     callback
   ) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
-    return UpdatesManager._prepareDocForUpdates(project_id, doc_id, function(
+    return UpdatesManager._prepareDocForUpdates(project_id, doc_id, function (
       error
     ) {
       if (error != null) {
@@ -356,7 +356,7 @@ module.exports = UpdatesManager = {
       }
       return LockManager.runWithLock(
         keys.historyLock({ doc_id }),
-        releaseLock =>
+        (releaseLock) =>
           UpdatesManager.processUncompressedUpdates(
             project_id,
             doc_id,
@@ -371,23 +371,23 @@ module.exports = UpdatesManager = {
   // Process all updates for a project, only check project-level information once
   processUncompressedUpdatesForProject(project_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
-    return RedisManager.getDocIdsWithHistoryOps(project_id, function(
+    return RedisManager.getDocIdsWithHistoryOps(project_id, function (
       error,
       doc_ids
     ) {
       if (error != null) {
         return callback(error)
       }
-      return UpdatesManager._prepareProjectForUpdates(project_id, function(
+      return UpdatesManager._prepareProjectForUpdates(project_id, function (
         error,
         temporary
       ) {
         const jobs = []
         for (const doc_id of Array.from(doc_ids)) {
-          ;(doc_id =>
-            jobs.push(cb =>
+          ;((doc_id) =>
+            jobs.push((cb) =>
               UpdatesManager._processUncompressedUpdatesForDocWithLock(
                 project_id,
                 doc_id,
@@ -404,9 +404,9 @@ module.exports = UpdatesManager = {
   // flush all outstanding changes
   flushAll(limit, callback) {
     if (callback == null) {
-      callback = function(error, result) {}
+      callback = function (error, result) {}
     }
-    return RedisManager.getProjectIdsWithHistoryOps(function(
+    return RedisManager.getProjectIdsWithHistoryOps(function (
       error,
       project_ids
     ) {
@@ -426,15 +426,15 @@ module.exports = UpdatesManager = {
       const selectedProjects =
         limit < 0 ? project_ids : project_ids.slice(0, limit)
       for (project_id of Array.from(selectedProjects)) {
-        ;(project_id =>
-          jobs.push(cb =>
+        ;((project_id) =>
+          jobs.push((cb) =>
             UpdatesManager.processUncompressedUpdatesForProject(
               project_id,
-              err => cb(null, { failed: err != null, project_id })
+              (err) => cb(null, { failed: err != null, project_id })
             )
           ))(project_id)
       }
-      return async.series(jobs, function(error, result) {
+      return async.series(jobs, function (error, result) {
         let x
         if (error != null) {
           return callback(error)
@@ -468,16 +468,16 @@ module.exports = UpdatesManager = {
 
   getDanglingUpdates(callback) {
     if (callback == null) {
-      callback = function(error, doc_ids) {}
+      callback = function (error, doc_ids) {}
     }
-    return RedisManager.getAllDocIdsWithHistoryOps(function(
+    return RedisManager.getAllDocIdsWithHistoryOps(function (
       error,
       all_doc_ids
     ) {
       if (error != null) {
         return callback(error)
       }
-      return RedisManager.getProjectIdsWithHistoryOps(function(
+      return RedisManager.getProjectIdsWithHistoryOps(function (
         error,
         all_project_ids
       ) {
@@ -485,14 +485,14 @@ module.exports = UpdatesManager = {
           return callback(error)
         }
         // function to get doc_ids for each project
-        const task = cb =>
+        const task = (cb) =>
           async.concatSeries(
             all_project_ids,
             RedisManager.getDocIdsWithHistoryOps,
             cb
           )
         // find the dangling doc ids
-        return task(function(error, project_doc_ids) {
+        return task(function (error, project_doc_ids) {
           const dangling_doc_ids = _.difference(all_doc_ids, project_doc_ids)
           logger.log(
             { all_doc_ids, all_project_ids, project_doc_ids, dangling_doc_ids },
@@ -509,12 +509,12 @@ module.exports = UpdatesManager = {
       options = {}
     }
     if (callback == null) {
-      callback = function(error, updates) {}
+      callback = function (error, updates) {}
     }
     return UpdatesManager.processUncompressedUpdatesWithLock(
       project_id,
       doc_id,
-      function(error) {
+      function (error) {
         if (error != null) {
           return callback(error)
         }
@@ -524,7 +524,7 @@ module.exports = UpdatesManager = {
           doc_id,
           options.from,
           options.to,
-          function(error, updates) {
+          function (error, updates) {
             if (error != null) {
               return callback(error)
             }
@@ -540,16 +540,16 @@ module.exports = UpdatesManager = {
       options = {}
     }
     if (callback == null) {
-      callback = function(error, updates) {}
+      callback = function (error, updates) {}
     }
-    return UpdatesManager.getDocUpdates(project_id, doc_id, options, function(
+    return UpdatesManager.getDocUpdates(project_id, doc_id, options, function (
       error,
       updates
     ) {
       if (error != null) {
         return callback(error)
       }
-      return UpdatesManager.fillUserInfo(updates, function(error, updates) {
+      return UpdatesManager.fillUserInfo(updates, function (error, updates) {
         if (error != null) {
           return callback(error)
         }
@@ -563,7 +563,7 @@ module.exports = UpdatesManager = {
       options = {}
     }
     if (callback == null) {
-      callback = function(error, updates) {}
+      callback = function (error, updates) {}
     }
     if (!options.min_count) {
       options.min_count = 25
@@ -573,11 +573,11 @@ module.exports = UpdatesManager = {
     let nextBeforeTimestamp = null
     return UpdatesManager.processUncompressedUpdatesForProject(
       project_id,
-      function(error) {
+      function (error) {
         if (error != null) {
           return callback(error)
         }
-        return PackManager.makeProjectIterator(project_id, before, function(
+        return PackManager.makeProjectIterator(project_id, before, function (
           err,
           iterator
         ) {
@@ -590,8 +590,8 @@ module.exports = UpdatesManager = {
               // console.log "checking iterator.done", iterator.done()
               summarizedUpdates.length < options.min_count && !iterator.done(),
 
-            cb =>
-              iterator.next(function(err, partialUpdates) {
+            (cb) =>
+              iterator.next(function (err, partialUpdates) {
                 if (err != null) {
                   return callback(err)
                 }
@@ -612,19 +612,19 @@ module.exports = UpdatesManager = {
             () =>
               // finally done all updates
               // console.log 'summarized Updates', summarizedUpdates
-              UpdatesManager.fillSummarizedUserInfo(summarizedUpdates, function(
-                err,
-                results
-              ) {
-                if (err != null) {
-                  return callback(err)
+              UpdatesManager.fillSummarizedUserInfo(
+                summarizedUpdates,
+                function (err, results) {
+                  if (err != null) {
+                    return callback(err)
+                  }
+                  return callback(
+                    null,
+                    results,
+                    !iterator.done() ? nextBeforeTimestamp : undefined
+                  )
                 }
-                return callback(
-                  null,
-                  results,
-                  !iterator.done() ? nextBeforeTimestamp : undefined
-                )
-              })
+              )
           )
         })
       }
@@ -633,14 +633,14 @@ module.exports = UpdatesManager = {
 
   fetchUserInfo(users, callback) {
     if (callback == null) {
-      callback = function(error, fetchedUserInfo) {}
+      callback = function (error, fetchedUserInfo) {}
     }
     const jobs = []
     const fetchedUserInfo = {}
     for (const user_id in users) {
-      ;(user_id =>
-        jobs.push(callback =>
-          WebApiManager.getUserInfo(user_id, function(error, userInfo) {
+      ;((user_id) =>
+        jobs.push((callback) =>
+          WebApiManager.getUserInfo(user_id, function (error, userInfo) {
             if (error != null) {
               return callback(error)
             }
@@ -650,7 +650,7 @@ module.exports = UpdatesManager = {
         ))(user_id)
     }
 
-    return async.series(jobs, function(err) {
+    return async.series(jobs, function (err) {
       if (err != null) {
         return callback(err)
       }
@@ -661,7 +661,7 @@ module.exports = UpdatesManager = {
   fillUserInfo(updates, callback) {
     let update, user_id
     if (callback == null) {
-      callback = function(error, updates) {}
+      callback = function (error, updates) {}
     }
     const users = {}
     for (update of Array.from(updates)) {
@@ -671,7 +671,7 @@ module.exports = UpdatesManager = {
       }
     }
 
-    return UpdatesManager.fetchUserInfo(users, function(
+    return UpdatesManager.fetchUserInfo(users, function (
       error,
       fetchedUserInfo
     ) {
@@ -692,7 +692,7 @@ module.exports = UpdatesManager = {
   fillSummarizedUserInfo(updates, callback) {
     let update, user_id, user_ids
     if (callback == null) {
-      callback = function(error, updates) {}
+      callback = function (error, updates) {}
     }
     const users = {}
     for (update of Array.from(updates)) {
@@ -704,7 +704,7 @@ module.exports = UpdatesManager = {
       }
     }
 
-    return UpdatesManager.fetchUserInfo(users, function(
+    return UpdatesManager.fetchUserInfo(users, function (
       error,
       fetchedUserInfo
     ) {

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app/js/UpdatesManager.js.map


+ 6 - 6
services/track-changes/app/js/WebApiManager.js

@@ -26,7 +26,7 @@ const MAX_HTTP_REQUEST_LENGTH = 15000 // 15 seconds
 module.exports = WebApiManager = {
   sendRequest(url, callback) {
     if (callback == null) {
-      callback = function(error, body) {}
+      callback = function (error, body) {}
     }
     return request.get(
       {
@@ -39,7 +39,7 @@ module.exports = WebApiManager = {
           sendImmediately: true
         }
       },
-      function(error, res, body) {
+      function (error, res, body) {
         if (error != null) {
           return callback(error)
         }
@@ -61,11 +61,11 @@ module.exports = WebApiManager = {
 
   getUserInfo(user_id, callback) {
     if (callback == null) {
-      callback = function(error, userInfo) {}
+      callback = function (error, userInfo) {}
     }
     const url = `/user/${user_id}/personal_info`
     logger.log({ user_id }, 'getting user info from web')
-    return WebApiManager.sendRequest(url, function(error, body) {
+    return WebApiManager.sendRequest(url, function (error, body) {
       let user
       if (error != null) {
         logger.error({ err: error, user_id, url }, 'error accessing web')
@@ -93,11 +93,11 @@ module.exports = WebApiManager = {
 
   getProjectDetails(project_id, callback) {
     if (callback == null) {
-      callback = function(error, details) {}
+      callback = function (error, details) {}
     }
     const url = `/project/${project_id}/details`
     logger.log({ project_id }, 'getting project details from web')
-    return WebApiManager.sendRequest(url, function(error, body) {
+    return WebApiManager.sendRequest(url, function (error, body) {
       let project
       if (error != null) {
         logger.error({ err: error, project_id, url }, 'error accessing web')

File diff suppressed because it is too large
+ 8 - 0
services/track-changes/app/js/WebApiManager.js.map


+ 10 - 0
services/track-changes/app/js/mongojs.js.map

@@ -0,0 +1,10 @@
+{
+  "version": 3,
+  "file": "mongojs.js",
+  "sourceRoot": "../..",
+  "sources": [
+    "app/coffee/mongojs.coffee"
+  ],
+  "names": [],
+  "mappings": ";AAAA;AAAA,MAAA;;EAAA,QAAA,GAAW,OAAA,CAAQ,qBAAR;;EACX,OAAA,GAAU,OAAA,CAAQ,SAAR;;EACV,IAAA,GAAO,OAAA,CAAQ,MAAR;;EACP,EAAA,GAAK,OAAA,CAAQ,QAAQ,CAAC,KAAK,CAAC,GAAvB,EAA4B,CAAC,YAAD,EAAe,wBAAf,EAAyC,iBAAzC,CAA5B;;EACL,MAAM,CAAC,OAAP,GACC;IAAA,EAAA,EAAI,EAAJ;IACA,QAAA,EAAU,OAAO,CAAC,QADlB;IAEA,IAAA,EAAM,IAAI,IAAI,CAAC,QAAT,CAAA,CAFN;;AALD"
+}

File diff suppressed because it is too large
+ 388 - 340
services/track-changes/app/lib/diff_match_patch.js


+ 7 - 7
services/track-changes/config/settings.defaults.js

@@ -17,19 +17,19 @@ module.exports = {
   },
   apis: {
     documentupdater: {
-      url: `http://${process.env.DOCUMENT_UPDATER_HOST ||
+      url: `http://${
+        process.env.DOCUMENT_UPDATER_HOST ||
         process.env.DOCUPDATER_HOST ||
-        'localhost'}:3003`
+        'localhost'
+      }:3003`
     },
     docstore: {
       url: `http://${process.env.DOCSTORE_HOST || 'localhost'}:3016`
     },
     web: {
-      url: `http://${process.env.WEB_API_HOST ||
-        process.env.WEB_HOST ||
-        'localhost'}:${process.env.WEB_API_PORT ||
-        process.env.WEB_PORT ||
-        3000}`,
+      url: `http://${
+        process.env.WEB_API_HOST || process.env.WEB_HOST || 'localhost'
+      }:${process.env.WEB_API_PORT || process.env.WEB_PORT || 3000}`,
       user: process.env.WEB_API_USER || 'sharelatex',
       pass: process.env.WEB_API_PASSWORD || 'password'
     }

+ 51 - 51
services/track-changes/test/acceptance/js/AppendingUpdatesTests.js

@@ -24,13 +24,13 @@ const TrackChangesApp = require('./helpers/TrackChangesApp')
 const TrackChangesClient = require('./helpers/TrackChangesClient')
 const MockWebApi = require('./helpers/MockWebApi')
 
-describe('Appending doc ops to the history', function() {
-  before(function(done) {
+describe('Appending doc ops to the history', function () {
+  before(function (done) {
     return TrackChangesApp.ensureRunning(done)
   })
 
-  describe('when the history does not exist yet', function() {
-    before(function(done) {
+  describe('when the history does not exist yet', function () {
+    before(function (done) {
       this.project_id = ObjectId().toString()
       this.doc_id = ObjectId().toString()
       this.user_id = ObjectId().toString()
@@ -55,7 +55,7 @@ describe('Appending doc ops to the history', function() {
             v: 5
           }
         ],
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }
@@ -75,7 +75,7 @@ describe('Appending doc ops to the history', function() {
       return null
     })
 
-    it('should insert the compressed op into mongo', function() {
+    it('should insert the compressed op into mongo', function () {
       return expect(this.updates[0].pack[0].op).to.deep.equal([
         {
           p: 3,
@@ -84,21 +84,21 @@ describe('Appending doc ops to the history', function() {
       ])
     })
 
-    it('should insert the correct version number into mongo', function() {
+    it('should insert the correct version number into mongo', function () {
       return expect(this.updates[0].v).to.equal(5)
     })
 
-    it('should store the doc id', function() {
+    it('should store the doc id', function () {
       return expect(this.updates[0].doc_id.toString()).to.equal(this.doc_id)
     })
 
-    it('should store the project id', function() {
+    it('should store the project id', function () {
       return expect(this.updates[0].project_id.toString()).to.equal(
         this.project_id
       )
     })
 
-    return it('should clear the doc from the DocsWithHistoryOps set', function(done) {
+    return it('should clear the doc from the DocsWithHistoryOps set', function (done) {
       rclient.sismember(
         `DocsWithHistoryOps:${this.project_id}`,
         this.doc_id,
@@ -111,8 +111,8 @@ describe('Appending doc ops to the history', function() {
     })
   })
 
-  describe('when the history has already been started', function() {
-    beforeEach(function(done) {
+  describe('when the history has already been started', function () {
+    beforeEach(function (done) {
       this.project_id = ObjectId().toString()
       this.doc_id = ObjectId().toString()
       this.user_id = ObjectId().toString()
@@ -137,7 +137,7 @@ describe('Appending doc ops to the history', function() {
             v: 5
           }
         ],
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }
@@ -156,8 +156,8 @@ describe('Appending doc ops to the history', function() {
       return null
     })
 
-    describe('when the updates are recent and from the same user', function() {
-      beforeEach(function(done) {
+    describe('when the updates are recent and from the same user', function () {
+      beforeEach(function (done) {
         TrackChangesClient.pushRawUpdates(
           this.project_id,
           this.doc_id,
@@ -178,7 +178,7 @@ describe('Appending doc ops to the history', function() {
               v: 8
             }
           ],
-          error => {
+          (error) => {
             if (error != null) {
               throw error
             }
@@ -198,7 +198,7 @@ describe('Appending doc ops to the history', function() {
         return null
       })
 
-      it('should combine all the updates into one pack', function() {
+      it('should combine all the updates into one pack', function () {
         return expect(this.updates[0].pack[1].op).to.deep.equal([
           {
             p: 6,
@@ -207,13 +207,13 @@ describe('Appending doc ops to the history', function() {
         ])
       })
 
-      return it('should insert the correct version number into mongo', function() {
+      return it('should insert the correct version number into mongo', function () {
         return expect(this.updates[0].v_end).to.equal(8)
       })
     })
 
-    return describe('when the updates are far apart', function() {
-      beforeEach(function(done) {
+    return describe('when the updates are far apart', function () {
+      beforeEach(function (done) {
         const oneDay = 24 * 60 * 60 * 1000
         TrackChangesClient.pushRawUpdates(
           this.project_id,
@@ -235,7 +235,7 @@ describe('Appending doc ops to the history', function() {
               v: 8
             }
           ],
-          error => {
+          (error) => {
             if (error != null) {
               throw error
             }
@@ -255,7 +255,7 @@ describe('Appending doc ops to the history', function() {
         return null
       })
 
-      return it('should combine the updates into one pack', function() {
+      return it('should combine the updates into one pack', function () {
         expect(this.updates[0].pack[0].op).to.deep.equal([
           {
             p: 3,
@@ -272,8 +272,8 @@ describe('Appending doc ops to the history', function() {
     })
   })
 
-  describe('when the updates need processing in batches', function() {
-    before(function(done) {
+  describe('when the updates need processing in batches', function () {
+    before(function (done) {
       this.project_id = ObjectId().toString()
       this.doc_id = ObjectId().toString()
       this.user_id = ObjectId().toString()
@@ -293,7 +293,7 @@ describe('Appending doc ops to the history', function() {
         this.project_id,
         this.doc_id,
         updates,
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }
@@ -313,17 +313,17 @@ describe('Appending doc ops to the history', function() {
       return null
     })
 
-    it('should concat the compressed op into mongo', function() {
+    it('should concat the compressed op into mongo', function () {
       return expect(this.updates[0].pack.length).to.deep.equal(3)
     }) // batch size is 100
 
-    return it('should insert the correct version number into mongo', function() {
+    return it('should insert the correct version number into mongo', function () {
       return expect(this.updates[0].v_end).to.equal(250)
     })
   })
 
-  describe('when there are multiple ops in each update', function() {
-    before(function(done) {
+  describe('when there are multiple ops in each update', function () {
+    before(function (done) {
       this.project_id = ObjectId().toString()
       this.doc_id = ObjectId().toString()
       this.user_id = ObjectId().toString()
@@ -352,7 +352,7 @@ describe('Appending doc ops to the history', function() {
             v: 4
           }
         ],
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }
@@ -372,7 +372,7 @@ describe('Appending doc ops to the history', function() {
       return null
     })
 
-    it('should insert the compressed ops into mongo', function() {
+    it('should insert the compressed ops into mongo', function () {
       expect(this.updates[0].pack[0].op).to.deep.equal([
         {
           p: 3,
@@ -387,14 +387,14 @@ describe('Appending doc ops to the history', function() {
       ])
     })
 
-    return it('should insert the correct version numbers into mongo', function() {
+    return it('should insert the correct version numbers into mongo', function () {
       expect(this.updates[0].pack[0].v).to.equal(3)
       return expect(this.updates[0].pack[1].v).to.equal(4)
     })
   })
 
-  describe('when there is a no-op update', function() {
-    before(function(done) {
+  describe('when there is a no-op update', function () {
+    before(function (done) {
       this.project_id = ObjectId().toString()
       this.doc_id = ObjectId().toString()
       this.user_id = ObjectId().toString()
@@ -415,7 +415,7 @@ describe('Appending doc ops to the history', function() {
             v: 4
           }
         ],
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }
@@ -435,11 +435,11 @@ describe('Appending doc ops to the history', function() {
       return null
     })
 
-    it('should insert the compressed no-op into mongo', function() {
+    it('should insert the compressed no-op into mongo', function () {
       return expect(this.updates[0].pack[0].op).to.deep.equal([])
     })
 
-    it('should insert the compressed next update into mongo', function() {
+    it('should insert the compressed next update into mongo', function () {
       return expect(this.updates[0].pack[1].op).to.deep.equal([
         {
           p: 3,
@@ -448,14 +448,14 @@ describe('Appending doc ops to the history', function() {
       ])
     })
 
-    return it('should insert the correct version numbers into mongo', function() {
+    return it('should insert the correct version numbers into mongo', function () {
       expect(this.updates[0].pack[0].v).to.equal(3)
       return expect(this.updates[0].pack[1].v).to.equal(4)
     })
   })
 
-  describe('when there is a comment update', function() {
-    before(function(done) {
+  describe('when there is a comment update', function () {
+    before(function (done) {
       this.project_id = ObjectId().toString()
       this.doc_id = ObjectId().toString()
       this.user_id = ObjectId().toString()
@@ -473,7 +473,7 @@ describe('Appending doc ops to the history', function() {
             v: 3
           }
         ],
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }
@@ -493,19 +493,19 @@ describe('Appending doc ops to the history', function() {
       return null
     })
 
-    it('should ignore the comment op', function() {
+    it('should ignore the comment op', function () {
       return expect(this.updates[0].pack[0].op).to.deep.equal([
         { d: 'bar', p: 6 }
       ])
     })
 
-    return it('should insert the correct version numbers into mongo', function() {
+    return it('should insert the correct version numbers into mongo', function () {
       return expect(this.updates[0].pack[0].v).to.equal(3)
     })
   })
 
-  describe('when the project has versioning enabled', function() {
-    before(function(done) {
+  describe('when the project has versioning enabled', function () {
+    before(function (done) {
       this.project_id = ObjectId().toString()
       this.doc_id = ObjectId().toString()
       this.user_id = ObjectId().toString()
@@ -521,7 +521,7 @@ describe('Appending doc ops to the history', function() {
             v: 3
           }
         ],
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }
@@ -541,13 +541,13 @@ describe('Appending doc ops to the history', function() {
       return null
     })
 
-    return it('should not add a expiresAt entry in the update in mongo', function() {
+    return it('should not add a expiresAt entry in the update in mongo', function () {
       return expect(this.updates[0].expiresAt).to.be.undefined
     })
   })
 
-  return describe('when the project does not have versioning enabled', function() {
-    before(function(done) {
+  return describe('when the project does not have versioning enabled', function () {
+    before(function (done) {
       this.project_id = ObjectId().toString()
       this.doc_id = ObjectId().toString()
       this.user_id = ObjectId().toString()
@@ -563,7 +563,7 @@ describe('Appending doc ops to the history', function() {
             v: 3
           }
         ],
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }
@@ -583,7 +583,7 @@ describe('Appending doc ops to the history', function() {
       return null
     })
 
-    return it('should add a expiresAt entry in the update in mongo', function() {
+    return it('should add a expiresAt entry in the update in mongo', function () {
       return expect(this.updates[0].expiresAt).to.exist
     })
   })

+ 36 - 28
services/track-changes/test/acceptance/js/ArchivingUpdatesTests.js

@@ -30,15 +30,15 @@ const TrackChangesClient = require('./helpers/TrackChangesClient')
 const MockDocStoreApi = require('./helpers/MockDocStoreApi')
 const MockWebApi = require('./helpers/MockWebApi')
 
-describe('Archiving updates', function() {
-  before(function(done) {
+describe('Archiving updates', function () {
+  before(function (done) {
     if (
       __guard__(
         __guard__(
           Settings != null ? Settings.trackchanges : undefined,
-          x1 => x1.s3
+          (x1) => x1.s3
         ),
-        x => x.key.length
+        (x) => x.key.length
       ) < 1
     ) {
       const message = new Error('s3 keys not setup, this test setup will fail')
@@ -48,7 +48,7 @@ describe('Archiving updates', function() {
     return TrackChangesClient.waitForS3(done)
   })
 
-  before(function(done) {
+  before(function (done) {
     this.now = Date.now()
     this.to = this.now
     this.user_id = ObjectId().toString()
@@ -104,14 +104,14 @@ describe('Archiving updates', function() {
         this.project_id,
         this.doc_id,
         this.updates,
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }
           return TrackChangesClient.flushDoc(
             this.project_id,
             this.doc_id,
-            error => {
+            (error) => {
               if (error != null) {
                 throw error
               }
@@ -124,7 +124,7 @@ describe('Archiving updates', function() {
     return null
   })
 
-  after(function(done) {
+  after(function (done) {
     MockWebApi.getUserInfo.restore()
     return db.docHistory.remove(
       { project_id: ObjectId(this.project_id) },
@@ -143,18 +143,22 @@ describe('Archiving updates', function() {
     )
   })
 
-  describe("archiving a doc's updates", function() {
-    before(function(done) {
-      TrackChangesClient.pushDocHistory(this.project_id, this.doc_id, error => {
-        if (error != null) {
-          throw error
+  describe("archiving a doc's updates", function () {
+    before(function (done) {
+      TrackChangesClient.pushDocHistory(
+        this.project_id,
+        this.doc_id,
+        (error) => {
+          if (error != null) {
+            throw error
+          }
+          return done()
         }
-        return done()
-      })
+      )
       return null
     })
 
-    it('should have one cached pack', function(done) {
+    it('should have one cached pack', function (done) {
       return db.docHistory.count(
         { doc_id: ObjectId(this.doc_id), expiresAt: { $exists: true } },
         (error, count) => {
@@ -167,7 +171,7 @@ describe('Archiving updates', function() {
       )
     })
 
-    it('should have one remaining pack after cache is expired', function(done) {
+    it('should have one remaining pack after cache is expired', function (done) {
       return db.docHistory.remove(
         {
           doc_id: ObjectId(this.doc_id),
@@ -191,7 +195,7 @@ describe('Archiving updates', function() {
       )
     })
 
-    it('should have a docHistoryIndex entry marked as inS3', function(done) {
+    it('should have a docHistoryIndex entry marked as inS3', function (done) {
       return db.docHistoryIndex.findOne(
         { _id: ObjectId(this.doc_id) },
         (error, index) => {
@@ -204,7 +208,7 @@ describe('Archiving updates', function() {
       )
     })
 
-    it('should have a docHistoryIndex entry with the last version', function(done) {
+    it('should have a docHistoryIndex entry with the last version', function (done) {
       return db.docHistoryIndex.findOne(
         { _id: ObjectId(this.doc_id) },
         (error, index) => {
@@ -217,7 +221,7 @@ describe('Archiving updates', function() {
       )
     })
 
-    return it('should store 1024 doc changes in S3 in one pack', function(done) {
+    return it('should store 1024 doc changes in S3 in one pack', function (done) {
       return db.docHistoryIndex.findOne(
         { _id: ObjectId(this.doc_id) },
         (error, index) => {
@@ -240,18 +244,22 @@ describe('Archiving updates', function() {
     })
   })
 
-  return describe("unarchiving a doc's updates", function() {
-    before(function(done) {
-      TrackChangesClient.pullDocHistory(this.project_id, this.doc_id, error => {
-        if (error != null) {
-          throw error
+  return describe("unarchiving a doc's updates", function () {
+    before(function (done) {
+      TrackChangesClient.pullDocHistory(
+        this.project_id,
+        this.doc_id,
+        (error) => {
+          if (error != null) {
+            throw error
+          }
+          return done()
         }
-        return done()
-      })
+      )
       return null
     })
 
-    return it('should restore both packs', function(done) {
+    return it('should restore both packs', function (done) {
       return db.docHistory.count(
         { doc_id: ObjectId(this.doc_id) },
         (error, count) => {

+ 25 - 25
services/track-changes/test/acceptance/js/FlushingUpdatesTests.js

@@ -24,13 +24,13 @@ const TrackChangesApp = require('./helpers/TrackChangesApp')
 const TrackChangesClient = require('./helpers/TrackChangesClient')
 const MockWebApi = require('./helpers/MockWebApi')
 
-describe('Flushing updates', function() {
-  before(function(done) {
+describe('Flushing updates', function () {
+  before(function (done) {
     return TrackChangesApp.ensureRunning(done)
   })
 
-  describe("flushing a doc's updates", function() {
-    before(function(done) {
+  describe("flushing a doc's updates", function () {
+    before(function (done) {
       this.project_id = ObjectId().toString()
       this.doc_id = ObjectId().toString()
       this.user_id = ObjectId().toString()
@@ -46,14 +46,14 @@ describe('Flushing updates', function() {
             v: 3
           }
         ],
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }
           return TrackChangesClient.flushDoc(
             this.project_id,
             this.doc_id,
-            error => {
+            (error) => {
               if (error != null) {
                 throw error
               }
@@ -65,7 +65,7 @@ describe('Flushing updates', function() {
       return null
     })
 
-    return it('should flush the op into mongo', function(done) {
+    return it('should flush the op into mongo', function (done) {
       TrackChangesClient.getCompressedUpdates(this.doc_id, (error, updates) => {
         expect(updates[0].pack[0].op).to.deep.equal([
           {
@@ -79,9 +79,9 @@ describe('Flushing updates', function() {
     })
   })
 
-  return describe("flushing a project's updates", function() {
-    describe('with versioning enabled', function() {
-      before(function(done) {
+  return describe("flushing a project's updates", function () {
+    describe('with versioning enabled', function () {
+      before(function (done) {
         this.project_id = ObjectId().toString()
         this.doc_id = ObjectId().toString()
         this.user_id = ObjectId().toString()
@@ -109,11 +109,11 @@ describe('Flushing updates', function() {
               v: 3
             }
           ],
-          error => {
+          (error) => {
             if (error != null) {
               throw error
             }
-            return TrackChangesClient.flushProject(this.project_id, error => {
+            return TrackChangesClient.flushProject(this.project_id, (error) => {
               if (error != null) {
                 throw error
               }
@@ -124,7 +124,7 @@ describe('Flushing updates', function() {
         return null
       })
 
-      it('should not mark the updates for deletion', function(done) {
+      it('should not mark the updates for deletion', function (done) {
         TrackChangesClient.getCompressedUpdates(
           this.doc_id,
           (error, updates) => {
@@ -135,7 +135,7 @@ describe('Flushing updates', function() {
         return null
       })
 
-      return it('should preserve history forever', function(done) {
+      return it('should preserve history forever', function (done) {
         TrackChangesClient.getProjectMetaData(
           this.project_id,
           (error, project) => {
@@ -147,8 +147,8 @@ describe('Flushing updates', function() {
       })
     })
 
-    describe('without versioning enabled', function() {
-      before(function(done) {
+    describe('without versioning enabled', function () {
+      before(function (done) {
         this.project_id = ObjectId().toString()
         this.doc_id = ObjectId().toString()
         this.user_id = ObjectId().toString()
@@ -176,11 +176,11 @@ describe('Flushing updates', function() {
               v: 3
             }
           ],
-          error => {
+          (error) => {
             if (error != null) {
               throw error
             }
-            return TrackChangesClient.flushProject(this.project_id, error => {
+            return TrackChangesClient.flushProject(this.project_id, (error) => {
               if (error != null) {
                 throw error
               }
@@ -191,7 +191,7 @@ describe('Flushing updates', function() {
         return null
       })
 
-      return it('should mark the updates for deletion', function(done) {
+      return it('should mark the updates for deletion', function (done) {
         TrackChangesClient.getCompressedUpdates(
           this.doc_id,
           (error, updates) => {
@@ -203,8 +203,8 @@ describe('Flushing updates', function() {
       })
     })
 
-    return describe('without versioning enabled but with preserveHistory set to true', function() {
-      before(function(done) {
+    return describe('without versioning enabled but with preserveHistory set to true', function () {
+      before(function (done) {
         this.project_id = ObjectId().toString()
         this.doc_id = ObjectId().toString()
         this.user_id = ObjectId().toString()
@@ -219,7 +219,7 @@ describe('Flushing updates', function() {
 
         TrackChangesClient.setPreserveHistoryForProject(
           this.project_id,
-          error => {
+          (error) => {
             if (error != null) {
               throw error
             }
@@ -241,13 +241,13 @@ describe('Flushing updates', function() {
                   v: 3
                 }
               ],
-              error => {
+              (error) => {
                 if (error != null) {
                   throw error
                 }
                 return TrackChangesClient.flushProject(
                   this.project_id,
-                  error => {
+                  (error) => {
                     if (error != null) {
                       throw error
                     }
@@ -261,7 +261,7 @@ describe('Flushing updates', function() {
         return null
       })
 
-      return it('should not mark the updates for deletion', function(done) {
+      return it('should not mark the updates for deletion', function (done) {
         TrackChangesClient.getCompressedUpdates(
           this.doc_id,
           (error, updates) => {

+ 6 - 6
services/track-changes/test/acceptance/js/GettingADiffTests.js

@@ -23,8 +23,8 @@ const TrackChangesClient = require('./helpers/TrackChangesClient')
 const MockDocUpdaterApi = require('./helpers/MockDocUpdaterApi')
 const MockWebApi = require('./helpers/MockWebApi')
 
-describe('Getting a diff', function() {
-  beforeEach(function(done) {
+describe('Getting a diff', function () {
+  beforeEach(function (done) {
     sinon.spy(MockDocUpdaterApi, 'getDoc')
 
     this.now = Date.now()
@@ -89,7 +89,7 @@ describe('Getting a diff', function() {
         this.project_id,
         this.doc_id,
         this.updates,
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }
@@ -112,17 +112,17 @@ describe('Getting a diff', function() {
     return null
   })
 
-  afterEach(function() {
+  afterEach(function () {
     MockDocUpdaterApi.getDoc.restore()
     MockWebApi.getUserInfo.restore()
     return null
   })
 
-  it('should return the diff', function() {
+  it('should return the diff', function () {
     return expect(this.diff).to.deep.equal(this.expected_diff)
   })
 
-  return it('should get the doc from the doc updater', function() {
+  return it('should get the doc from the doc updater', function () {
     MockDocUpdaterApi.getDoc
       .calledWith(this.project_id, this.doc_id)
       .should.equal(true)

+ 10 - 11
services/track-changes/test/acceptance/js/GettingUpdatesTests.js

@@ -23,8 +23,8 @@ const TrackChangesApp = require('./helpers/TrackChangesApp')
 const TrackChangesClient = require('./helpers/TrackChangesClient')
 const MockWebApi = require('./helpers/MockWebApi')
 
-describe('Getting updates', function() {
-  before(function(done) {
+describe('Getting updates', function () {
+  before(function (done) {
     this.now = Date.now()
     this.to = this.now
     this.user_id = ObjectId().toString()
@@ -72,7 +72,7 @@ describe('Getting updates', function() {
         this.project_id,
         this.doc_id,
         this.updates,
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }
@@ -82,7 +82,6 @@ describe('Getting updates', function() {
     })
     return null
   })
-
   ;({
     after() {
       MockWebApi.getUserInfo.restore()
@@ -90,8 +89,8 @@ describe('Getting updates', function() {
     }
   })
 
-  describe('getting updates up to the limit', function() {
-    before(function(done) {
+  describe('getting updates up to the limit', function () {
+    before(function (done) {
       TrackChangesClient.getUpdates(
         this.project_id,
         { before: this.to + 1, min_count: 3 },
@@ -106,11 +105,11 @@ describe('Getting updates', function() {
       return null
     })
 
-    it('should fetch the user details from the web api', function() {
+    it('should fetch the user details from the web api', function () {
       return MockWebApi.getUserInfo.calledWith(this.user_id).should.equal(true)
     })
 
-    return it('should return at least the min_count number of summarized updates', function() {
+    return it('should return at least the min_count number of summarized updates', function () {
       const docs1 = {}
       docs1[this.doc_id] = { toV: 20, fromV: 19 }
       const docs2 = {}
@@ -146,8 +145,8 @@ describe('Getting updates', function() {
     })
   })
 
-  return describe('getting updates beyond the end of the database', function() {
-    before(function(done) {
+  return describe('getting updates beyond the end of the database', function () {
+    before(function (done) {
       TrackChangesClient.getUpdates(
         this.project_id,
         { before: this.to - 8 * this.hours + 1, min_count: 30 },
@@ -162,7 +161,7 @@ describe('Getting updates', function() {
       return null
     })
 
-    return it('should return as many updates as it can', function() {
+    return it('should return as many updates as it can', function () {
       const docs1 = {}
       docs1[this.doc_id] = { toV: 4, fromV: 3 }
       const docs2 = {}

+ 9 - 9
services/track-changes/test/acceptance/js/LockManagerTests.js

@@ -20,42 +20,42 @@ const LockManager = require('../../../app/js/LockManager')
 const rclient = require('redis').createClient(Settings.redis.history) // Only works locally for now
 const TrackChangesApp = require('./helpers/TrackChangesApp')
 
-describe('Locking document', function() {
-  before(function(done) {
+describe('Locking document', function () {
+  before(function (done) {
     TrackChangesApp.ensureRunning(done)
     return null
   })
 
-  return describe('when the lock has expired in redis', function() {
-    before(function(done) {
+  return describe('when the lock has expired in redis', function () {
+    before(function (done) {
       LockManager.LOCK_TTL = 1 // second
       LockManager.runWithLock(
         'doc123',
-        releaseA => {
+        (releaseA) => {
           // we create a lock A and allow it to expire in redis
           return setTimeout(
             () =>
               // now we create a new lock B and try to release A
               LockManager.runWithLock(
                 'doc123',
-                releaseB => {
+                (releaseB) => {
                   return releaseA()
                 }, // try to release lock A to see if it wipes out lock B
-                error => {}
+                (error) => {}
               ),
 
             // we never release lock B so nothing should happen here
             1500
           )
         }, // enough time to wait until the lock has expired
-        error =>
+        (error) =>
           // we get here after trying to release lock A
           done()
       )
       return null
     })
 
-    return it('the new lock should not be removed by the expired locker', function(done) {
+    return it('the new lock should not be removed by the expired locker', function (done) {
       LockManager.checkLock('doc123', (err, isFree) => {
         expect(isFree).to.equal(false)
         return done()

+ 6 - 6
services/track-changes/test/acceptance/js/RestoringVersions.js

@@ -23,8 +23,8 @@ const TrackChangesClient = require('./helpers/TrackChangesClient')
 const MockDocUpdaterApi = require('./helpers/MockDocUpdaterApi')
 const MockWebApi = require('./helpers/MockWebApi')
 
-describe('Restoring a version', function() {
-  before(function(done) {
+describe('Restoring a version', function () {
+  before(function (done) {
     sinon.spy(MockDocUpdaterApi, 'setDoc')
 
     this.now = Date.now()
@@ -78,7 +78,7 @@ describe('Restoring a version', function() {
         this.project_id,
         this.doc_id,
         this.updates,
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }
@@ -87,7 +87,7 @@ describe('Restoring a version', function() {
             this.doc_id,
             this.beforeVersion,
             this.user_id,
-            error => {
+            (error) => {
               if (error != null) {
                 throw error
               }
@@ -100,12 +100,12 @@ describe('Restoring a version', function() {
     return null
   })
 
-  after(function() {
+  after(function () {
     MockDocUpdaterApi.setDoc.restore()
     return null
   })
 
-  return it('should set the doc in the doc updater', function() {
+  return it('should set the doc in the doc updater', function () {
     MockDocUpdaterApi.setDoc
       .calledWith(
         this.project_id,

+ 3 - 3
services/track-changes/test/acceptance/js/helpers/MockDocStoreApi.js

@@ -19,7 +19,7 @@ module.exports = MockDocUpdaterApi = {
 
   getAllDoc(project_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return callback(null, this.docs)
   },
@@ -39,12 +39,12 @@ module.exports = MockDocUpdaterApi = {
     })
 
     return app
-      .listen(3016, error => {
+      .listen(3016, (error) => {
         if (error != null) {
           throw error
         }
       })
-      .on('error', error => {
+      .on('error', (error) => {
         console.error('error starting MockDocStoreApi:', error.message)
         return process.exit(1)
       })

+ 19 - 22
services/track-changes/test/acceptance/js/helpers/MockDocUpdaterApi.js

@@ -22,14 +22,14 @@ module.exports = MockDocUpdaterApi = {
 
   getDoc(project_id, doc_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return callback(null, this.docs[doc_id])
   },
 
   setDoc(project_id, doc_id, lines, user_id, undoing, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     if (!this.docs[doc_id]) {
       this.docs[doc_id] = {}
@@ -56,33 +56,30 @@ module.exports = MockDocUpdaterApi = {
       )
     })
 
-    app.post(
-      '/project/:project_id/doc/:doc_id',
-      (req, res, next) => {
-        return this.setDoc(
-          req.params.project_id,
-          req.params.doc_id,
-          req.body.lines,
-          req.body.user_id,
-          req.body.undoing,
-          (errr, doc) => {
-            if (typeof error !== 'undefined' && error !== null) {
-              return res.sendStatus(500)
-            } else {
-              return res.sendStatus(204)
-            }
+    app.post('/project/:project_id/doc/:doc_id', (req, res, next) => {
+      return this.setDoc(
+        req.params.project_id,
+        req.params.doc_id,
+        req.body.lines,
+        req.body.user_id,
+        req.body.undoing,
+        (errr, doc) => {
+          if (typeof error !== 'undefined' && error !== null) {
+            return res.sendStatus(500)
+          } else {
+            return res.sendStatus(204)
           }
-        )
-      }
-    )
+        }
+      )
+    })
 
     return app
-      .listen(3003, error => {
+      .listen(3003, (error) => {
         if (error != null) {
           throw error
         }
       })
-      .on('error', error => {
+      .on('error', (error) => {
         console.error('error starting MockDocUpdaterApi:', error.message)
         return process.exit(1)
       })

+ 4 - 4
services/track-changes/test/acceptance/js/helpers/MockWebApi.js

@@ -21,14 +21,14 @@ module.exports = MockWebApi = {
 
   getUserInfo(user_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return callback(null, this.users[user_id] || null)
   },
 
   getProjectDetails(project_id, callback) {
     if (callback == null) {
-      callback = function(error, project) {}
+      callback = function (error, project) {}
     }
     return callback(null, this.projects[project_id])
   },
@@ -61,12 +61,12 @@ module.exports = MockWebApi = {
     })
 
     return app
-      .listen(3000, error => {
+      .listen(3000, (error) => {
         if (error != null) {
           throw error
         }
       })
-      .on('error', error => {
+      .on('error', (error) => {
         console.error('error starting MockWebApiServer:', error.message)
         return process.exit(1)
       })

+ 3 - 3
services/track-changes/test/acceptance/js/helpers/TrackChangesApp.js

@@ -23,7 +23,7 @@ module.exports = {
   callbacks: [],
   ensureRunning(callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     if (this.running) {
       return callback()
@@ -37,10 +37,10 @@ module.exports = {
           Settings.internal != null
             ? Settings.internal.trackchanges
             : undefined,
-          x => x.port
+          (x) => x.port
         ),
         'localhost',
-        error => {
+        (error) => {
           if (error != null) {
             throw error
           }

+ 18 - 18
services/track-changes/test/acceptance/js/helpers/TrackChangesClient.js

@@ -33,9 +33,9 @@ const S3_BUCKET = Settings.trackchanges.stores.doc_history
 module.exports = TrackChangesClient = {
   flushAndGetCompressedUpdates(project_id, doc_id, callback) {
     if (callback == null) {
-      callback = function(error, updates) {}
+      callback = function (error, updates) {}
     }
-    return TrackChangesClient.flushDoc(project_id, doc_id, error => {
+    return TrackChangesClient.flushDoc(project_id, doc_id, (error) => {
       if (error != null) {
         return callback(error)
       }
@@ -45,7 +45,7 @@ module.exports = TrackChangesClient = {
 
   flushDoc(project_id, doc_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return request.post(
       {
@@ -60,7 +60,7 @@ module.exports = TrackChangesClient = {
 
   flushProject(project_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return request.post(
       {
@@ -75,7 +75,7 @@ module.exports = TrackChangesClient = {
 
   getCompressedUpdates(doc_id, callback) {
     if (callback == null) {
-      callback = function(error, updates) {}
+      callback = function (error, updates) {}
     }
     return db.docHistory
       .find({ doc_id: ObjectId(doc_id) })
@@ -85,7 +85,7 @@ module.exports = TrackChangesClient = {
 
   getProjectMetaData(project_id, callback) {
     if (callback == null) {
-      callback = function(error, updates) {}
+      callback = function (error, updates) {}
     }
     return db.projectHistoryMetaData.find(
       {
@@ -97,7 +97,7 @@ module.exports = TrackChangesClient = {
 
   setPreserveHistoryForProject(project_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return db.projectHistoryMetaData.update(
       {
@@ -115,18 +115,18 @@ module.exports = TrackChangesClient = {
 
   pushRawUpdates(project_id, doc_id, updates, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return rclient.sadd(
       Keys.docsWithHistoryOps({ project_id }),
       doc_id,
-      error => {
+      (error) => {
         if (error != null) {
           return callback(error)
         }
         return rclient.rpush(
           Keys.uncompressedHistoryOps({ doc_id }),
-          ...Array.from(Array.from(updates).map(u => JSON.stringify(u))),
+          ...Array.from(Array.from(updates).map((u) => JSON.stringify(u))),
           callback
         )
       }
@@ -135,7 +135,7 @@ module.exports = TrackChangesClient = {
 
   getDiff(project_id, doc_id, from, to, callback) {
     if (callback == null) {
-      callback = function(error, diff) {}
+      callback = function (error, diff) {}
     }
     return request.get(
       {
@@ -150,7 +150,7 @@ module.exports = TrackChangesClient = {
 
   getUpdates(project_id, options, callback) {
     if (callback == null) {
-      callback = function(error, body) {}
+      callback = function (error, body) {}
     }
     return request.get(
       {
@@ -165,7 +165,7 @@ module.exports = TrackChangesClient = {
 
   restoreDoc(project_id, doc_id, version, user_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return request.post(
       {
@@ -183,7 +183,7 @@ module.exports = TrackChangesClient = {
 
   pushDocHistory(project_id, doc_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return request.post(
       {
@@ -198,7 +198,7 @@ module.exports = TrackChangesClient = {
 
   pullDocHistory(project_id, doc_id, callback) {
     if (callback == null) {
-      callback = function(error) {}
+      callback = function (error) {}
     }
     return request.post(
       {
@@ -237,7 +237,7 @@ module.exports = TrackChangesClient = {
 
   getS3Doc(project_id, doc_id, pack_id, callback) {
     if (callback == null) {
-      callback = function(error, body) {}
+      callback = function (error, body) {}
     }
     const params = {
       Bucket: S3_BUCKET,
@@ -263,7 +263,7 @@ module.exports = TrackChangesClient = {
 
   removeS3Doc(project_id, doc_id, callback) {
     if (callback == null) {
-      callback = function(error, res, body) {}
+      callback = function (error, res, body) {}
     }
     let params = {
       Bucket: S3_BUCKET,
@@ -278,7 +278,7 @@ module.exports = TrackChangesClient = {
       params = {
         Bucket: S3_BUCKET,
         Delete: {
-          Objects: data.Contents.map(s3object => ({ Key: s3object.Key }))
+          Objects: data.Contents.map((s3object) => ({ Key: s3object.Key }))
         }
       }
 

+ 59 - 59
services/track-changes/test/unit/js/DiffGenerator/DiffGeneratorTests.js

@@ -17,8 +17,8 @@ const { expect } = chai
 const modulePath = '../../../../app/js/DiffGenerator.js'
 const SandboxedModule = require('sandboxed-module')
 
-describe('DiffGenerator', function() {
-  beforeEach(function() {
+describe('DiffGenerator', function () {
+  beforeEach(function () {
     this.DiffGenerator = SandboxedModule.require(modulePath, {
       requires: {
         'logger-sharelatex': { warn: sinon.stub() }
@@ -34,9 +34,9 @@ describe('DiffGenerator', function() {
     })
   })
 
-  describe('rewindOp', function() {
-    describe('rewinding an insert', function() {
-      return it('should undo the insert', function() {
+  describe('rewindOp', function () {
+    describe('rewinding an insert', function () {
+      return it('should undo the insert', function () {
         const content = 'hello world'
         const rewoundContent = this.DiffGenerator.rewindOp(content, {
           p: 6,
@@ -46,8 +46,8 @@ describe('DiffGenerator', function() {
       })
     })
 
-    describe('rewinding a delete', function() {
-      return it('should undo the delete', function() {
+    describe('rewinding a delete', function () {
+      return it('should undo the delete', function () {
         const content = 'hello rld'
         const rewoundContent = this.DiffGenerator.rewindOp(content, {
           p: 6,
@@ -57,8 +57,8 @@ describe('DiffGenerator', function() {
       })
     })
 
-    describe('with an inconsistent update', function() {
-      return it('should throw an error', function() {
+    describe('with an inconsistent update', function () {
+      return it('should throw an error', function () {
         const content = 'hello world'
         return expect(() => {
           return this.DiffGenerator.rewindOp(content, { p: 6, i: 'foo' })
@@ -66,8 +66,8 @@ describe('DiffGenerator', function() {
       })
     })
 
-    return describe('with an update which is beyond the length of the content', function() {
-      return it('should undo the insert as if it were at the end of the content', function() {
+    return describe('with an update which is beyond the length of the content', function () {
+      return it('should undo the insert as if it were at the end of the content', function () {
         const content = 'foobar'
         const rewoundContent = this.DiffGenerator.rewindOp(content, {
           p: 4,
@@ -78,8 +78,8 @@ describe('DiffGenerator', function() {
     })
   })
 
-  describe('rewindUpdate', function() {
-    return it('should rewind ops in reverse', function() {
+  describe('rewindUpdate', function () {
+    return it('should rewind ops in reverse', function () {
       const content = 'aaabbbccc'
       const update = {
         op: [
@@ -92,8 +92,8 @@ describe('DiffGenerator', function() {
     })
   })
 
-  describe('rewindUpdates', function() {
-    return it('should rewind updates in reverse', function() {
+  describe('rewindUpdates', function () {
+    return it('should rewind updates in reverse', function () {
       const content = 'aaabbbccc'
       const updates = [
         { op: [{ p: 3, i: 'bbb' }] },
@@ -104,8 +104,8 @@ describe('DiffGenerator', function() {
     })
   })
 
-  describe('buildDiff', function() {
-    beforeEach(function() {
+  describe('buildDiff', function () {
+    beforeEach(function () {
       this.diff = [{ u: 'mock-diff' }]
       this.content = 'Hello world'
       this.updates = [
@@ -121,11 +121,11 @@ describe('DiffGenerator', function() {
       ))
     })
 
-    it('should return the diff', function() {
+    it('should return the diff', function () {
       return this.result.should.deep.equal(this.diff)
     })
 
-    it('should build the content into an initial diff', function() {
+    it('should build the content into an initial diff', function () {
       return this.DiffGenerator.applyUpdateToDiff
         .calledWith(
           [
@@ -138,24 +138,24 @@ describe('DiffGenerator', function() {
         .should.equal(true)
     })
 
-    it('should apply each update', function() {
-      return Array.from(this.updates).map(update =>
+    it('should apply each update', function () {
+      return Array.from(this.updates).map((update) =>
         this.DiffGenerator.applyUpdateToDiff
           .calledWith(sinon.match.any, update)
           .should.equal(true)
       )
     })
 
-    return it('should compress the diff', function() {
+    return it('should compress the diff', function () {
       return this.DiffGenerator.compressDiff
         .calledWith(this.diff)
         .should.equal(true)
     })
   })
 
-  describe('compressDiff', function() {
-    describe('with adjacent inserts with the same user_id', function() {
-      return it('should create one update with combined meta data and min/max timestamps', function() {
+  describe('compressDiff', function () {
+    describe('with adjacent inserts with the same user_id', function () {
+      return it('should create one update with combined meta data and min/max timestamps', function () {
         const diff = this.DiffGenerator.compressDiff([
           {
             i: 'foo',
@@ -175,8 +175,8 @@ describe('DiffGenerator', function() {
       })
     })
 
-    describe('with adjacent inserts with different user_ids', function() {
-      return it('should leave the inserts unchanged', function() {
+    describe('with adjacent inserts with different user_ids', function () {
+      return it('should leave the inserts unchanged', function () {
         const input = [
           {
             i: 'foo',
@@ -192,8 +192,8 @@ describe('DiffGenerator', function() {
       })
     })
 
-    describe('with adjacent deletes with the same user_id', function() {
-      return it('should create one update with combined meta data and min/max timestamps', function() {
+    describe('with adjacent deletes with the same user_id', function () {
+      return it('should create one update with combined meta data and min/max timestamps', function () {
         const diff = this.DiffGenerator.compressDiff([
           {
             d: 'foo',
@@ -213,8 +213,8 @@ describe('DiffGenerator', function() {
       })
     })
 
-    return describe('with adjacent deletes with different user_ids', function() {
-      return it('should leave the deletes unchanged', function() {
+    return describe('with adjacent deletes with different user_ids', function () {
+      return it('should leave the deletes unchanged', function () {
         const input = [
           {
             d: 'foo',
@@ -231,9 +231,9 @@ describe('DiffGenerator', function() {
     })
   })
 
-  return describe('applyUpdateToDiff', function() {
-    describe('an insert', function() {
-      it('should insert into the middle of (u)nchanged text', function() {
+  return describe('applyUpdateToDiff', function () {
+    describe('an insert', function () {
+      it('should insert into the middle of (u)nchanged text', function () {
         const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], {
           op: [{ p: 3, i: 'baz' }],
           meta: this.meta
@@ -245,7 +245,7 @@ describe('DiffGenerator', function() {
         ])
       })
 
-      it('should insert into the start of (u)changed text', function() {
+      it('should insert into the start of (u)changed text', function () {
         const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], {
           op: [{ p: 0, i: 'baz' }],
           meta: this.meta
@@ -256,7 +256,7 @@ describe('DiffGenerator', function() {
         ])
       })
 
-      it('should insert into the end of (u)changed text', function() {
+      it('should insert into the end of (u)changed text', function () {
         const diff = this.DiffGenerator.applyUpdateToDiff([{ u: 'foobar' }], {
           op: [{ p: 6, i: 'baz' }],
           meta: this.meta
@@ -267,7 +267,7 @@ describe('DiffGenerator', function() {
         ])
       })
 
-      it('should insert into the middle of (i)inserted text', function() {
+      it('should insert into the middle of (i)inserted text', function () {
         const diff = this.DiffGenerator.applyUpdateToDiff(
           [{ i: 'foobar', meta: this.meta }],
           { op: [{ p: 3, i: 'baz' }], meta: this.meta }
@@ -279,7 +279,7 @@ describe('DiffGenerator', function() {
         ])
       })
 
-      return it('should not count deletes in the running length total', function() {
+      return it('should not count deletes in the running length total', function () {
         const diff = this.DiffGenerator.applyUpdateToDiff(
           [{ d: 'deleted', meta: this.meta }, { u: 'foobar' }],
           { op: [{ p: 3, i: 'baz' }], meta: this.meta }
@@ -293,9 +293,9 @@ describe('DiffGenerator', function() {
       })
     })
 
-    return describe('a delete', function() {
-      describe('deleting unchanged text', function() {
-        it('should delete from the middle of (u)nchanged text', function() {
+    return describe('a delete', function () {
+      describe('deleting unchanged text', function () {
+        it('should delete from the middle of (u)nchanged text', function () {
           const diff = this.DiffGenerator.applyUpdateToDiff(
             [{ u: 'foobazbar' }],
             { op: [{ p: 3, d: 'baz' }], meta: this.meta }
@@ -307,7 +307,7 @@ describe('DiffGenerator', function() {
           ])
         })
 
-        it('should delete from the start of (u)nchanged text', function() {
+        it('should delete from the start of (u)nchanged text', function () {
           const diff = this.DiffGenerator.applyUpdateToDiff(
             [{ u: 'foobazbar' }],
             { op: [{ p: 0, d: 'foo' }], meta: this.meta }
@@ -318,7 +318,7 @@ describe('DiffGenerator', function() {
           ])
         })
 
-        it('should delete from the end of (u)nchanged text', function() {
+        it('should delete from the end of (u)nchanged text', function () {
           const diff = this.DiffGenerator.applyUpdateToDiff(
             [{ u: 'foobazbar' }],
             { op: [{ p: 6, d: 'bar' }], meta: this.meta }
@@ -329,7 +329,7 @@ describe('DiffGenerator', function() {
           ])
         })
 
-        return it('should delete across multiple (u)changed text parts', function() {
+        return it('should delete across multiple (u)changed text parts', function () {
           const diff = this.DiffGenerator.applyUpdateToDiff(
             [{ u: 'foo' }, { u: 'baz' }, { u: 'bar' }],
             { op: [{ p: 2, d: 'obazb' }], meta: this.meta }
@@ -344,8 +344,8 @@ describe('DiffGenerator', function() {
         })
       })
 
-      describe('deleting inserts', function() {
-        it('should delete from the middle of (i)nserted text', function() {
+      describe('deleting inserts', function () {
+        it('should delete from the middle of (i)nserted text', function () {
           const diff = this.DiffGenerator.applyUpdateToDiff(
             [{ i: 'foobazbar', meta: this.meta }],
             { op: [{ p: 3, d: 'baz' }], meta: this.meta }
@@ -356,7 +356,7 @@ describe('DiffGenerator', function() {
           ])
         })
 
-        it('should delete from the start of (u)nchanged text', function() {
+        it('should delete from the start of (u)nchanged text', function () {
           const diff = this.DiffGenerator.applyUpdateToDiff(
             [{ i: 'foobazbar', meta: this.meta }],
             { op: [{ p: 0, d: 'foo' }], meta: this.meta }
@@ -364,7 +364,7 @@ describe('DiffGenerator', function() {
           return expect(diff).to.deep.equal([{ i: 'bazbar', meta: this.meta }])
         })
 
-        it('should delete from the end of (u)nchanged text', function() {
+        it('should delete from the end of (u)nchanged text', function () {
           const diff = this.DiffGenerator.applyUpdateToDiff(
             [{ i: 'foobazbar', meta: this.meta }],
             { op: [{ p: 6, d: 'bar' }], meta: this.meta }
@@ -372,7 +372,7 @@ describe('DiffGenerator', function() {
           return expect(diff).to.deep.equal([{ i: 'foobaz', meta: this.meta }])
         })
 
-        return it('should delete across multiple (u)changed and (i)nserted text parts', function() {
+        return it('should delete across multiple (u)changed and (i)nserted text parts', function () {
           const diff = this.DiffGenerator.applyUpdateToDiff(
             [{ u: 'foo' }, { i: 'baz', meta: this.meta }, { u: 'bar' }],
             { op: [{ p: 2, d: 'obazb' }], meta: this.meta }
@@ -386,8 +386,8 @@ describe('DiffGenerator', function() {
         })
       })
 
-      describe('deleting over existing deletes', function() {
-        return it('should delete across multiple (u)changed and (d)deleted text parts', function() {
+      describe('deleting over existing deletes', function () {
+        return it('should delete across multiple (u)changed and (d)deleted text parts', function () {
           const diff = this.DiffGenerator.applyUpdateToDiff(
             [{ u: 'foo' }, { d: 'baz', meta: this.meta }, { u: 'bar' }],
             { op: [{ p: 2, d: 'ob' }], meta: this.meta }
@@ -402,8 +402,8 @@ describe('DiffGenerator', function() {
         })
       })
 
-      describe("deleting when the text doesn't match", function() {
-        it('should throw an error when deleting from the middle of (u)nchanged text', function() {
+      describe("deleting when the text doesn't match", function () {
+        it('should throw an error when deleting from the middle of (u)nchanged text', function () {
           return expect(() =>
             this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], {
               op: [{ p: 3, d: 'xxx' }],
@@ -412,7 +412,7 @@ describe('DiffGenerator', function() {
           ).to.throw(this.DiffGenerator.ConsistencyError)
         })
 
-        it('should throw an error when deleting from the start of (u)nchanged text', function() {
+        it('should throw an error when deleting from the start of (u)nchanged text', function () {
           return expect(() =>
             this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], {
               op: [{ p: 0, d: 'xxx' }],
@@ -421,7 +421,7 @@ describe('DiffGenerator', function() {
           ).to.throw(this.DiffGenerator.ConsistencyError)
         })
 
-        return it('should throw an error when deleting from the end of (u)nchanged text', function() {
+        return it('should throw an error when deleting from the end of (u)nchanged text', function () {
           return expect(() =>
             this.DiffGenerator.applyUpdateToDiff([{ u: 'foobazbar' }], {
               op: [{ p: 6, d: 'xxx' }],
@@ -431,8 +431,8 @@ describe('DiffGenerator', function() {
         })
       })
 
-      describe('when the last update in the existing diff is a delete', function() {
-        return it('should insert the new update before the delete', function() {
+      describe('when the last update in the existing diff is a delete', function () {
+        return it('should insert the new update before the delete', function () {
           const diff = this.DiffGenerator.applyUpdateToDiff(
             [{ u: 'foo' }, { d: 'bar', meta: this.meta }],
             { op: [{ p: 3, i: 'baz' }], meta: this.meta }
@@ -445,8 +445,8 @@ describe('DiffGenerator', function() {
         })
       })
 
-      return describe('when the only update in the existing diff is a delete', function() {
-        return it('should insert the new update after the delete', function() {
+      return describe('when the only update in the existing diff is a delete', function () {
+        return it('should insert the new update after the delete', function () {
           const diff = this.DiffGenerator.applyUpdateToDiff(
             [{ d: 'bar', meta: this.meta }],
             { op: [{ p: 0, i: 'baz' }], meta: this.meta }

+ 56 - 57
services/track-changes/test/unit/js/DiffManager/DiffManagerTests.js

@@ -17,8 +17,8 @@ const { expect } = chai
 const modulePath = '../../../../app/js/DiffManager.js'
 const SandboxedModule = require('sandboxed-module')
 
-describe('DiffManager', function() {
-  beforeEach(function() {
+describe('DiffManager', function () {
+  beforeEach(function () {
     this.DiffManager = SandboxedModule.require(modulePath, {
       requires: {
         'logger-sharelatex': (this.logger = {
@@ -38,8 +38,8 @@ describe('DiffManager', function() {
     return (this.doc_id = 'mock-doc-id')
   })
 
-  describe('getLatestDocAndUpdates', function() {
-    beforeEach(function() {
+  describe('getLatestDocAndUpdates', function () {
+    beforeEach(function () {
       this.content = 'hello world'
       this.version = 42
       this.updates = ['mock-update-1', 'mock-update-2']
@@ -52,8 +52,8 @@ describe('DiffManager', function() {
         .callsArgWith(3, null, this.updates))
     })
 
-    describe('with a fromVersion', function() {
-      beforeEach(function() {
+    describe('with a fromVersion', function () {
+      beforeEach(function () {
         return this.DiffManager.getLatestDocAndUpdates(
           this.project_id,
           this.doc_id,
@@ -62,27 +62,27 @@ describe('DiffManager', function() {
         )
       })
 
-      it('should get the latest version of the doc', function() {
+      it('should get the latest version of the doc', function () {
         return this.DocumentUpdaterManager.getDocument
           .calledWith(this.project_id, this.doc_id)
           .should.equal(true)
       })
 
-      it('should get the latest updates', function() {
+      it('should get the latest updates', function () {
         return this.UpdatesManager.getDocUpdatesWithUserInfo
           .calledWith(this.project_id, this.doc_id, { from: this.from })
           .should.equal(true)
       })
 
-      return it('should call the callback with the content, version and updates', function() {
+      return it('should call the callback with the content, version and updates', function () {
         return this.callback
           .calledWith(null, this.content, this.version, this.updates)
           .should.equal(true)
       })
     })
 
-    return describe('with no fromVersion', function() {
-      beforeEach(function() {
+    return describe('with no fromVersion', function () {
+      beforeEach(function () {
         return this.DiffManager.getLatestDocAndUpdates(
           this.project_id,
           this.doc_id,
@@ -91,19 +91,19 @@ describe('DiffManager', function() {
         )
       })
 
-      it('should get the latest version of the doc', function() {
+      it('should get the latest version of the doc', function () {
         return this.DocumentUpdaterManager.getDocument
           .calledWith(this.project_id, this.doc_id)
           .should.equal(true)
       })
 
-      it('should not get the latest updates', function() {
+      it('should not get the latest updates', function () {
         return this.UpdatesManager.getDocUpdatesWithUserInfo.called.should.equal(
           false
         )
       })
 
-      return it('should call the callback with the content, version and blank updates', function() {
+      return it('should call the callback with the content, version and blank updates', function () {
         return this.callback
           .calledWith(null, this.content, this.version, [])
           .should.equal(true)
@@ -111,8 +111,8 @@ describe('DiffManager', function() {
     })
   })
 
-  describe('getDiff', function() {
-    beforeEach(function() {
+  describe('getDiff', function () {
+    beforeEach(function () {
       this.content = 'hello world'
       // Op versions are the version they were applied to, so doc is always one version
       // ahead.s
@@ -146,8 +146,8 @@ describe('DiffManager', function() {
       return (this.diff = [{ u: 'mock-diff' }])
     })
 
-    describe('with matching versions', function() {
-      beforeEach(function() {
+    describe('with matching versions', function () {
+      beforeEach(function () {
         this.DiffManager.getDocumentBeforeVersion = sinon
           .stub()
           .callsArgWith(3, null, this.rewound_content, this.updates)
@@ -161,13 +161,13 @@ describe('DiffManager', function() {
         )
       })
 
-      it('should get the latest doc and version with all recent updates', function() {
+      it('should get the latest doc and version with all recent updates', function () {
         return this.DiffManager.getDocumentBeforeVersion
           .calledWith(this.project_id, this.doc_id, this.fromVersion)
           .should.equal(true)
       })
 
-      it('should generate the diff', function() {
+      it('should generate the diff', function () {
         return this.DiffGenerator.buildDiff
           .calledWith(
             this.rewound_content,
@@ -176,21 +176,20 @@ describe('DiffManager', function() {
           .should.equal(true)
       })
 
-      return it('should call the callback with the diff', function() {
+      return it('should call the callback with the diff', function () {
         return this.callback.calledWith(null, this.diff).should.equal(true)
       })
     })
 
-    describe('when the updates are inconsistent', function() {
-      beforeEach(function() {
+    describe('when the updates are inconsistent', function () {
+      beforeEach(function () {
         this.DiffManager.getLatestDocAndUpdates = sinon
           .stub()
           .callsArgWith(3, null, this.content, this.version, this.updates)
         this.DiffGenerator.buildDiff = sinon
           .stub()
           .throws((this.error = new Error('inconsistent!')))
-        this.DiffGenerator.rewindUpdates = sinon
-            .stub()
+        this.DiffGenerator.rewindUpdates = sinon.stub()
         this.DiffManager.getDiff(
           this.project_id,
           this.doc_id,
@@ -200,7 +199,7 @@ describe('DiffManager', function() {
         )
       })
 
-      it('should call the callback with an error', function() {
+      it('should call the callback with an error', function () {
         this.callback.calledWith(sinon.match(Error)).should.equal(true)
         const errorObj = this.callback.args[0][0]
         expect(errorObj.message).to.include('inconsistent!')
@@ -208,15 +207,15 @@ describe('DiffManager', function() {
     })
   })
 
-  describe('getDocumentBeforeVersion', function() {
-    beforeEach(function() {
+  describe('getDocumentBeforeVersion', function () {
+    beforeEach(function () {
       this.DiffManager._tryGetDocumentBeforeVersion = sinon.stub()
       this.document = 'mock-documents'
       return (this.rewound_updates = 'mock-rewound-updates')
     })
 
-    describe('succesfully', function() {
-      beforeEach(function() {
+    describe('succesfully', function () {
+      beforeEach(function () {
         this.DiffManager._tryGetDocumentBeforeVersion.yields(
           null,
           this.document,
@@ -230,21 +229,21 @@ describe('DiffManager', function() {
         )
       })
 
-      it('should call _tryGetDocumentBeforeVersion', function() {
+      it('should call _tryGetDocumentBeforeVersion', function () {
         return this.DiffManager._tryGetDocumentBeforeVersion
           .calledWith(this.project_id, this.doc_id, this.version)
           .should.equal(true)
       })
 
-      return it('should call the callback with the response', function() {
+      return it('should call the callback with the response', function () {
         return this.callback
           .calledWith(null, this.document, this.rewound_updates)
           .should.equal(true)
       })
     })
 
-    describe('with a retry needed', function() {
-      beforeEach(function() {
+    describe('with a retry needed', function () {
+      beforeEach(function () {
         let retried = false
         this.DiffManager._tryGetDocumentBeforeVersion = (
           project_id,
@@ -270,21 +269,21 @@ describe('DiffManager', function() {
         )
       })
 
-      it('should call _tryGetDocumentBeforeVersion twice', function() {
+      it('should call _tryGetDocumentBeforeVersion twice', function () {
         return this.DiffManager._tryGetDocumentBeforeVersion.calledTwice.should.equal(
           true
         )
       })
 
-      return it('should call the callback with the response', function() {
+      return it('should call the callback with the response', function () {
         return this.callback
           .calledWith(null, this.document, this.rewound_updates)
           .should.equal(true)
       })
     })
 
-    describe('with a non-retriable error', function() {
-      beforeEach(function() {
+    describe('with a non-retriable error', function () {
+      beforeEach(function () {
         this.error = new Error('oops')
         this.DiffManager._tryGetDocumentBeforeVersion.yields(this.error)
         return this.DiffManager.getDocumentBeforeVersion(
@@ -295,19 +294,19 @@ describe('DiffManager', function() {
         )
       })
 
-      it('should call _tryGetDocumentBeforeVersion once', function() {
+      it('should call _tryGetDocumentBeforeVersion once', function () {
         return this.DiffManager._tryGetDocumentBeforeVersion.calledOnce.should.equal(
           true
         )
       })
 
-      return it('should call the callback with the error', function() {
+      return it('should call the callback with the error', function () {
         return this.callback.calledWith(this.error).should.equal(true)
       })
     })
 
-    return describe('when retry limit is matched', function() {
-      beforeEach(function() {
+    return describe('when retry limit is matched', function () {
+      beforeEach(function () {
         this.error = new Error('oops')
         this.error.retry = true
         this.DiffManager._tryGetDocumentBeforeVersion.yields(this.error)
@@ -319,20 +318,20 @@ describe('DiffManager', function() {
         )
       })
 
-      it('should call _tryGetDocumentBeforeVersion three times (max retries)', function() {
+      it('should call _tryGetDocumentBeforeVersion three times (max retries)', function () {
         return this.DiffManager._tryGetDocumentBeforeVersion.calledThrice.should.equal(
           true
         )
       })
 
-      return it('should call the callback with the error', function() {
+      return it('should call the callback with the error', function () {
         return this.callback.calledWith(this.error).should.equal(true)
       })
     })
   })
 
-  return describe('_tryGetDocumentBeforeVersion', function() {
-    beforeEach(function() {
+  return describe('_tryGetDocumentBeforeVersion', function () {
+    beforeEach(function () {
       this.content = 'hello world'
       // Op versions are the version they were applied to, so doc is always one version
       // ahead.s
@@ -364,8 +363,8 @@ describe('DiffManager', function() {
       return (this.diff = [{ u: 'mock-diff' }])
     })
 
-    describe('with matching versions', function() {
-      beforeEach(function() {
+    describe('with matching versions', function () {
+      beforeEach(function () {
         this.DiffManager.getLatestDocAndUpdates = sinon
           .stub()
           .callsArgWith(3, null, this.content, this.version, this.updates)
@@ -386,25 +385,25 @@ describe('DiffManager', function() {
         )
       })
 
-      it('should get the latest doc and version with all recent updates', function() {
+      it('should get the latest doc and version with all recent updates', function () {
         return this.DiffManager.getLatestDocAndUpdates
           .calledWith(this.project_id, this.doc_id, this.fromVersion)
           .should.equal(true)
       })
 
-      it('should rewind the diff', function() {
+      it('should rewind the diff', function () {
         return sinon.assert.calledOnce(this.rewindUpdatesWithArgs)
       })
 
-      return it('should call the callback with the rewound document and updates', function() {
+      return it('should call the callback with the rewound document and updates', function () {
         return this.callback
           .calledWith(null, this.rewound_content, this.updates)
           .should.equal(true)
       })
     })
 
-    describe('with mismatching versions', function() {
-      beforeEach(function() {
+    describe('with mismatching versions', function () {
+      beforeEach(function () {
         this.version = 50
         this.updates = [
           { op: 'mock-1', v: 40 },
@@ -421,15 +420,15 @@ describe('DiffManager', function() {
         )
       })
 
-      return it('should call the callback with an error with retry = true set', function() {
+      return it('should call the callback with an error with retry = true set', function () {
         this.callback.calledOnce.should.equal(true)
         const error = this.callback.args[0][0]
         return expect(error.retry).to.equal(true)
       })
     })
 
-    return describe('when the updates are inconsistent', function() {
-      beforeEach(function() {
+    return describe('when the updates are inconsistent', function () {
+      beforeEach(function () {
         this.DiffManager.getLatestDocAndUpdates = sinon
           .stub()
           .callsArgWith(3, null, this.content, this.version, this.updates)
@@ -444,7 +443,7 @@ describe('DiffManager', function() {
         )
       })
 
-      return it('should call the callback with an error', function() {
+      return it('should call the callback with an error', function () {
         return this.callback.calledWith(this.error).should.equal(true)
       })
     })

+ 8 - 8
services/track-changes/test/unit/js/DocArchive/MongoAWS.js

@@ -18,8 +18,8 @@ const { ObjectId } = require('mongojs')
 const MemoryStream = require('memorystream')
 const zlib = require('zlib')
 
-describe('MongoAWS', function() {
-  beforeEach(function() {
+describe('MongoAWS', function () {
+  beforeEach(function () {
     this.MongoAWS = SandboxedModule.require(modulePath, {
       singleOnly: true,
       requires: {
@@ -58,8 +58,8 @@ describe('MongoAWS', function() {
     return (this.callback = sinon.stub())
   })
 
-  describe('archivePack', function() {
-    beforeEach(function(done) {
+  describe('archivePack', function () {
+    beforeEach(function (done) {
       this.awssdk.config = { update: sinon.stub() }
       this.awssdk.S3 = sinon.stub()
       this.S3S.WriteStream = () => MemoryStream.createWriteStream()
@@ -79,13 +79,13 @@ describe('MongoAWS', function() {
       )
     })
 
-    return it('should call the callback', function() {
+    return it('should call the callback', function () {
       return this.callback.called.should.equal(true)
     })
   })
 
-  return describe('unArchivePack', function() {
-    beforeEach(function(done) {
+  return describe('unArchivePack', function () {
+    beforeEach(function (done) {
       return zlib.gzip('{"pack":"123"}', (err, zbuf) => {
         this.awssdk.config = { update: sinon.stub() }
         this.awssdk.S3 = sinon.stub()
@@ -106,7 +106,7 @@ describe('MongoAWS', function() {
       })
     })
 
-    return it('should call db.docHistory.insert', function() {
+    return it('should call db.docHistory.insert', function () {
       return this.db.docHistory.insert.called.should.equal(true)
     })
   })

+ 25 - 25
services/track-changes/test/unit/js/DocumentUpdaterManager/DocumentUpdaterManagerTests.js

@@ -16,8 +16,8 @@ const { expect } = chai
 const modulePath = '../../../../app/js/DocumentUpdaterManager.js'
 const SandboxedModule = require('sandboxed-module')
 
-describe('DocumentUpdaterManager', function() {
-  beforeEach(function() {
+describe('DocumentUpdaterManager', function () {
+  beforeEach(function () {
     this.DocumentUpdaterManager = SandboxedModule.require(modulePath, {
       requires: {
         request: (this.request = {}),
@@ -35,9 +35,9 @@ describe('DocumentUpdaterManager', function() {
     return (this.version = 42)
   })
 
-  describe('getDocument', function() {
-    describe('successfully', function() {
-      beforeEach(function() {
+  describe('getDocument', function () {
+    describe('successfully', function () {
+      beforeEach(function () {
         this.body = JSON.stringify({
           lines: this.lines,
           version: this.version,
@@ -53,20 +53,20 @@ describe('DocumentUpdaterManager', function() {
         )
       })
 
-      it('should get the document from the document updater', function() {
+      it('should get the document from the document updater', function () {
         const url = `${this.settings.apis.documentupdater.url}/project/${this.project_id}/doc/${this.doc_id}`
         return this.request.get.calledWith(url).should.equal(true)
       })
 
-      return it('should call the callback with the content and version', function() {
+      return it('should call the callback with the content and version', function () {
         return this.callback
           .calledWith(null, this.lines.join('\n'), this.version)
           .should.equal(true)
       })
     })
 
-    describe('when the document updater API returns an error', function() {
-      beforeEach(function() {
+    describe('when the document updater API returns an error', function () {
+      beforeEach(function () {
         this.request.get = sinon
           .stub()
           .callsArgWith(
@@ -82,13 +82,13 @@ describe('DocumentUpdaterManager', function() {
         )
       })
 
-      return it('should return an error to the callback', function() {
+      return it('should return an error to the callback', function () {
         return this.callback.calledWith(this.error).should.equal(true)
       })
     })
 
-    return describe('when the document updater returns a failure error code', function() {
-      beforeEach(function() {
+    return describe('when the document updater returns a failure error code', function () {
+      beforeEach(function () {
         this.request.get = sinon
           .stub()
           .callsArgWith(1, null, { statusCode: 500 }, '')
@@ -99,7 +99,7 @@ describe('DocumentUpdaterManager', function() {
         )
       })
 
-      return it('should return the callback with an error', function() {
+      return it('should return the callback with an error', function () {
         return this.callback
           .calledWith(
             sinon.match.has(
@@ -112,14 +112,14 @@ describe('DocumentUpdaterManager', function() {
     })
   })
 
-  return describe('setDocument', function() {
-    beforeEach(function() {
+  return describe('setDocument', function () {
+    beforeEach(function () {
       this.content = 'mock content'
       return (this.user_id = 'user-id-123')
     })
 
-    describe('successfully', function() {
-      beforeEach(function() {
+    describe('successfully', function () {
+      beforeEach(function () {
         this.request.post = sinon
           .stub()
           .callsArgWith(1, null, { statusCode: 200 })
@@ -132,7 +132,7 @@ describe('DocumentUpdaterManager', function() {
         )
       })
 
-      it('should set the document in the document updater', function() {
+      it('should set the document in the document updater', function () {
         const url = `${this.settings.apis.documentupdater.url}/project/${this.project_id}/doc/${this.doc_id}`
         return this.request.post
           .calledWith({
@@ -147,13 +147,13 @@ describe('DocumentUpdaterManager', function() {
           .should.equal(true)
       })
 
-      return it('should call the callback', function() {
+      return it('should call the callback', function () {
         return this.callback.calledWith(null).should.equal(true)
       })
     })
 
-    describe('when the document updater API returns an error', function() {
-      beforeEach(function() {
+    describe('when the document updater API returns an error', function () {
+      beforeEach(function () {
         this.request.post = sinon
           .stub()
           .callsArgWith(
@@ -171,13 +171,13 @@ describe('DocumentUpdaterManager', function() {
         )
       })
 
-      return it('should return an error to the callback', function() {
+      return it('should return an error to the callback', function () {
         return this.callback.calledWith(this.error).should.equal(true)
       })
     })
 
-    return describe('when the document updater returns a failure error code', function() {
-      beforeEach(function() {
+    return describe('when the document updater returns a failure error code', function () {
+      beforeEach(function () {
         this.request.post = sinon
           .stub()
           .callsArgWith(1, null, { statusCode: 500 }, '')
@@ -190,7 +190,7 @@ describe('DocumentUpdaterManager', function() {
         )
       })
 
-      return it('should return the callback with an error', function() {
+      return it('should return the callback with an error', function () {
         return this.callback
           .calledWith(
             sinon.match.has(

+ 22 - 22
services/track-changes/test/unit/js/HttpController/HttpControllerTests.js

@@ -16,8 +16,8 @@ const { expect } = chai
 const modulePath = '../../../../app/js/HttpController.js'
 const SandboxedModule = require('sandboxed-module')
 
-describe('HttpController', function() {
-  beforeEach(function() {
+describe('HttpController', function () {
+  beforeEach(function () {
     this.HttpController = SandboxedModule.require(modulePath, {
       singleOnly: true,
       requires: {
@@ -37,8 +37,8 @@ describe('HttpController', function() {
     return (this.now = Date.now())
   })
 
-  describe('flushDoc', function() {
-    beforeEach(function() {
+  describe('flushDoc', function () {
+    beforeEach(function () {
       this.req = {
         params: {
           doc_id: this.doc_id,
@@ -52,19 +52,19 @@ describe('HttpController', function() {
       return this.HttpController.flushDoc(this.req, this.res, this.next)
     })
 
-    it('should process the updates', function() {
+    it('should process the updates', function () {
       return this.UpdatesManager.processUncompressedUpdatesWithLock
         .calledWith(this.project_id, this.doc_id)
         .should.equal(true)
     })
 
-    return it('should return a success code', function() {
+    return it('should return a success code', function () {
       return this.res.sendStatus.calledWith(204).should.equal(true)
     })
   })
 
-  describe('flushProject', function() {
-    beforeEach(function() {
+  describe('flushProject', function () {
+    beforeEach(function () {
       this.req = {
         params: {
           project_id: this.project_id
@@ -77,19 +77,19 @@ describe('HttpController', function() {
       return this.HttpController.flushProject(this.req, this.res, this.next)
     })
 
-    it('should process the updates', function() {
+    it('should process the updates', function () {
       return this.UpdatesManager.processUncompressedUpdatesForProject
         .calledWith(this.project_id)
         .should.equal(true)
     })
 
-    return it('should return a success code', function() {
+    return it('should return a success code', function () {
       return this.res.sendStatus.calledWith(204).should.equal(true)
     })
   })
 
-  describe('getDiff', function() {
-    beforeEach(function() {
+  describe('getDiff', function () {
+    beforeEach(function () {
       this.from = 42
       this.to = 45
       this.req = {
@@ -108,7 +108,7 @@ describe('HttpController', function() {
       return this.HttpController.getDiff(this.req, this.res, this.next)
     })
 
-    it('should get the diff', function() {
+    it('should get the diff', function () {
       return this.DiffManager.getDiff
         .calledWith(
           this.project_id,
@@ -119,13 +119,13 @@ describe('HttpController', function() {
         .should.equal(true)
     })
 
-    return it('should return the diff', function() {
+    return it('should return the diff', function () {
       return this.res.json.calledWith({ diff: this.diff }).should.equal(true)
     })
   })
 
-  describe('getUpdates', function() {
-    beforeEach(function() {
+  describe('getUpdates', function () {
+    beforeEach(function () {
       this.before = Date.now()
       this.nextBeforeTimestamp = this.before - 100
       this.min_count = 10
@@ -146,7 +146,7 @@ describe('HttpController', function() {
       return this.HttpController.getUpdates(this.req, this.res, this.next)
     })
 
-    it('should get the updates', function() {
+    it('should get the updates', function () {
       return this.UpdatesManager.getSummarizedProjectUpdates
         .calledWith(this.project_id, {
           before: this.before,
@@ -155,7 +155,7 @@ describe('HttpController', function() {
         .should.equal(true)
     })
 
-    return it('should return the formatted updates', function() {
+    return it('should return the formatted updates', function () {
       return this.res.json
         .calledWith({
           updates: this.updates,
@@ -165,8 +165,8 @@ describe('HttpController', function() {
     })
   })
 
-  return describe('RestoreManager', function() {
-    beforeEach(function() {
+  return describe('RestoreManager', function () {
+    beforeEach(function () {
       this.version = '42'
       this.req = {
         params: {
@@ -184,7 +184,7 @@ describe('HttpController', function() {
       return this.HttpController.restore(this.req, this.res, this.next)
     })
 
-    it('should restore the document', function() {
+    it('should restore the document', function () {
       return this.RestoreManager.restoreToBeforeVersion
         .calledWith(
           this.project_id,
@@ -195,7 +195,7 @@ describe('HttpController', function() {
         .should.equal(true)
     })
 
-    return it('should return a success code', function() {
+    return it('should return a success code', function () {
       return this.res.sendStatus.calledWith(204).should.equal(true)
     })
   })

+ 61 - 61
services/track-changes/test/unit/js/LockManager/LockManagerTests.js

@@ -22,8 +22,8 @@ const { expect } = chai
 const modulePath = '../../../../app/js/LockManager.js'
 const SandboxedModule = require('sandboxed-module')
 
-describe('LockManager', function() {
-  beforeEach(function() {
+describe('LockManager', function () {
+  beforeEach(function () {
     this.Settings = {
       redis: {
         lock: {}
@@ -45,37 +45,37 @@ describe('LockManager', function() {
     return (this.callback = sinon.stub())
   })
 
-  describe('checkLock', function() {
-    describe('when the lock is taken', function() {
-      beforeEach(function() {
+  describe('checkLock', function () {
+    describe('when the lock is taken', function () {
+      beforeEach(function () {
         this.rclient.exists = sinon.stub().callsArgWith(1, null, '1')
         return this.LockManager.checkLock(this.key, this.callback)
       })
 
-      it('should check the lock in redis', function() {
+      it('should check the lock in redis', function () {
         return this.rclient.exists.calledWith(this.key).should.equal(true)
       })
 
-      return it('should return the callback with false', function() {
+      return it('should return the callback with false', function () {
         return this.callback.calledWith(null, false).should.equal(true)
       })
     })
 
-    return describe('when the lock is free', function() {
-      beforeEach(function() {
+    return describe('when the lock is free', function () {
+      beforeEach(function () {
         this.rclient.exists = sinon.stub().callsArgWith(1, null, '0')
         return this.LockManager.checkLock(this.key, this.callback)
       })
 
-      return it('should return the callback with true', function() {
+      return it('should return the callback with true', function () {
         return this.callback.calledWith(null, true).should.equal(true)
       })
     })
   })
 
-  describe('tryLock', function() {
-    describe('when the lock is taken', function() {
-      beforeEach(function() {
+  describe('tryLock', function () {
+    describe('when the lock is taken', function () {
+      beforeEach(function () {
         this.rclient.set = sinon.stub().callsArgWith(5, null, null)
         this.LockManager.randomLock = sinon
           .stub()
@@ -83,7 +83,7 @@ describe('LockManager', function() {
         return this.LockManager.tryLock(this.key, this.callback)
       })
 
-      it('should check the lock in redis', function() {
+      it('should check the lock in redis', function () {
         return this.rclient.set
           .calledWith(
             this.key,
@@ -95,43 +95,43 @@ describe('LockManager', function() {
           .should.equal(true)
       })
 
-      return it('should return the callback with false', function() {
+      return it('should return the callback with false', function () {
         return this.callback.calledWith(null, false).should.equal(true)
       })
     })
 
-    return describe('when the lock is free', function() {
-      beforeEach(function() {
+    return describe('when the lock is free', function () {
+      beforeEach(function () {
         this.rclient.set = sinon.stub().callsArgWith(5, null, 'OK')
         return this.LockManager.tryLock(this.key, this.callback)
       })
 
-      return it('should return the callback with true', function() {
+      return it('should return the callback with true', function () {
         return this.callback.calledWith(null, true).should.equal(true)
       })
     })
   })
 
-  describe('deleteLock', function() {
-    return beforeEach(function() {
-      beforeEach(function() {
+  describe('deleteLock', function () {
+    return beforeEach(function () {
+      beforeEach(function () {
         this.rclient.del = sinon.stub().callsArg(1)
         return this.LockManager.deleteLock(this.key, this.callback)
       })
 
-      it('should delete the lock in redis', function() {
+      it('should delete the lock in redis', function () {
         return this.rclient.del.calledWith(key).should.equal(true)
       })
 
-      return it('should call the callback', function() {
+      return it('should call the callback', function () {
         return this.callback.called.should.equal(true)
       })
     })
   })
 
-  describe('getLock', function() {
-    describe('when the lock is not taken', function() {
-      beforeEach(function(done) {
+  describe('getLock', function () {
+    describe('when the lock is not taken', function () {
+      beforeEach(function (done) {
         this.LockManager.tryLock = sinon.stub().callsArgWith(1, null, true)
         return this.LockManager.getLock(this.key, (...args) => {
           this.callback(...Array.from(args || []))
@@ -139,26 +139,26 @@ describe('LockManager', function() {
         })
       })
 
-      it('should try to get the lock', function() {
+      it('should try to get the lock', function () {
         return this.LockManager.tryLock.calledWith(this.key).should.equal(true)
       })
 
-      it('should only need to try once', function() {
+      it('should only need to try once', function () {
         return this.LockManager.tryLock.callCount.should.equal(1)
       })
 
-      return it('should return the callback', function() {
+      return it('should return the callback', function () {
         return this.callback.calledWith(null).should.equal(true)
       })
     })
 
-    describe('when the lock is initially set', function() {
-      beforeEach(function(done) {
+    describe('when the lock is initially set', function () {
+      beforeEach(function (done) {
         const startTime = Date.now()
         this.LockManager.LOCK_TEST_INTERVAL = 5
-        this.LockManager.tryLock = function(doc_id, callback) {
+        this.LockManager.tryLock = function (doc_id, callback) {
           if (callback == null) {
-            callback = function(error, isFree) {}
+            callback = function (error, isFree) {}
           }
           if (Date.now() - startTime < 100) {
             return callback(null, false)
@@ -174,17 +174,17 @@ describe('LockManager', function() {
         })
       })
 
-      it('should call tryLock multiple times until free', function() {
+      it('should call tryLock multiple times until free', function () {
         return (this.LockManager.tryLock.callCount > 1).should.equal(true)
       })
 
-      return it('should return the callback', function() {
+      return it('should return the callback', function () {
         return this.callback.calledWith(null).should.equal(true)
       })
     })
 
-    return describe('when the lock times out', function() {
-      beforeEach(function(done) {
+    return describe('when the lock times out', function () {
+      beforeEach(function (done) {
         const time = Date.now()
         this.LockManager.MAX_LOCK_WAIT_TIME = 5
         this.LockManager.tryLock = sinon.stub().callsArgWith(1, null, false)
@@ -194,7 +194,7 @@ describe('LockManager', function() {
         })
       })
 
-      return it('should return the callback with an error', function() {
+      return it('should return the callback with an error', function () {
         return this.callback
           .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
@@ -202,12 +202,12 @@ describe('LockManager', function() {
     })
   })
 
-  return describe('runWithLock', function() {
-    describe('with successful run', function() {
-      beforeEach(function() {
-        this.runner = function(releaseLock) {
+  return describe('runWithLock', function () {
+    describe('with successful run', function () {
+      beforeEach(function () {
+        this.runner = function (releaseLock) {
           if (releaseLock == null) {
-            releaseLock = function(error) {}
+            releaseLock = function (error) {}
           }
           return releaseLock()
         }
@@ -221,31 +221,31 @@ describe('LockManager', function() {
         )
       })
 
-      it('should get the lock', function() {
+      it('should get the lock', function () {
         return this.LockManager.getLock.calledWith(this.key).should.equal(true)
       })
 
-      it('should run the passed function', function() {
+      it('should run the passed function', function () {
         return this.runner.called.should.equal(true)
       })
 
-      it('should release the lock', function() {
+      it('should release the lock', function () {
         return this.LockManager.releaseLock
           .calledWith(this.key)
           .should.equal(true)
       })
 
-      return it('should call the callback', function() {
+      return it('should call the callback', function () {
         return this.callback.called.should.equal(true)
       })
     })
 
-    describe('when the runner function returns an error', function() {
-      beforeEach(function() {
+    describe('when the runner function returns an error', function () {
+      beforeEach(function () {
         this.error = new Error('oops')
-        this.runner = releaseLock => {
+        this.runner = (releaseLock) => {
           if (releaseLock == null) {
-            releaseLock = function(error) {}
+            releaseLock = function (error) {}
           }
           return releaseLock(this.error)
         }
@@ -259,20 +259,20 @@ describe('LockManager', function() {
         )
       })
 
-      it('should release the lock', function() {
+      it('should release the lock', function () {
         return this.LockManager.releaseLock
           .calledWith(this.key)
           .should.equal(true)
       })
 
-      return it('should call the callback with the error', function() {
+      return it('should call the callback with the error', function () {
         return this.callback.calledWith(this.error).should.equal(true)
       })
     })
 
-    return describe('releaseLock', function() {
-      describe('when the lock is current', function() {
-        beforeEach(function() {
+    return describe('releaseLock', function () {
+      describe('when the lock is current', function () {
+        beforeEach(function () {
           this.rclient.eval = sinon.stub().yields(null, 1)
           return this.LockManager.releaseLock(
             this.key,
@@ -281,7 +281,7 @@ describe('LockManager', function() {
           )
         })
 
-        it('should clear the data from redis', function() {
+        it('should clear the data from redis', function () {
           return this.rclient.eval
             .calledWith(
               this.LockManager.unlockScript,
@@ -292,13 +292,13 @@ describe('LockManager', function() {
             .should.equal(true)
         })
 
-        return it('should call the callback', function() {
+        return it('should call the callback', function () {
           return this.callback.called.should.equal(true)
         })
       })
 
-      return describe('when the lock has expired', function() {
-        beforeEach(function() {
+      return describe('when the lock has expired', function () {
+        beforeEach(function () {
           this.rclient.eval = sinon.stub().yields(null, 0)
           return this.LockManager.releaseLock(
             this.key,
@@ -307,7 +307,7 @@ describe('LockManager', function() {
           )
         })
 
-        return it('should return an error if the lock has expired', function() {
+        return it('should return an error if the lock has expired', function () {
           return this.callback
             .calledWith(
               sinon.match.has('message', 'tried to release timed out lock')

+ 34 - 34
services/track-changes/test/unit/js/MongoManager/MongoManagerTests.js

@@ -19,8 +19,8 @@ const SandboxedModule = require('sandboxed-module')
 const { ObjectId } = require('mongojs')
 const tk = require('timekeeper')
 
-describe('MongoManager', function() {
-  beforeEach(function() {
+describe('MongoManager', function () {
+  beforeEach(function () {
     tk.freeze(new Date())
     this.MongoManager = SandboxedModule.require(modulePath, {
       requires: {
@@ -35,12 +35,12 @@ describe('MongoManager', function() {
     return (this.project_id = ObjectId().toString())
   })
 
-  afterEach(function() {
+  afterEach(function () {
     return tk.reset()
   })
 
-  describe('getLastCompressedUpdate', function() {
-    beforeEach(function() {
+  describe('getLastCompressedUpdate', function () {
+    beforeEach(function () {
       this.update = 'mock-update'
       this.db.docHistory = {}
       this.db.docHistory.find = sinon.stub().returns(this.db.docHistory)
@@ -57,28 +57,28 @@ describe('MongoManager', function() {
       )
     })
 
-    it('should find the updates for the doc', function() {
+    it('should find the updates for the doc', function () {
       return this.db.docHistory.find
         .calledWith({ doc_id: ObjectId(this.doc_id) })
         .should.equal(true)
     })
 
-    it('should limit to one result', function() {
+    it('should limit to one result', function () {
       return this.db.docHistory.limit.calledWith(1).should.equal(true)
     })
 
-    it('should sort in descending version order', function() {
+    it('should sort in descending version order', function () {
       return this.db.docHistory.sort.calledWith({ v: -1 }).should.equal(true)
     })
 
-    return it('should call the call back with the update', function() {
+    return it('should call the call back with the update', function () {
       return this.callback.calledWith(null, this.update).should.equal(true)
     })
   })
 
-  describe('peekLastCompressedUpdate', function() {
-    describe('when there is no last update', function() {
-      beforeEach(function() {
+  describe('peekLastCompressedUpdate', function () {
+    describe('when there is no last update', function () {
+      beforeEach(function () {
         this.PackManager.getLastPackFromIndex = sinon
           .stub()
           .callsArgWith(1, null, null)
@@ -91,19 +91,19 @@ describe('MongoManager', function() {
         )
       })
 
-      it('should get the last update', function() {
+      it('should get the last update', function () {
         return this.MongoManager.getLastCompressedUpdate
           .calledWith(this.doc_id)
           .should.equal(true)
       })
 
-      return it('should call the callback with no update', function() {
+      return it('should call the callback with no update', function () {
         return this.callback.calledWith(null, null).should.equal(true)
       })
     })
 
-    describe('when there is an update', function() {
-      beforeEach(function() {
+    describe('when there is an update', function () {
+      beforeEach(function () {
         this.update = { _id: Object() }
         this.MongoManager.getLastCompressedUpdate = sinon
           .stub()
@@ -114,19 +114,19 @@ describe('MongoManager', function() {
         )
       })
 
-      it('should get the last update', function() {
+      it('should get the last update', function () {
         return this.MongoManager.getLastCompressedUpdate
           .calledWith(this.doc_id)
           .should.equal(true)
       })
 
-      return it('should call the callback with the update', function() {
+      return it('should call the callback with the update', function () {
         return this.callback.calledWith(null, this.update).should.equal(true)
       })
     })
 
-    return describe('when there is a last update in S3', function() {
-      beforeEach(function() {
+    return describe('when there is a last update in S3', function () {
+      beforeEach(function () {
         this.update = { _id: Object(), v: 12345, v_end: 12345, inS3: true }
         this.PackManager.getLastPackFromIndex = sinon
           .stub()
@@ -140,13 +140,13 @@ describe('MongoManager', function() {
         )
       })
 
-      it('should get the last update', function() {
+      it('should get the last update', function () {
         return this.MongoManager.getLastCompressedUpdate
           .calledWith(this.doc_id)
           .should.equal(true)
       })
 
-      return it('should call the callback with a null update and the correct version', function() {
+      return it('should call the callback with a null update and the correct version', function () {
         return this.callback
           .calledWith(null, null, this.update.v_end)
           .should.equal(true)
@@ -154,8 +154,8 @@ describe('MongoManager', function() {
     })
   })
 
-  describe('backportProjectId', function() {
-    beforeEach(function() {
+  describe('backportProjectId', function () {
+    beforeEach(function () {
       this.db.docHistory = { update: sinon.stub().callsArg(3) }
       return this.MongoManager.backportProjectId(
         this.project_id,
@@ -164,7 +164,7 @@ describe('MongoManager', function() {
       )
     })
 
-    it("should insert the project_id into all entries for the doc_id which don't have it set", function() {
+    it("should insert the project_id into all entries for the doc_id which don't have it set", function () {
       return this.db.docHistory.update
         .calledWith(
           {
@@ -181,13 +181,13 @@ describe('MongoManager', function() {
         .should.equal(true)
     })
 
-    return it('should call the callback', function() {
+    return it('should call the callback', function () {
       return this.callback.called.should.equal(true)
     })
   })
 
-  describe('getProjectMetaData', function() {
-    beforeEach(function() {
+  describe('getProjectMetaData', function () {
+    beforeEach(function () {
       this.metadata = { mock: 'metadata' }
       this.db.projectHistoryMetaData = {
         find: sinon.stub().callsArgWith(1, null, [this.metadata])
@@ -198,19 +198,19 @@ describe('MongoManager', function() {
       )
     })
 
-    it('should look up the meta data in the db', function() {
+    it('should look up the meta data in the db', function () {
       return this.db.projectHistoryMetaData.find
         .calledWith({ project_id: ObjectId(this.project_id) })
         .should.equal(true)
     })
 
-    return it('should return the metadata', function() {
+    return it('should return the metadata', function () {
       return this.callback.calledWith(null, this.metadata).should.equal(true)
     })
   })
 
-  return describe('setProjectMetaData', function() {
-    beforeEach(function() {
+  return describe('setProjectMetaData', function () {
+    beforeEach(function () {
       this.metadata = { mock: 'metadata' }
       this.db.projectHistoryMetaData = {
         update: sinon.stub().callsArgWith(3, null, [this.metadata])
@@ -222,7 +222,7 @@ describe('MongoManager', function() {
       )
     })
 
-    it('should upsert the metadata into the DB', function() {
+    it('should upsert the metadata into the DB', function () {
       return this.db.projectHistoryMetaData.update
         .calledWith(
           {
@@ -238,7 +238,7 @@ describe('MongoManager', function() {
         .should.equal(true)
     })
 
-    return it('should call the callback', function() {
+    return it('should call the callback', function () {
       return this.callback.called.should.equal(true)
     })
   })

+ 90 - 90
services/track-changes/test/unit/js/PackManager/PackManagerTests.js

@@ -24,8 +24,8 @@ const _ = require('underscore')
 
 const tk = require('timekeeper')
 
-describe('PackManager', function() {
-  beforeEach(function() {
+describe('PackManager', function () {
+  beforeEach(function () {
     tk.freeze(new Date())
     this.PackManager = SandboxedModule.require(modulePath, {
       requires: {
@@ -46,12 +46,12 @@ describe('PackManager', function() {
     return (this.PackManager.MAX_COUNT = 512)
   })
 
-  afterEach(function() {
+  afterEach(function () {
     return tk.reset()
   })
 
-  describe('insertCompressedUpdates', function() {
-    beforeEach(function() {
+  describe('insertCompressedUpdates', function () {
+    beforeEach(function () {
       this.lastUpdate = {
         _id: '12345',
         pack: [
@@ -72,8 +72,8 @@ describe('PackManager', function() {
       })
     })
 
-    describe('with no last update', function() {
-      beforeEach(function() {
+    describe('with no last update', function () {
+      beforeEach(function () {
         this.PackManager.insertUpdatesIntoNewPack = sinon.stub().callsArg(4)
         return this.PackManager.insertCompressedUpdates(
           this.project_id,
@@ -85,21 +85,21 @@ describe('PackManager', function() {
         )
       })
 
-      describe('for a small update', function() {
-        it('should insert the update into a new pack', function() {
+      describe('for a small update', function () {
+        it('should insert the update into a new pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(this.project_id, this.doc_id, this.newUpdates, true)
             .should.equal(true)
         })
 
-        return it('should call the callback', function() {
+        return it('should call the callback', function () {
           return this.callback.called.should.equal(true)
         })
       })
 
-      return describe('for many small updates', function() {
-        beforeEach(function() {
-          this.newUpdates = __range__(0, 2048, true).map(i => ({
+      return describe('for many small updates', function () {
+        beforeEach(function () {
+          this.newUpdates = __range__(0, 2048, true).map((i) => ({
             op: `op-${i}`,
             meta: `meta-${i}`,
             v: i
@@ -114,7 +114,7 @@ describe('PackManager', function() {
           )
         })
 
-        it('should append the initial updates to the existing pack', function() {
+        it('should append the initial updates to the existing pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(
               this.project_id,
@@ -125,7 +125,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should insert the first set remaining updates as a new pack', function() {
+        it('should insert the first set remaining updates as a new pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(
               this.project_id,
@@ -136,7 +136,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should insert the second set of remaining updates as a new pack', function() {
+        it('should insert the second set of remaining updates as a new pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(
               this.project_id,
@@ -147,7 +147,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should insert the third set of remaining updates as a new pack', function() {
+        it('should insert the third set of remaining updates as a new pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(
               this.project_id,
@@ -158,7 +158,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should insert the final set of remaining updates as a new pack', function() {
+        it('should insert the final set of remaining updates as a new pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(
               this.project_id,
@@ -169,14 +169,14 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        return it('should call the callback', function() {
+        return it('should call the callback', function () {
           return this.callback.called.should.equal(true)
         })
       })
     })
 
-    describe('with an existing pack as the last update', function() {
-      beforeEach(function() {
+    describe('with an existing pack as the last update', function () {
+      beforeEach(function () {
         this.PackManager.appendUpdatesToExistingPack = sinon.stub().callsArg(5)
         this.PackManager.insertUpdatesIntoNewPack = sinon.stub().callsArg(4)
         return this.PackManager.insertCompressedUpdates(
@@ -189,8 +189,8 @@ describe('PackManager', function() {
         )
       })
 
-      describe('for a small update', function() {
-        it('should append the update to the existing pack', function() {
+      describe('for a small update', function () {
+        it('should append the update to the existing pack', function () {
           return this.PackManager.appendUpdatesToExistingPack
             .calledWith(
               this.project_id,
@@ -201,19 +201,19 @@ describe('PackManager', function() {
             )
             .should.equal(true)
         })
-        it('should not insert any new packs', function() {
+        it('should not insert any new packs', function () {
           return this.PackManager.insertUpdatesIntoNewPack.called.should.equal(
             false
           )
         })
-        return it('should call the callback', function() {
+        return it('should call the callback', function () {
           return this.callback.called.should.equal(true)
         })
       })
 
-      describe('for many small updates', function() {
-        beforeEach(function() {
-          this.newUpdates = __range__(0, 2048, true).map(i => ({
+      describe('for many small updates', function () {
+        beforeEach(function () {
+          this.newUpdates = __range__(0, 2048, true).map((i) => ({
             op: `op-${i}`,
             meta: `meta-${i}`,
             v: i
@@ -228,7 +228,7 @@ describe('PackManager', function() {
           )
         })
 
-        it('should append the initial updates to the existing pack', function() {
+        it('should append the initial updates to the existing pack', function () {
           return this.PackManager.appendUpdatesToExistingPack
             .calledWith(
               this.project_id,
@@ -240,7 +240,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should insert the first set remaining updates as a new pack', function() {
+        it('should insert the first set remaining updates as a new pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(
               this.project_id,
@@ -251,7 +251,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should insert the second set of remaining updates as a new pack', function() {
+        it('should insert the second set of remaining updates as a new pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(
               this.project_id,
@@ -262,7 +262,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should insert the third set of remaining updates as a new pack', function() {
+        it('should insert the third set of remaining updates as a new pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(
               this.project_id,
@@ -273,7 +273,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should insert the final set of remaining updates as a new pack', function() {
+        it('should insert the final set of remaining updates as a new pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(
               this.project_id,
@@ -284,21 +284,21 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        return it('should call the callback', function() {
+        return it('should call the callback', function () {
           return this.callback.called.should.equal(true)
         })
       })
 
-      return describe('for many big updates', function() {
-        beforeEach(function() {
+      return describe('for many big updates', function () {
+        beforeEach(function () {
           const longString = __range__(
             0,
             0.75 * this.PackManager.MAX_SIZE,
             true
           )
-            .map(j => 'a')
+            .map((j) => 'a')
             .join('')
-          this.newUpdates = [0, 1, 2, 3, 4].map(i => ({
+          this.newUpdates = [0, 1, 2, 3, 4].map((i) => ({
             op: `op-${i}-${longString}`,
             meta: `meta-${i}`,
             v: i
@@ -313,7 +313,7 @@ describe('PackManager', function() {
           )
         })
 
-        it('should append the initial updates to the existing pack', function() {
+        it('should append the initial updates to the existing pack', function () {
           return this.PackManager.appendUpdatesToExistingPack
             .calledWith(
               this.project_id,
@@ -325,7 +325,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should insert the first set remaining updates as a new pack', function() {
+        it('should insert the first set remaining updates as a new pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(
               this.project_id,
@@ -336,7 +336,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should insert the second set of remaining updates as a new pack', function() {
+        it('should insert the second set of remaining updates as a new pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(
               this.project_id,
@@ -347,7 +347,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should insert the third set of remaining updates as a new pack', function() {
+        it('should insert the third set of remaining updates as a new pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(
               this.project_id,
@@ -358,7 +358,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should insert the final set of remaining updates as a new pack', function() {
+        it('should insert the final set of remaining updates as a new pack', function () {
           return this.PackManager.insertUpdatesIntoNewPack
             .calledWith(
               this.project_id,
@@ -369,15 +369,15 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        return it('should call the callback', function() {
+        return it('should call the callback', function () {
           return this.callback.called.should.equal(true)
         })
       })
     })
 
-    describe('flushCompressedUpdates', function() {
-      return describe('when there is no previous update', function() {
-        beforeEach(function() {
+    describe('flushCompressedUpdates', function () {
+      return describe('when there is no previous update', function () {
+        beforeEach(function () {
           return this.PackManager.flushCompressedUpdates(
             this.project_id,
             this.doc_id,
@@ -388,8 +388,8 @@ describe('PackManager', function() {
           )
         })
 
-        return describe('for a small update  that will expire', function() {
-          it('should insert the update into mongo', function() {
+        return describe('for a small update  that will expire', function () {
+          it('should insert the update into mongo', function () {
             return this.db.docHistory.save
               .calledWithMatch({
                 pack: this.newUpdates,
@@ -402,7 +402,7 @@ describe('PackManager', function() {
               .should.equal(true)
           })
 
-          it('should set an expiry time in the future', function() {
+          it('should set an expiry time in the future', function () {
             return this.db.docHistory.save
               .calledWithMatch({
                 expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000)
@@ -410,15 +410,15 @@ describe('PackManager', function() {
               .should.equal(true)
           })
 
-          return it('should call the callback', function() {
+          return it('should call the callback', function () {
             return this.callback.called.should.equal(true)
           })
         })
       })
     })
 
-    describe('when there is a recent previous update in mongo that expires', function() {
-      beforeEach(function() {
+    describe('when there is a recent previous update in mongo that expires', function () {
+      beforeEach(function () {
         this.lastUpdate = {
           _id: '12345',
           pack: [
@@ -441,8 +441,8 @@ describe('PackManager', function() {
         )
       })
 
-      return describe('for a small update that will expire', function() {
-        it('should append the update in mongo', function() {
+      return describe('for a small update that will expire', function () {
+        it('should append the update in mongo', function () {
           return this.db.docHistory.findAndModify
             .calledWithMatch({
               query: { _id: this.lastUpdate._id },
@@ -454,7 +454,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should set an expiry time in the future', function() {
+        it('should set an expiry time in the future', function () {
           return this.db.docHistory.findAndModify
             .calledWithMatch({
               update: {
@@ -464,14 +464,14 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        return it('should call the callback', function() {
+        return it('should call the callback', function () {
           return this.callback.called.should.equal(true)
         })
       })
     })
 
-    describe('when there is a recent previous update in mongo that expires', function() {
-      beforeEach(function() {
+    describe('when there is a recent previous update in mongo that expires', function () {
+      beforeEach(function () {
         this.PackManager.updateIndex = sinon.stub().callsArg(2)
 
         this.lastUpdate = {
@@ -496,8 +496,8 @@ describe('PackManager', function() {
         )
       })
 
-      return describe('for a small update that will not expire', function() {
-        it('should insert the update into mongo', function() {
+      return describe('for a small update that will not expire', function () {
+        it('should insert the update into mongo', function () {
           return this.db.docHistory.save
             .calledWithMatch({
               pack: this.newUpdates,
@@ -510,20 +510,20 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should not set any expiry time', function() {
+        it('should not set any expiry time', function () {
           return this.db.docHistory.save
             .neverCalledWithMatch(sinon.match.has('expiresAt'))
             .should.equal(true)
         })
 
-        return it('should call the callback', function() {
+        return it('should call the callback', function () {
           return this.callback.called.should.equal(true)
         })
       })
     })
 
-    return describe('when there is an old previous update in mongo', function() {
-      beforeEach(function() {
+    return describe('when there is an old previous update in mongo', function () {
+      beforeEach(function () {
         this.lastUpdate = {
           _id: '12345',
           pack: [
@@ -546,8 +546,8 @@ describe('PackManager', function() {
         )
       })
 
-      return describe('for a small update that will expire', function() {
-        it('should insert the update into mongo', function() {
+      return describe('for a small update that will expire', function () {
+        it('should insert the update into mongo', function () {
           return this.db.docHistory.save
             .calledWithMatch({
               pack: this.newUpdates,
@@ -560,7 +560,7 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        it('should set an expiry time in the future', function() {
+        it('should set an expiry time in the future', function () {
           return this.db.docHistory.save
             .calledWithMatch({
               expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000)
@@ -568,28 +568,28 @@ describe('PackManager', function() {
             .should.equal(true)
         })
 
-        return it('should call the callback', function() {
+        return it('should call the callback', function () {
           return this.callback.called.should.equal(true)
         })
       })
     })
   })
 
-  describe('getOpsByVersionRange', function() {})
+  describe('getOpsByVersionRange', function () {})
 
-  describe('loadPacksByVersionRange', function() {})
+  describe('loadPacksByVersionRange', function () {})
 
-  describe('fetchPacksIfNeeded', function() {})
+  describe('fetchPacksIfNeeded', function () {})
 
-  describe('makeProjectIterator', function() {})
+  describe('makeProjectIterator', function () {})
 
-  describe('getPackById', function() {})
+  describe('getPackById', function () {})
 
-  describe('increaseTTL', function() {})
+  describe('increaseTTL', function () {})
 
-  describe('getIndex', function() {})
+  describe('getIndex', function () {})
 
-  describe('getPackFromIndex', function() {})
+  describe('getPackFromIndex', function () {})
   // getLastPackFromIndex:
   // getIndexWithKeys
   // initialiseIndex
@@ -604,9 +604,9 @@ describe('PackManager', function() {
   // 	updateIndexIfNeeded
   // 	findUnarchivedPacks
 
-  return describe('checkArchiveNotInProgress', function() {
-    describe('when an archive is in progress', function() {
-      beforeEach(function() {
+  return describe('checkArchiveNotInProgress', function () {
+    describe('when an archive is in progress', function () {
+      beforeEach(function () {
         this.db.docHistoryIndex = {
           findOne: sinon.stub().callsArgWith(2, null, { inS3: false })
         }
@@ -617,18 +617,18 @@ describe('PackManager', function() {
           this.callback
         )
       })
-      it('should call the callback', function() {
+      it('should call the callback', function () {
         return this.callback.called.should.equal(true)
       })
-      return it('should return an error', function() {
+      return it('should return an error', function () {
         return this.callback
           .calledWith(sinon.match.has('message'))
           .should.equal(true)
       })
     })
 
-    describe('when an archive is completed', function() {
-      beforeEach(function() {
+    describe('when an archive is completed', function () {
+      beforeEach(function () {
         this.db.docHistoryIndex = {
           findOne: sinon.stub().callsArgWith(2, null, { inS3: true })
         }
@@ -639,18 +639,18 @@ describe('PackManager', function() {
           this.callback
         )
       })
-      it('should call the callback', function() {
+      it('should call the callback', function () {
         return this.callback.called.should.equal(true)
       })
-      return it('should return an error', function() {
+      return it('should return an error', function () {
         return this.callback
           .calledWith(sinon.match.has('message'))
           .should.equal(true)
       })
     })
 
-    return describe('when the archive has not started or completed', function() {
-      beforeEach(function() {
+    return describe('when the archive has not started or completed', function () {
+      beforeEach(function () {
         this.db.docHistoryIndex = {
           findOne: sinon.stub().callsArgWith(2, null, {})
         }
@@ -661,10 +661,10 @@ describe('PackManager', function() {
           this.callback
         )
       })
-      it('should call the callback with no error', function() {
+      it('should call the callback with no error', function () {
         return this.callback.called.should.equal(true)
       })
-      return it('should return with no error', function() {
+      return it('should return with no error', function () {
         return (typeof this.callback.lastCall.args[0]).should.equal('undefined')
       })
     })

+ 20 - 20
services/track-changes/test/unit/js/RedisManager/RedisManagerTests.js

@@ -18,8 +18,8 @@ const { expect } = chai
 const modulePath = '../../../../app/js/RedisManager.js'
 const SandboxedModule = require('sandboxed-module')
 
-describe('RedisManager', function() {
-  beforeEach(function() {
+describe('RedisManager', function () {
+  beforeEach(function () {
     this.RedisManager = SandboxedModule.require(modulePath, {
       requires: {
         'redis-sharelatex': {
@@ -52,13 +52,13 @@ describe('RedisManager', function() {
     return (this.callback = sinon.stub())
   })
 
-  describe('getOldestDocUpdates', function() {
-    beforeEach(function() {
+  describe('getOldestDocUpdates', function () {
+    beforeEach(function () {
       this.rawUpdates = [
         { v: 42, op: 'mock-op-42' },
         { v: 45, op: 'mock-op-45' }
       ]
-      this.jsonUpdates = Array.from(this.rawUpdates).map(update =>
+      this.jsonUpdates = Array.from(this.rawUpdates).map((update) =>
         JSON.stringify(update)
       )
       this.rclient.lrange = sinon.stub().callsArgWith(3, null, this.jsonUpdates)
@@ -69,7 +69,7 @@ describe('RedisManager', function() {
       )
     })
 
-    it('should read the updates from redis', function() {
+    it('should read the updates from redis', function () {
       return this.rclient.lrange
         .calledWith(
           `UncompressedHistoryOps:${this.doc_id}`,
@@ -79,27 +79,27 @@ describe('RedisManager', function() {
         .should.equal(true)
     })
 
-    it('should call the callback with the unparsed ops', function() {
+    it('should call the callback with the unparsed ops', function () {
       return this.callback.calledWith(null, this.jsonUpdates).should.equal(true)
     })
 
-    describe('expandDocUpdates', function() {
-      beforeEach(function() {
+    describe('expandDocUpdates', function () {
+      beforeEach(function () {
         return this.RedisManager.expandDocUpdates(
           this.jsonUpdates,
           this.callback
         )
       })
 
-      return it('should call the callback with the parsed ops', function() {
+      return it('should call the callback with the parsed ops', function () {
         return this.callback
           .calledWith(null, this.rawUpdates)
           .should.equal(true)
       })
     })
 
-    return describe('deleteAppliedDocUpdates', function() {
-      beforeEach(function() {
+    return describe('deleteAppliedDocUpdates', function () {
+      beforeEach(function () {
         this.rclient.lrem = sinon.stub()
         this.rclient.srem = sinon.stub()
         this.rclient.exec = sinon.stub().callsArgWith(0)
@@ -111,7 +111,7 @@ describe('RedisManager', function() {
         )
       })
 
-      it('should delete the first update from redis', function() {
+      it('should delete the first update from redis', function () {
         return this.rclient.lrem
           .calledWith(
             `UncompressedHistoryOps:${this.doc_id}`,
@@ -121,7 +121,7 @@ describe('RedisManager', function() {
           .should.equal(true)
       })
 
-      it('should delete the second update from redis', function() {
+      it('should delete the second update from redis', function () {
         return this.rclient.lrem
           .calledWith(
             `UncompressedHistoryOps:${this.doc_id}`,
@@ -131,20 +131,20 @@ describe('RedisManager', function() {
           .should.equal(true)
       })
 
-      it('should delete the doc from the set of docs with history ops', function() {
+      it('should delete the doc from the set of docs with history ops', function () {
         return this.rclient.srem
           .calledWith(`DocsWithHistoryOps:${this.project_id}`, this.doc_id)
           .should.equal(true)
       })
 
-      return it('should call the callback ', function() {
+      return it('should call the callback ', function () {
         return this.callback.called.should.equal(true)
       })
     })
   })
 
-  return describe('getDocIdsWithHistoryOps', function() {
-    beforeEach(function() {
+  return describe('getDocIdsWithHistoryOps', function () {
+    beforeEach(function () {
       this.doc_ids = ['mock-id-1', 'mock-id-2']
       this.rclient.smembers = sinon.stub().callsArgWith(1, null, this.doc_ids)
       return this.RedisManager.getDocIdsWithHistoryOps(
@@ -153,13 +153,13 @@ describe('RedisManager', function() {
       )
     })
 
-    it('should read the doc_ids from redis', function() {
+    it('should read the doc_ids from redis', function () {
       return this.rclient.smembers
         .calledWith(`DocsWithHistoryOps:${this.project_id}`)
         .should.equal(true)
     })
 
-    return it('should call the callback with the doc_ids', function() {
+    return it('should call the callback with the doc_ids', function () {
       return this.callback.calledWith(null, this.doc_ids).should.equal(true)
     })
   })

+ 7 - 7
services/track-changes/test/unit/js/RestoreManager/RestoreManagerTests.js

@@ -16,8 +16,8 @@ const { expect } = chai
 const modulePath = '../../../../app/js/RestoreManager.js'
 const SandboxedModule = require('sandboxed-module')
 
-describe('RestoreManager', function() {
-  beforeEach(function() {
+describe('RestoreManager', function () {
+  beforeEach(function () {
     this.RestoreManager = SandboxedModule.require(modulePath, {
       requires: {
         'logger-sharelatex': (this.logger = {
@@ -35,8 +35,8 @@ describe('RestoreManager', function() {
     return (this.version = 42)
   })
 
-  return describe('restoreToBeforeVersion', function() {
-    beforeEach(function() {
+  return describe('restoreToBeforeVersion', function () {
+    beforeEach(function () {
       this.content = 'mock content'
       this.DocumentUpdaterManager.setDocument = sinon.stub().callsArg(4)
       this.DiffManager.getDocumentBeforeVersion = sinon
@@ -51,19 +51,19 @@ describe('RestoreManager', function() {
       )
     })
 
-    it('should get the content before the requested version', function() {
+    it('should get the content before the requested version', function () {
       return this.DiffManager.getDocumentBeforeVersion
         .calledWith(this.project_id, this.doc_id, this.version)
         .should.equal(true)
     })
 
-    it('should set the document in the document updater', function() {
+    it('should set the document in the document updater', function () {
       return this.DocumentUpdaterManager.setDocument
         .calledWith(this.project_id, this.doc_id, this.content, this.user_id)
         .should.equal(true)
     })
 
-    return it('should call the callback', function() {
+    return it('should call the callback', function () {
       return this.callback.called.should.equal(true)
     })
   })

+ 39 - 39
services/track-changes/test/unit/js/UpdateCompressor/UpdateCompressorTests.js

@@ -17,14 +17,14 @@ const modulePath = '../../../../app/js/UpdateCompressor.js'
 const SandboxedModule = require('sandboxed-module')
 
 const bigstring = __range__(0, 2 * 1024 * 1024, true)
-  .map(i => 'a')
+  .map((i) => 'a')
   .join('')
 const mediumstring = __range__(0, 1024 * 1024, true)
-  .map(j => 'a')
+  .map((j) => 'a')
   .join('')
 
-describe('UpdateCompressor', function() {
-  beforeEach(function() {
+describe('UpdateCompressor', function () {
+  beforeEach(function () {
     this.UpdateCompressor = SandboxedModule.require(modulePath, {
       requires: {
         '../lib/diff_match_patch': require('../../../../app/lib/diff_match_patch')
@@ -36,8 +36,8 @@ describe('UpdateCompressor', function() {
     return (this.ts2 = Date.now() + 1000)
   })
 
-  describe('convertToSingleOpUpdates', function() {
-    it('should split grouped updates into individual updates', function() {
+  describe('convertToSingleOpUpdates', function () {
+    it('should split grouped updates into individual updates', function () {
       return expect(
         this.UpdateCompressor.convertToSingleOpUpdates([
           {
@@ -77,7 +77,7 @@ describe('UpdateCompressor', function() {
       ])
     })
 
-    it('should return no-op updates when the op list is empty', function() {
+    it('should return no-op updates when the op list is empty', function () {
       return expect(
         this.UpdateCompressor.convertToSingleOpUpdates([
           {
@@ -95,7 +95,7 @@ describe('UpdateCompressor', function() {
       ])
     })
 
-    return it('should ignore comment ops', function() {
+    return it('should ignore comment ops', function () {
       return expect(
         this.UpdateCompressor.convertToSingleOpUpdates([
           {
@@ -123,8 +123,8 @@ describe('UpdateCompressor', function() {
     })
   })
 
-  describe('concatUpdatesWithSameVersion', function() {
-    it('should concat updates with the same version', function() {
+  describe('concatUpdatesWithSameVersion', function () {
+    it('should concat updates with the same version', function () {
       return expect(
         this.UpdateCompressor.concatUpdatesWithSameVersion([
           {
@@ -173,7 +173,7 @@ describe('UpdateCompressor', function() {
       ])
     })
 
-    return it('should turn a noop into an empty op', function() {
+    return it('should turn a noop into an empty op', function () {
       return expect(
         this.UpdateCompressor.concatUpdatesWithSameVersion([
           {
@@ -196,9 +196,9 @@ describe('UpdateCompressor', function() {
     })
   })
 
-  describe('compress', function() {
-    describe('insert - insert', function() {
-      it('should append one insert to the other', function() {
+  describe('compress', function () {
+    describe('insert - insert', function () {
+      it('should append one insert to the other', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -225,7 +225,7 @@ describe('UpdateCompressor', function() {
         ])
       })
 
-      it('should insert one insert inside the other', function() {
+      it('should insert one insert inside the other', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -252,7 +252,7 @@ describe('UpdateCompressor', function() {
         ])
       })
 
-      it('should not append separated inserts', function() {
+      it('should not append separated inserts', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -288,7 +288,7 @@ describe('UpdateCompressor', function() {
         ])
       })
 
-      it('should not append inserts that are too big (second op)', function() {
+      it('should not append inserts that are too big (second op)', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -324,7 +324,7 @@ describe('UpdateCompressor', function() {
         ])
       })
 
-      it('should not append inserts that are too big (first op)', function() {
+      it('should not append inserts that are too big (first op)', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -360,7 +360,7 @@ describe('UpdateCompressor', function() {
         ])
       })
 
-      return it('should not append inserts that are too big (first and second op)', function() {
+      return it('should not append inserts that are too big (first and second op)', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -397,8 +397,8 @@ describe('UpdateCompressor', function() {
       })
     })
 
-    describe('delete - delete', function() {
-      it('should append one delete to the other', function() {
+    describe('delete - delete', function () {
+      it('should append one delete to the other', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -425,7 +425,7 @@ describe('UpdateCompressor', function() {
         ])
       })
 
-      it('should insert one delete inside the other', function() {
+      it('should insert one delete inside the other', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -452,7 +452,7 @@ describe('UpdateCompressor', function() {
         ])
       })
 
-      return it('should not append separated deletes', function() {
+      return it('should not append separated deletes', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -489,8 +489,8 @@ describe('UpdateCompressor', function() {
       })
     })
 
-    describe('insert - delete', function() {
-      it('should undo a previous insert', function() {
+    describe('insert - delete', function () {
+      it('should undo a previous insert', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -517,7 +517,7 @@ describe('UpdateCompressor', function() {
         ])
       })
 
-      it('should remove part of an insert from the middle', function() {
+      it('should remove part of an insert from the middle', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -544,7 +544,7 @@ describe('UpdateCompressor', function() {
         ])
       })
 
-      it('should cancel out two opposite updates', function() {
+      it('should cancel out two opposite updates', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -571,7 +571,7 @@ describe('UpdateCompressor', function() {
         ])
       })
 
-      it('should not combine separated updates', function() {
+      it('should not combine separated updates', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -607,7 +607,7 @@ describe('UpdateCompressor', function() {
         ])
       })
 
-      return it('should not combine updates with overlap beyond the end', function() {
+      return it('should not combine updates with overlap beyond the end', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -644,8 +644,8 @@ describe('UpdateCompressor', function() {
       })
     })
 
-    describe('delete - insert', function() {
-      it('should do a diff of the content', function() {
+    describe('delete - insert', function () {
+      it('should do a diff of the content', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -681,7 +681,7 @@ describe('UpdateCompressor', function() {
         ])
       })
 
-      return it('should return a no-op if the delete and insert are the same', function() {
+      return it('should return a no-op if the delete and insert are the same', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -709,8 +709,8 @@ describe('UpdateCompressor', function() {
       })
     })
 
-    describe('noop - insert', function() {
-      return it('should leave them untouched', function() {
+    describe('noop - insert', function () {
+      return it('should leave them untouched', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -747,8 +747,8 @@ describe('UpdateCompressor', function() {
       })
     })
 
-    return describe('noop - delete', function() {
-      return it('should leave them untouched', function() {
+    return describe('noop - delete', function () {
+      return it('should leave them untouched', function () {
         return expect(
           this.UpdateCompressor.compressUpdates([
             {
@@ -786,9 +786,9 @@ describe('UpdateCompressor', function() {
     })
   })
 
-  return describe('compressRawUpdates', function() {
-    return describe('merging in-place with an array op', function() {
-      return it('should not change the existing last updates', function() {
+  return describe('compressRawUpdates', function () {
+    return describe('merging in-place with an array op', function () {
+      return it('should not change the existing last updates', function () {
         return expect(
           this.UpdateCompressor.compressRawUpdates(
             {

+ 32 - 32
services/track-changes/test/unit/js/UpdateTrimmer/UpdateTrimmerTests.js

@@ -17,8 +17,8 @@ const modulePath = '../../../../app/js/UpdateTrimmer.js'
 const SandboxedModule = require('sandboxed-module')
 const tk = require('timekeeper')
 
-describe('UpdateTrimmer', function() {
-  beforeEach(function() {
+describe('UpdateTrimmer', function () {
+  beforeEach(function () {
     this.now = new Date()
     tk.freeze(this.now)
 
@@ -37,12 +37,12 @@ describe('UpdateTrimmer', function() {
     return (this.project_id = 'mock-project-id')
   })
 
-  afterEach(function() {
+  afterEach(function () {
     return tk.reset()
   })
 
-  return describe('shouldTrimUpdates', function() {
-    beforeEach(function() {
+  return describe('shouldTrimUpdates', function () {
+    beforeEach(function () {
       this.metadata = {}
       this.details = { features: {} }
       this.MongoManager.getProjectMetaData = sinon
@@ -55,8 +55,8 @@ describe('UpdateTrimmer', function() {
         .callsArgWith(1, null, this.details))
     })
 
-    describe('with preserveHistory set in the project meta data', function() {
-      beforeEach(function() {
+    describe('with preserveHistory set in the project meta data', function () {
+      beforeEach(function () {
         this.metadata.preserveHistory = true
         return this.UpdateTrimmer.shouldTrimUpdates(
           this.project_id,
@@ -64,28 +64,28 @@ describe('UpdateTrimmer', function() {
         )
       })
 
-      it('should look up the meta data', function() {
+      it('should look up the meta data', function () {
         return this.MongoManager.getProjectMetaData
           .calledWith(this.project_id)
           .should.equal(true)
       })
 
-      it('should not look up the project details', function() {
+      it('should not look up the project details', function () {
         return this.WebApiManager.getProjectDetails.called.should.equal(false)
       })
 
-      return it('should return false', function() {
+      return it('should return false', function () {
         return this.callback.calledWith(null, false).should.equal(true)
       })
     })
 
-    describe('without preserveHistory set in the project meta data', function() {
-      beforeEach(function() {
+    describe('without preserveHistory set in the project meta data', function () {
+      beforeEach(function () {
         return (this.metadata.preserveHistory = false)
       })
 
-      describe('when the project has the versioning feature', function() {
-        beforeEach(function() {
+      describe('when the project has the versioning feature', function () {
+        beforeEach(function () {
           this.details.features.versioning = true
           return this.UpdateTrimmer.shouldTrimUpdates(
             this.project_id,
@@ -93,37 +93,37 @@ describe('UpdateTrimmer', function() {
           )
         })
 
-        it('should look up the meta data', function() {
+        it('should look up the meta data', function () {
           return this.MongoManager.getProjectMetaData
             .calledWith(this.project_id)
             .should.equal(true)
         })
 
-        it('should look up the project details', function() {
+        it('should look up the project details', function () {
           return this.WebApiManager.getProjectDetails
             .calledWith(this.project_id)
             .should.equal(true)
         })
 
-        it('should insert preserveHistory into the metadata', function() {
+        it('should insert preserveHistory into the metadata', function () {
           return this.MongoManager.setProjectMetaData
             .calledWith(this.project_id, { preserveHistory: true })
             .should.equal(true)
         })
 
-        it('should upgrade any existing history', function() {
+        it('should upgrade any existing history', function () {
           return this.MongoManager.upgradeHistory
             .calledWith(this.project_id)
             .should.equal(true)
         })
 
-        return it('should return false', function() {
+        return it('should return false', function () {
           return this.callback.calledWith(null, false).should.equal(true)
         })
       })
 
-      return describe('when the project does not have the versioning feature', function() {
-        beforeEach(function() {
+      return describe('when the project does not have the versioning feature', function () {
+        beforeEach(function () {
           this.details.features.versioning = false
           return this.UpdateTrimmer.shouldTrimUpdates(
             this.project_id,
@@ -131,21 +131,21 @@ describe('UpdateTrimmer', function() {
           )
         })
 
-        return it('should return true', function() {
+        return it('should return true', function () {
           return this.callback.calledWith(null, true).should.equal(true)
         })
       })
     })
 
-    return describe('without any meta data', function() {
-      beforeEach(function() {
+    return describe('without any meta data', function () {
+      beforeEach(function () {
         return (this.MongoManager.getProjectMetaData = sinon
           .stub()
           .callsArgWith(1, null, null))
       })
 
-      describe('when the project has the versioning feature', function() {
-        beforeEach(function() {
+      describe('when the project has the versioning feature', function () {
+        beforeEach(function () {
           this.details.features.versioning = true
           return this.UpdateTrimmer.shouldTrimUpdates(
             this.project_id,
@@ -153,25 +153,25 @@ describe('UpdateTrimmer', function() {
           )
         })
 
-        it('should insert preserveHistory into the metadata', function() {
+        it('should insert preserveHistory into the metadata', function () {
           return this.MongoManager.setProjectMetaData
             .calledWith(this.project_id, { preserveHistory: true })
             .should.equal(true)
         })
 
-        it('should upgrade any existing history', function() {
+        it('should upgrade any existing history', function () {
           return this.MongoManager.upgradeHistory
             .calledWith(this.project_id)
             .should.equal(true)
         })
 
-        return it('should return false', function() {
+        return it('should return false', function () {
           return this.callback.calledWith(null, false).should.equal(true)
         })
       })
 
-      return describe('when the project does not have the versioning feature', function() {
-        beforeEach(function() {
+      return describe('when the project does not have the versioning feature', function () {
+        beforeEach(function () {
           this.details.features.versioning = false
           return this.UpdateTrimmer.shouldTrimUpdates(
             this.project_id,
@@ -179,7 +179,7 @@ describe('UpdateTrimmer', function() {
           )
         })
 
-        return it('should return true', function() {
+        return it('should return true', function () {
           return this.callback.calledWith(null, true).should.equal(true)
         })
       })

+ 109 - 109
services/track-changes/test/unit/js/UpdatesManager/UpdatesManagerTests.js

@@ -20,8 +20,8 @@ const { expect } = chai
 const modulePath = '../../../../app/js/UpdatesManager.js'
 const SandboxedModule = require('sandboxed-module')
 
-describe('UpdatesManager', function() {
-  beforeEach(function() {
+describe('UpdatesManager', function () {
+  beforeEach(function () {
     this.UpdatesManager = SandboxedModule.require(modulePath, {
       singleOnly: true,
       requires: {
@@ -53,9 +53,9 @@ describe('UpdatesManager', function() {
     return (this.temporary = 'temp-mock')
   })
 
-  describe('compressAndSaveRawUpdates', function() {
-    describe('when there are no raw ops', function() {
-      beforeEach(function() {
+  describe('compressAndSaveRawUpdates', function () {
+    describe('when there are no raw ops', function () {
+      beforeEach(function () {
         this.MongoManager.peekLastCompressedUpdate = sinon.stub()
         return this.UpdatesManager.compressAndSaveRawUpdates(
           this.project_id,
@@ -66,19 +66,19 @@ describe('UpdatesManager', function() {
         )
       })
 
-      it('should not need to access the database', function() {
+      it('should not need to access the database', function () {
         return this.MongoManager.peekLastCompressedUpdate.called.should.equal(
           false
         )
       })
 
-      return it('should call the callback', function() {
+      return it('should call the callback', function () {
         return this.callback.called.should.equal(true)
       })
     })
 
-    describe('when there is no compressed history to begin with', function() {
-      beforeEach(function() {
+    describe('when there is no compressed history to begin with', function () {
+      beforeEach(function () {
         this.rawUpdates = [
           { v: 12, op: 'mock-op-12' },
           { v: 13, op: 'mock-op-13' }
@@ -101,13 +101,13 @@ describe('UpdatesManager', function() {
         )
       })
 
-      it('should look at the last compressed op', function() {
+      it('should look at the last compressed op', function () {
         return this.MongoManager.peekLastCompressedUpdate
           .calledWith(this.doc_id)
           .should.equal(true)
       })
 
-      it('should save the compressed ops as a pack', function() {
+      it('should save the compressed ops as a pack', function () {
         return this.PackManager.insertCompressedUpdates
           .calledWith(
             this.project_id,
@@ -119,13 +119,13 @@ describe('UpdatesManager', function() {
           .should.equal(true)
       })
 
-      return it('should call the callback', function() {
+      return it('should call the callback', function () {
         return this.callback.called.should.equal(true)
       })
     })
 
-    describe('when the raw ops need appending to existing history', function() {
-      beforeEach(function() {
+    describe('when the raw ops need appending to existing history', function () {
+      beforeEach(function () {
         this.lastCompressedUpdate = { v: 11, op: 'compressed-op-11' }
         this.compressedUpdates = [
           { v: 12, op: 'compressed-op-11+12' },
@@ -146,8 +146,8 @@ describe('UpdatesManager', function() {
           .returns(this.compressedUpdates))
       })
 
-      describe('when the raw ops start where the existing history ends', function() {
-        beforeEach(function() {
+      describe('when the raw ops start where the existing history ends', function () {
+        beforeEach(function () {
           this.rawUpdates = [
             { v: 12, op: 'mock-op-12' },
             { v: 13, op: 'mock-op-13' }
@@ -161,19 +161,19 @@ describe('UpdatesManager', function() {
           )
         })
 
-        it('should look at the last compressed op', function() {
+        it('should look at the last compressed op', function () {
           return this.MongoManager.peekLastCompressedUpdate
             .calledWith(this.doc_id)
             .should.equal(true)
         })
 
-        it('should compress the raw ops', function() {
+        it('should compress the raw ops', function () {
           return this.UpdateCompressor.compressRawUpdates
             .calledWith(null, this.rawUpdates)
             .should.equal(true)
         })
 
-        it('should save the new compressed ops into a pack', function() {
+        it('should save the new compressed ops into a pack', function () {
           return this.PackManager.insertCompressedUpdates
             .calledWith(
               this.project_id,
@@ -185,13 +185,13 @@ describe('UpdatesManager', function() {
             .should.equal(true)
         })
 
-        return it('should call the callback', function() {
+        return it('should call the callback', function () {
           return this.callback.called.should.equal(true)
         })
       })
 
-      describe('when the raw ops start where the existing history ends and the history is in a pack', function() {
-        beforeEach(function() {
+      describe('when the raw ops start where the existing history ends and the history is in a pack', function () {
+        beforeEach(function () {
           this.lastCompressedUpdate = {
             pack: [{ v: 11, op: 'compressed-op-11' }],
             v: 11
@@ -217,19 +217,19 @@ describe('UpdatesManager', function() {
           )
         })
 
-        it('should look at the last compressed op', function() {
+        it('should look at the last compressed op', function () {
           return this.MongoManager.peekLastCompressedUpdate
             .calledWith(this.doc_id)
             .should.equal(true)
         })
 
-        it('should compress the raw ops', function() {
+        it('should compress the raw ops', function () {
           return this.UpdateCompressor.compressRawUpdates
             .calledWith(null, this.rawUpdates)
             .should.equal(true)
         })
 
-        it('should save the new compressed ops into a pack', function() {
+        it('should save the new compressed ops into a pack', function () {
           return this.PackManager.insertCompressedUpdates
             .calledWith(
               this.project_id,
@@ -241,13 +241,13 @@ describe('UpdatesManager', function() {
             .should.equal(true)
         })
 
-        return it('should call the callback', function() {
+        return it('should call the callback', function () {
           return this.callback.called.should.equal(true)
         })
       })
 
-      describe('when some raw ops are passed that have already been compressed', function() {
-        beforeEach(function() {
+      describe('when some raw ops are passed that have already been compressed', function () {
+        beforeEach(function () {
           this.rawUpdates = [
             { v: 10, op: 'mock-op-10' },
             { v: 11, op: 'mock-op-11' },
@@ -264,15 +264,15 @@ describe('UpdatesManager', function() {
           )
         })
 
-        return it('should only compress the more recent raw ops', function() {
+        return it('should only compress the more recent raw ops', function () {
           return this.UpdateCompressor.compressRawUpdates
             .calledWith(null, this.rawUpdates.slice(-2))
             .should.equal(true)
         })
       })
 
-      describe('when the raw ops do not follow from the last compressed op version', function() {
-        beforeEach(function() {
+      describe('when the raw ops do not follow from the last compressed op version', function () {
+        beforeEach(function () {
           this.rawUpdates = [{ v: 13, op: 'mock-op-13' }]
           return this.UpdatesManager.compressAndSaveRawUpdates(
             this.project_id,
@@ -283,7 +283,7 @@ describe('UpdatesManager', function() {
           )
         })
 
-        it('should call the callback with an error', function() {
+        it('should call the callback with an error', function () {
           return this.callback
             .calledWith(
               sinon.match.has(
@@ -294,15 +294,15 @@ describe('UpdatesManager', function() {
             .should.equal(true)
         })
 
-        return it('should not insert any update into mongo', function() {
+        return it('should not insert any update into mongo', function () {
           return this.PackManager.insertCompressedUpdates.called.should.equal(
             false
           )
         })
       })
 
-      return describe('when the raw ops are out of order', function() {
-        beforeEach(function() {
+      return describe('when the raw ops are out of order', function () {
+        beforeEach(function () {
           this.rawUpdates = [
             { v: 13, op: 'mock-op-13' },
             { v: 12, op: 'mock-op-12' }
@@ -316,13 +316,13 @@ describe('UpdatesManager', function() {
           )
         })
 
-        it('should call the callback with an error', function() {
+        it('should call the callback with an error', function () {
           return this.callback
             .calledWith(sinon.match.has('message'))
             .should.equal(true)
         })
 
-        return it('should not insert any update into mongo', function() {
+        return it('should not insert any update into mongo', function () {
           return this.PackManager.insertCompressedUpdates.called.should.equal(
             false
           )
@@ -330,8 +330,8 @@ describe('UpdatesManager', function() {
       })
     })
 
-    return describe('when the raw ops need appending to existing history which is in S3', function() {
-      beforeEach(function() {
+    return describe('when the raw ops need appending to existing history which is in S3', function () {
+      beforeEach(function () {
         this.lastCompressedUpdate = null
         this.lastVersion = 11
         this.compressedUpdates = [{ v: 13, op: 'compressed-op-12' }]
@@ -345,8 +345,8 @@ describe('UpdatesManager', function() {
           .returns(this.compressedUpdates))
       })
 
-      return describe('when the raw ops start where the existing history ends', function() {
-        beforeEach(function() {
+      return describe('when the raw ops start where the existing history ends', function () {
+        beforeEach(function () {
           this.rawUpdates = [
             { v: 12, op: 'mock-op-12' },
             { v: 13, op: 'mock-op-13' }
@@ -360,19 +360,19 @@ describe('UpdatesManager', function() {
           )
         })
 
-        it('should try to look at the last compressed op', function() {
+        it('should try to look at the last compressed op', function () {
           return this.MongoManager.peekLastCompressedUpdate
             .calledWith(this.doc_id)
             .should.equal(true)
         })
 
-        it('should compress the last compressed op and the raw ops', function() {
+        it('should compress the last compressed op and the raw ops', function () {
           return this.UpdateCompressor.compressRawUpdates
             .calledWith(this.lastCompressedUpdate, this.rawUpdates)
             .should.equal(true)
         })
 
-        it('should save the compressed ops', function() {
+        it('should save the compressed ops', function () {
           return this.PackManager.insertCompressedUpdates
             .calledWith(
               this.project_id,
@@ -384,15 +384,15 @@ describe('UpdatesManager', function() {
             .should.equal(true)
         })
 
-        return it('should call the callback', function() {
+        return it('should call the callback', function () {
           return this.callback.called.should.equal(true)
         })
       })
     })
   })
 
-  describe('processUncompressedUpdates', function() {
-    beforeEach(function() {
+  describe('processUncompressedUpdates', function () {
+    beforeEach(function () {
       this.UpdatesManager.compressAndSaveRawUpdates = sinon
         .stub()
         .callsArgWith(4)
@@ -403,8 +403,8 @@ describe('UpdatesManager', function() {
         .callsArgWith(1, null, (this.temporary = 'temp mock')))
     })
 
-    describe('when there is fewer than one batch to send', function() {
-      beforeEach(function() {
+    describe('when there is fewer than one batch to send', function () {
+      beforeEach(function () {
         this.updates = ['mock-update']
         this.RedisManager.getOldestDocUpdates = sinon
           .stub()
@@ -420,13 +420,13 @@ describe('UpdatesManager', function() {
         )
       })
 
-      it('should get the oldest updates', function() {
+      it('should get the oldest updates', function () {
         return this.RedisManager.getOldestDocUpdates
           .calledWith(this.doc_id, this.UpdatesManager.REDIS_READ_BATCH_SIZE)
           .should.equal(true)
       })
 
-      it('should compress and save the updates', function() {
+      it('should compress and save the updates', function () {
         return this.UpdatesManager.compressAndSaveRawUpdates
           .calledWith(
             this.project_id,
@@ -437,19 +437,19 @@ describe('UpdatesManager', function() {
           .should.equal(true)
       })
 
-      it('should delete the batch of uncompressed updates that was just processed', function() {
+      it('should delete the batch of uncompressed updates that was just processed', function () {
         return this.RedisManager.deleteAppliedDocUpdates
           .calledWith(this.project_id, this.doc_id, this.updates)
           .should.equal(true)
       })
 
-      return it('should call the callback', function() {
+      return it('should call the callback', function () {
         return this.callback.called.should.equal(true)
       })
     })
 
-    return describe('when there are multiple batches to send', function() {
-      beforeEach(function(done) {
+    return describe('when there are multiple batches to send', function () {
+      beforeEach(function (done) {
         this.UpdatesManager.REDIS_READ_BATCH_SIZE = 2
         this.updates = [
           'mock-update-0',
@@ -465,7 +465,7 @@ describe('UpdatesManager', function() {
           callback
         ) => {
           if (callback == null) {
-            callback = function(error, updates) {}
+            callback = function (error, updates) {}
           }
           const updates = this.redisArray.slice(0, batchSize)
           this.redisArray = this.redisArray.slice(batchSize)
@@ -487,11 +487,11 @@ describe('UpdatesManager', function() {
         )
       })
 
-      it('should get the oldest updates in three batches ', function() {
+      it('should get the oldest updates in three batches ', function () {
         return this.RedisManager.getOldestDocUpdates.callCount.should.equal(3)
       })
 
-      it('should compress and save the updates in batches', function() {
+      it('should compress and save the updates in batches', function () {
         this.UpdatesManager.compressAndSaveRawUpdates
           .calledWith(
             this.project_id,
@@ -518,20 +518,20 @@ describe('UpdatesManager', function() {
           .should.equal(true)
       })
 
-      it('should delete the batches of uncompressed updates', function() {
+      it('should delete the batches of uncompressed updates', function () {
         return this.RedisManager.deleteAppliedDocUpdates.callCount.should.equal(
           3
         )
       })
 
-      return it('should call the callback', function() {
+      return it('should call the callback', function () {
         return this.callback.called.should.equal(true)
       })
     })
   })
 
-  describe('processCompressedUpdatesWithLock', function() {
-    beforeEach(function() {
+  describe('processCompressedUpdatesWithLock', function () {
+    beforeEach(function () {
       this.UpdateTrimmer.shouldTrimUpdates = sinon
         .stub()
         .callsArgWith(1, null, (this.temporary = 'temp mock'))
@@ -545,31 +545,31 @@ describe('UpdatesManager', function() {
       )
     })
 
-    it('should check if the updates are temporary', function() {
+    it('should check if the updates are temporary', function () {
       return this.UpdateTrimmer.shouldTrimUpdates
         .calledWith(this.project_id)
         .should.equal(true)
     })
 
-    it('should backport the project id', function() {
+    it('should backport the project id', function () {
       return this.MongoManager.backportProjectId
         .calledWith(this.project_id, this.doc_id)
         .should.equal(true)
     })
 
-    it('should run processUncompressedUpdates with the lock', function() {
+    it('should run processUncompressedUpdates with the lock', function () {
       return this.LockManager.runWithLock
         .calledWith(`HistoryLock:${this.doc_id}`)
         .should.equal(true)
     })
 
-    return it('should call the callback', function() {
+    return it('should call the callback', function () {
       return this.callback.called.should.equal(true)
     })
   })
 
-  describe('getDocUpdates', function() {
-    beforeEach(function() {
+  describe('getDocUpdates', function () {
+    beforeEach(function () {
       this.updates = ['mock-updates']
       this.options = { to: 'mock-to', limit: 'mock-limit' }
       this.PackManager.getOpsByVersionRange = sinon
@@ -586,13 +586,13 @@ describe('UpdatesManager', function() {
       )
     })
 
-    it('should process outstanding updates', function() {
+    it('should process outstanding updates', function () {
       return this.UpdatesManager.processUncompressedUpdatesWithLock
         .calledWith(this.project_id, this.doc_id)
         .should.equal(true)
     })
 
-    it('should get the updates from the database', function() {
+    it('should get the updates from the database', function () {
       return this.PackManager.getOpsByVersionRange
         .calledWith(
           this.project_id,
@@ -603,13 +603,13 @@ describe('UpdatesManager', function() {
         .should.equal(true)
     })
 
-    return it('should return the updates', function() {
+    return it('should return the updates', function () {
       return this.callback.calledWith(null, this.updates).should.equal(true)
     })
   })
 
-  describe('getDocUpdatesWithUserInfo', function() {
-    beforeEach(function() {
+  describe('getDocUpdatesWithUserInfo', function () {
+    beforeEach(function () {
       this.updates = ['mock-updates']
       this.options = { to: 'mock-to', limit: 'mock-limit' }
       this.updatesWithUserInfo = ['updates-with-user-info']
@@ -627,27 +627,27 @@ describe('UpdatesManager', function() {
       )
     })
 
-    it('should get the updates', function() {
+    it('should get the updates', function () {
       return this.UpdatesManager.getDocUpdates
         .calledWith(this.project_id, this.doc_id, this.options)
         .should.equal(true)
     })
 
-    it('should file the updates with the user info', function() {
+    it('should file the updates with the user info', function () {
       return this.UpdatesManager.fillUserInfo
         .calledWith(this.updates)
         .should.equal(true)
     })
 
-    return it('should return the updates with the filled details', function() {
+    return it('should return the updates with the filled details', function () {
       return this.callback
         .calledWith(null, this.updatesWithUserInfo)
         .should.equal(true)
     })
   })
 
-  describe('processUncompressedUpdatesForProject', function() {
-    beforeEach(function(done) {
+  describe('processUncompressedUpdatesForProject', function () {
+    beforeEach(function (done) {
       this.doc_ids = ['mock-id-1', 'mock-id-2']
       this.UpdateTrimmer.shouldTrimUpdates = sinon
         .stub()
@@ -668,27 +668,27 @@ describe('UpdatesManager', function() {
       )
     })
 
-    it('should get all the docs with history ops', function() {
+    it('should get all the docs with history ops', function () {
       return this.RedisManager.getDocIdsWithHistoryOps
         .calledWith(this.project_id)
         .should.equal(true)
     })
 
-    it('should process the doc ops for the each doc_id', function() {
-      return Array.from(this.doc_ids).map(doc_id =>
+    it('should process the doc ops for the each doc_id', function () {
+      return Array.from(this.doc_ids).map((doc_id) =>
         this.UpdatesManager._processUncompressedUpdatesForDocWithLock
           .calledWith(this.project_id, doc_id, this.temporary)
           .should.equal(true)
       )
     })
 
-    return it('should call the callback', function() {
+    return it('should call the callback', function () {
       return this.callback.called.should.equal(true)
     })
   })
 
-  describe('getSummarizedProjectUpdates', function() {
-    beforeEach(function() {
+  describe('getSummarizedProjectUpdates', function () {
+    beforeEach(function () {
       this.updates = [
         {
           doc_id: 123,
@@ -707,7 +707,7 @@ describe('UpdatesManager', function() {
       this.updatesWithUserInfo = ['updates-with-user-info']
       this.done_state = false
       this.iterator = {
-        next: cb => {
+        next: (cb) => {
           this.done_state = true
           return cb(null, this.updates)
         },
@@ -731,25 +731,25 @@ describe('UpdatesManager', function() {
       )
     })
 
-    it('should process any outstanding updates', function() {
+    it('should process any outstanding updates', function () {
       return this.UpdatesManager.processUncompressedUpdatesForProject
         .calledWith(this.project_id)
         .should.equal(true)
     })
 
-    it('should get the updates', function() {
+    it('should get the updates', function () {
       return this.PackManager.makeProjectIterator
         .calledWith(this.project_id, this.options.before)
         .should.equal(true)
     })
 
-    it('should fill the updates with the user info', function() {
+    it('should fill the updates with the user info', function () {
       return this.UpdatesManager.fillSummarizedUserInfo
         .calledWith(this.summarizedUpdates)
         .should.equal(true)
     })
 
-    return it('should return the updates with the filled details', function() {
+    return it('should return the updates with the filled details', function () {
       return this.callback
         .calledWith(null, this.updatesWithUserInfo)
         .should.equal(true)
@@ -861,9 +861,9 @@ describe('UpdatesManager', function() {
   // 		it "should call the callback with the updates", ->
   // 			@callback.calledWith(null, @updates, null).should.equal true
 
-  describe('fillUserInfo', function() {
-    describe('with valid users', function() {
-      beforeEach(function(done) {
+  describe('fillUserInfo', function () {
+    describe('with valid users', function () {
+      beforeEach(function (done) {
         const { ObjectId } = require('mongojs')
         this.user_id_1 = ObjectId().toString()
         this.user_id_2 = ObjectId().toString()
@@ -893,7 +893,7 @@ describe('UpdatesManager', function() {
 
         this.WebApiManager.getUserInfo = (user_id, callback) => {
           if (callback == null) {
-            callback = function(error, userInfo) {}
+            callback = function (error, userInfo) {}
           }
           return callback(null, this.user_info[user_id])
         }
@@ -908,7 +908,7 @@ describe('UpdatesManager', function() {
         )
       })
 
-      it('should only call getUserInfo once for each user_id', function() {
+      it('should only call getUserInfo once for each user_id', function () {
         this.WebApiManager.getUserInfo.calledTwice.should.equal(true)
         this.WebApiManager.getUserInfo
           .calledWith(this.user_id_1)
@@ -918,7 +918,7 @@ describe('UpdatesManager', function() {
           .should.equal(true)
       })
 
-      return it('should return the updates with the user info filled', function() {
+      return it('should return the updates with the user info filled', function () {
         return expect(this.results).to.deep.equal([
           {
             meta: {
@@ -948,8 +948,8 @@ describe('UpdatesManager', function() {
       })
     })
 
-    return describe('with invalid user ids', function() {
-      beforeEach(function(done) {
+    return describe('with invalid user ids', function () {
+      beforeEach(function (done) {
         this.updates = [
           {
             meta: {
@@ -966,7 +966,7 @@ describe('UpdatesManager', function() {
         ]
         this.WebApiManager.getUserInfo = (user_id, callback) => {
           if (callback == null) {
-            callback = function(error, userInfo) {}
+            callback = function (error, userInfo) {}
           }
           return callback(null, this.user_info[user_id])
         }
@@ -981,11 +981,11 @@ describe('UpdatesManager', function() {
         )
       })
 
-      it('should not call getUserInfo', function() {
+      it('should not call getUserInfo', function () {
         return this.WebApiManager.getUserInfo.called.should.equal(false)
       })
 
-      return it('should return the updates without the user info filled', function() {
+      return it('should return the updates without the user info filled', function () {
         return expect(this.results).to.deep.equal([
           {
             meta: {},
@@ -1000,14 +1000,14 @@ describe('UpdatesManager', function() {
     })
   })
 
-  return describe('_summarizeUpdates', function() {
-    beforeEach(function() {
+  return describe('_summarizeUpdates', function () {
+    beforeEach(function () {
       this.now = Date.now()
       this.user_1 = { id: 'mock-user-1' }
       return (this.user_2 = { id: 'mock-user-2' })
     })
 
-    it('should concat updates that are close in time', function() {
+    it('should concat updates that are close in time', function () {
       const result = this.UpdatesManager._summarizeUpdates([
         {
           doc_id: 'doc-id-1',
@@ -1046,7 +1046,7 @@ describe('UpdatesManager', function() {
       ])
     })
 
-    it('should leave updates that are far apart in time', function() {
+    it('should leave updates that are far apart in time', function () {
       const oneDay = 1000 * 60 * 60 * 24
       const result = this.UpdatesManager._summarizeUpdates([
         {
@@ -1098,7 +1098,7 @@ describe('UpdatesManager', function() {
       ])
     })
 
-    it('should concat onto existing summarized updates', function() {
+    it('should concat onto existing summarized updates', function () {
       const result = this.UpdatesManager._summarizeUpdates(
         [
           {
@@ -1157,7 +1157,7 @@ describe('UpdatesManager', function() {
       ])
     })
 
-    it('should include null user values', function() {
+    it('should include null user values', function () {
       const result = this.UpdatesManager._summarizeUpdates([
         {
           doc_id: 'doc-id-1',
@@ -1195,7 +1195,7 @@ describe('UpdatesManager', function() {
       ])
     })
 
-    it('should include null user values, when the null is earlier in the updates list', function() {
+    it('should include null user values, when the null is earlier in the updates list', function () {
       const result = this.UpdatesManager._summarizeUpdates([
         {
           doc_id: 'doc-id-1',
@@ -1233,7 +1233,7 @@ describe('UpdatesManager', function() {
       ])
     })
 
-    it('should roll several null user values into one', function() {
+    it('should roll several null user values into one', function () {
       const result = this.UpdatesManager._summarizeUpdates([
         {
           doc_id: 'doc-id-1',
@@ -1280,7 +1280,7 @@ describe('UpdatesManager', function() {
       ])
     })
 
-    return it('should split updates before a big delete', function() {
+    return it('should split updates before a big delete', function () {
       const result = this.UpdatesManager._summarizeUpdates([
         {
           doc_id: 'doc-id-1',

+ 27 - 27
services/track-changes/test/unit/js/WebApiManager/WebApiManagerTests.js

@@ -16,8 +16,8 @@ const { expect } = chai
 const modulePath = '../../../../app/js/WebApiManager.js'
 const SandboxedModule = require('sandboxed-module')
 
-describe('WebApiManager', function() {
-  beforeEach(function() {
+describe('WebApiManager', function () {
+  beforeEach(function () {
     this.WebApiManager = SandboxedModule.require(modulePath, {
       requires: {
         requestretry: (this.request = {}),
@@ -49,9 +49,9 @@ describe('WebApiManager', function() {
     return (this.project = { features: 'mock-features' })
   })
 
-  describe('getUserInfo', function() {
-    describe('successfully', function() {
-      beforeEach(function() {
+  describe('getUserInfo', function () {
+    describe('successfully', function () {
+      beforeEach(function () {
         this.body = JSON.stringify(this.user_info)
         this.request.get = sinon
           .stub()
@@ -59,7 +59,7 @@ describe('WebApiManager', function() {
         return this.WebApiManager.getUserInfo(this.user_id, this.callback)
       })
 
-      it('should get the user from the web api', function() {
+      it('should get the user from the web api', function () {
         return this.request.get
           .calledWithMatch({
             url: `${this.settings.apis.web.url}/user/${this.user_id}/personal_info`,
@@ -72,7 +72,7 @@ describe('WebApiManager', function() {
           .should.equal(true)
       })
 
-      return it('should call the callback with only the email, id and names', function() {
+      return it('should call the callback with only the email, id and names', function () {
         return this.callback
           .calledWith(null, {
             id: this.user_id,
@@ -84,8 +84,8 @@ describe('WebApiManager', function() {
       })
     })
 
-    describe('when the web API returns an error', function() {
-      beforeEach(function() {
+    describe('when the web API returns an error', function () {
+      beforeEach(function () {
         this.request.get = sinon
           .stub()
           .callsArgWith(
@@ -97,20 +97,20 @@ describe('WebApiManager', function() {
         return this.WebApiManager.getUserInfo(this.user_id, this.callback)
       })
 
-      return it('should return an error to the callback', function() {
+      return it('should return an error to the callback', function () {
         return this.callback.calledWith(this.error).should.equal(true)
       })
     })
 
-    describe('when the web returns a failure error code', function() {
-      beforeEach(function() {
+    describe('when the web returns a failure error code', function () {
+      beforeEach(function () {
         this.request.get = sinon
           .stub()
           .callsArgWith(1, null, { statusCode: 500, attempts: 42 }, '')
         return this.WebApiManager.getUserInfo(this.user_id, this.callback)
       })
 
-      return it('should return the callback with an error', function() {
+      return it('should return the callback with an error', function () {
         return this.callback
           .calledWith(
             sinon.match.has(
@@ -122,23 +122,23 @@ describe('WebApiManager', function() {
       })
     })
 
-    return describe('when the user cannot be found', function() {
-      beforeEach(function() {
+    return describe('when the user cannot be found', function () {
+      beforeEach(function () {
         this.request.get = sinon
           .stub()
           .callsArgWith(1, null, { statusCode: 404 }, 'nothing')
         return this.WebApiManager.getUserInfo(this.user_id, this.callback)
       })
 
-      return it('should return a null value', function() {
+      return it('should return a null value', function () {
         return this.callback.calledWith(null, null).should.equal(true)
       })
     })
   })
 
-  return describe('getProjectDetails', function() {
-    describe('successfully', function() {
-      beforeEach(function() {
+  return describe('getProjectDetails', function () {
+    describe('successfully', function () {
+      beforeEach(function () {
         this.body = JSON.stringify(this.project)
         this.request.get = sinon
           .stub()
@@ -149,7 +149,7 @@ describe('WebApiManager', function() {
         )
       })
 
-      it('should get the project from the web api', function() {
+      it('should get the project from the web api', function () {
         return this.request.get
           .calledWithMatch({
             url: `${this.settings.apis.web.url}/project/${this.project_id}/details`,
@@ -162,13 +162,13 @@ describe('WebApiManager', function() {
           .should.equal(true)
       })
 
-      return it('should call the callback with the project', function() {
+      return it('should call the callback with the project', function () {
         return this.callback.calledWith(null, this.project).should.equal(true)
       })
     })
 
-    describe('when the web API returns an error', function() {
-      beforeEach(function() {
+    describe('when the web API returns an error', function () {
+      beforeEach(function () {
         this.request.get = sinon
           .stub()
           .callsArgWith(
@@ -183,13 +183,13 @@ describe('WebApiManager', function() {
         )
       })
 
-      return it('should return an error to the callback', function() {
+      return it('should return an error to the callback', function () {
         return this.callback.calledWith(this.error).should.equal(true)
       })
     })
 
-    return describe('when the web returns a failure error code', function() {
-      beforeEach(function() {
+    return describe('when the web returns a failure error code', function () {
+      beforeEach(function () {
         this.request.get = sinon
           .stub()
           .callsArgWith(1, null, { statusCode: 500, attempts: 42 }, '')
@@ -199,7 +199,7 @@ describe('WebApiManager', function() {
         )
       })
 
-      return it('should return the callback with an error', function() {
+      return it('should return the callback with an error', function () {
         return this.callback
           .calledWith(
             sinon.match.has(

Some files were not shown because too many files changed in this diff