Eric Mc Sween 6 лет назад
Родитель
Сommit
65fe74fd2d
19 измененных файлов с 331 добавлено и 232 удалено
  1. 208 120
      services/document-updater/package-lock.json
  2. 1 1
      services/document-updater/package.json
  3. 19 19
      services/document-updater/test/acceptance/js/FlushingDocsTests.js
  4. 16 12
      services/document-updater/test/acceptance/js/GettingADocumentTests.js
  5. 18 18
      services/document-updater/test/acceptance/js/SettingADocumentTests.js
  6. 8 9
      services/document-updater/test/unit/js/DocumentManager/DocumentManagerTests.js
  7. 1 1
      services/document-updater/test/unit/js/HistoryRedisManager/HistoryRedisManagerTests.js
  8. 12 12
      services/document-updater/test/unit/js/HttpController/HttpControllerTests.js
  9. 1 1
      services/document-updater/test/unit/js/LockManager/ReleasingTheLock.js
  10. 7 3
      services/document-updater/test/unit/js/LockManager/getLockTests.js
  11. 3 2
      services/document-updater/test/unit/js/LockManager/tryLockTests.js
  12. 9 8
      services/document-updater/test/unit/js/PersistenceManager/PersistenceManagerTests.js
  13. 3 1
      services/document-updater/test/unit/js/ProjectManager/flushAndDeleteProjectTests.js
  14. 3 1
      services/document-updater/test/unit/js/ProjectManager/flushProjectTests.js
  15. 6 5
      services/document-updater/test/unit/js/ProjectManager/getProjectDocsTests.js
  16. 1 1
      services/document-updater/test/unit/js/RealTimeRedisManager/RealTimeRedisManagerTests.js
  17. 9 15
      services/document-updater/test/unit/js/RedisManager/RedisManagerTests.js
  18. 3 2
      services/document-updater/test/unit/js/ShareJsDB/ShareJsDBTests.js
  19. 3 1
      services/document-updater/test/unit/js/ShareJsUpdateManager/ShareJsUpdateManagerTests.js

Разница между файлами не показана из-за своего большого размера
+ 208 - 120
services/document-updater/package-lock.json


+ 1 - 1
services/document-updater/package.json

@@ -55,7 +55,7 @@
     "prettier": "^2.0.5",
     "prettier-eslint-cli": "^5.0.0",
     "sandboxed-module": "~0.2.0",
-    "sinon": "~1.5.2",
+    "sinon": "^9.0.2",
     "timekeeper": "^2.0.0"
   }
 }

+ 19 - 19
services/document-updater/test/acceptance/js/FlushingDocsTests.js

@@ -121,26 +121,26 @@ describe('Flushing a doc to Mongo', function () {
         version: this.version
       })
       let t = 30000
-      sinon.stub(
-        MockWebApi,
-        'setDocument',
-        (
-          project_id,
-          doc_id,
-          lines,
-          version,
-          ranges,
-          lastUpdatedAt,
-          lastUpdatedBy,
-          callback
-        ) => {
-          if (callback == null) {
-            callback = function (error) {}
+      sinon
+        .stub(MockWebApi, 'setDocument')
+        .callsFake(
+          (
+            project_id,
+            doc_id,
+            lines,
+            version,
+            ranges,
+            lastUpdatedAt,
+            lastUpdatedBy,
+            callback
+          ) => {
+            if (callback == null) {
+              callback = function (error) {}
+            }
+            setTimeout(callback, t)
+            return (t = 0)
           }
-          setTimeout(callback, t)
-          return (t = 0)
-        }
-      )
+        )
       return DocUpdaterClient.preloadDoc(this.project_id, this.doc_id, done)
     })
 

+ 16 - 12
services/document-updater/test/acceptance/js/GettingADocumentTests.js

@@ -216,12 +216,14 @@ describe('Getting a document', function () {
         DocUpdaterClient.randomId(),
         DocUpdaterClient.randomId()
       ])
-      sinon.stub(MockWebApi, 'getDocument', (project_id, doc_id, callback) => {
-        if (callback == null) {
-          callback = function (error, doc) {}
-        }
-        return callback(new Error('oops'))
-      })
+      sinon
+        .stub(MockWebApi, 'getDocument')
+        .callsFake((project_id, doc_id, callback) => {
+          if (callback == null) {
+            callback = function (error, doc) {}
+          }
+          return callback(new Error('oops'))
+        })
       return DocUpdaterClient.getDoc(
         this.project_id,
         this.doc_id,
@@ -248,12 +250,14 @@ describe('Getting a document', function () {
         DocUpdaterClient.randomId(),
         DocUpdaterClient.randomId()
       ])
-      sinon.stub(MockWebApi, 'getDocument', (project_id, doc_id, callback) => {
-        if (callback == null) {
-          callback = function (error, doc) {}
-        }
-        return setTimeout(callback, 30000)
-      })
+      sinon
+        .stub(MockWebApi, 'getDocument')
+        .callsFake((project_id, doc_id, callback) => {
+          if (callback == null) {
+            callback = function (error, doc) {}
+          }
+          return setTimeout(callback, 30000)
+        })
       return done()
     })
 

+ 18 - 18
services/document-updater/test/acceptance/js/SettingADocumentTests.js

@@ -88,9 +88,9 @@ describe('Setting a document', function () {
     })
 
     after(function () {
-      MockTrackChangesApi.flushDoc.reset()
-      MockProjectHistoryApi.flushProject.reset()
-      MockWebApi.setDocument.reset()
+      MockTrackChangesApi.flushDoc.resetHistory()
+      MockProjectHistoryApi.flushProject.resetHistory()
+      MockWebApi.setDocument.resetHistory()
     })
 
     it('should return a 204 status code', function () {
@@ -171,9 +171,9 @@ describe('Setting a document', function () {
     })
 
     after(function () {
-      MockTrackChangesApi.flushDoc.reset()
-      MockProjectHistoryApi.flushProject.reset()
-      MockWebApi.setDocument.reset()
+      MockTrackChangesApi.flushDoc.resetHistory()
+      MockProjectHistoryApi.flushProject.resetHistory()
+      MockWebApi.setDocument.resetHistory()
     })
 
     it('should return a 204 status code', function () {
@@ -254,9 +254,9 @@ describe('Setting a document', function () {
       })
 
       after(function () {
-        MockTrackChangesApi.flushDoc.reset()
-        MockProjectHistoryApi.flushProject.reset()
-        MockWebApi.setDocument.reset()
+        MockTrackChangesApi.flushDoc.resetHistory()
+        MockProjectHistoryApi.flushProject.resetHistory()
+        MockWebApi.setDocument.resetHistory()
       })
 
       it(`should return a ${testCase.expectedStatusCode} status code`, function () {
@@ -310,9 +310,9 @@ describe('Setting a document', function () {
     })
 
     after(function () {
-      MockTrackChangesApi.flushDoc.reset()
-      MockProjectHistoryApi.flushProject.reset()
-      MockWebApi.setDocument.reset()
+      MockTrackChangesApi.flushDoc.resetHistory()
+      MockProjectHistoryApi.flushProject.resetHistory()
+      MockWebApi.setDocument.resetHistory()
     })
 
     it('should return a 204 status code', function () {
@@ -388,9 +388,9 @@ describe('Setting a document', function () {
       })
 
       after(function () {
-        MockTrackChangesApi.flushDoc.reset()
-        MockProjectHistoryApi.flushProject.reset()
-        MockWebApi.setDocument.reset()
+        MockTrackChangesApi.flushDoc.resetHistory()
+        MockProjectHistoryApi.flushProject.resetHistory()
+        MockWebApi.setDocument.resetHistory()
       })
 
       it('should undo the tracked changes', function (done) {
@@ -451,9 +451,9 @@ describe('Setting a document', function () {
       })
 
       after(function () {
-        MockTrackChangesApi.flushDoc.reset()
-        MockProjectHistoryApi.flushProject.reset()
-        MockWebApi.setDocument.reset()
+        MockTrackChangesApi.flushDoc.resetHistory()
+        MockProjectHistoryApi.flushProject.resetHistory()
+        MockWebApi.setDocument.resetHistory()
       })
 
       it('should not undo the tracked changes', function (done) {

+ 8 - 9
services/document-updater/test/unit/js/DocumentManager/DocumentManagerTests.js

@@ -52,7 +52,8 @@ describe('DocumentManager', function () {
         './RealTimeRedisManager': (this.RealTimeRedisManager = {}),
         './DiffCodec': (this.DiffCodec = {}),
         './UpdateManager': (this.UpdateManager = {}),
-        './RangesManager': (this.RangesManager = {})
+        './RangesManager': (this.RangesManager = {}),
+        './Errors': Errors
       }
     })
     this.project_id = 'project-id-123'
@@ -765,10 +766,9 @@ describe('DocumentManager', function () {
       })
 
       return it('should call the callback with a not found error', function () {
-        const error = new Errors.NotFoundError(
-          `document not found: ${this.doc_id}`
-        )
-        return this.callback.calledWith(error).should.equal(true)
+        return this.callback
+          .calledWith(sinon.match.instanceOf(Errors.NotFoundError))
+          .should.equal(true)
       })
     })
   })
@@ -848,10 +848,9 @@ describe('DocumentManager', function () {
       })
 
       return it('should call the callback with a not found error', function () {
-        const error = new Errors.NotFoundError(
-          `document not found: ${this.doc_id}`
-        )
-        return this.callback.calledWith(error).should.equal(true)
+        return this.callback
+          .calledWith(sinon.match.instanceOf(Errors.NotFoundError))
+          .should.equal(true)
       })
     })
   })

+ 1 - 1
services/document-updater/test/unit/js/HistoryRedisManager/HistoryRedisManagerTests.js

@@ -95,7 +95,7 @@ describe('HistoryRedisManager', function () {
 
       return it('should call the callback with an error', function () {
         return this.callback
-          .calledWith(new Error('cannot push no ops'))
+          .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
       })
     })

+ 12 - 12
services/document-updater/test/unit/js/HttpController/HttpControllerTests.js

@@ -159,7 +159,7 @@ describe('HttpController', function () {
 
       it('should call next with NotFoundError', function () {
         this.next
-          .calledWith(new Errors.NotFoundError('not found'))
+          .calledWith(sinon.match.instanceOf(Errors.NotFoundError))
           .should.equal(true)
       })
     })
@@ -173,7 +173,7 @@ describe('HttpController', function () {
       })
 
       it('should call next with the error', function () {
-        this.next.calledWith(new Error('oops')).should.equal(true)
+        this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
       })
     })
   })
@@ -252,7 +252,7 @@ describe('HttpController', function () {
       })
 
       it('should call next with the error', function () {
-        this.next.calledWith(new Error('oops')).should.equal(true)
+        this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
       })
     })
 
@@ -327,7 +327,7 @@ describe('HttpController', function () {
       })
 
       it('should call next with the error', function () {
-        this.next.calledWith(new Error('oops')).should.equal(true)
+        this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
       })
     })
   })
@@ -387,7 +387,7 @@ describe('HttpController', function () {
       })
 
       it('should call next with the error', function () {
-        this.next.calledWith(new Error('oops')).should.equal(true)
+        this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
       })
     })
   })
@@ -477,7 +477,7 @@ describe('HttpController', function () {
       })
 
       it('should call next with the error', function () {
-        this.next.calledWith(new Error('oops')).should.equal(true)
+        this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
       })
     })
   })
@@ -550,7 +550,7 @@ describe('HttpController', function () {
       })
 
       it('should call next with the error', function () {
-        this.next.calledWith(new Error('oops')).should.equal(true)
+        this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
       })
     })
   })
@@ -640,7 +640,7 @@ describe('HttpController', function () {
       })
 
       it('should call next with the error', function () {
-        this.next.calledWith(new Error('oops')).should.equal(true)
+        this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
       })
     })
   })
@@ -703,7 +703,7 @@ describe('HttpController', function () {
       })
 
       it('should call next with the error', function () {
-        this.next.calledWith(new Error('oops')).should.equal(true)
+        this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
       })
     })
   })
@@ -804,7 +804,7 @@ describe('HttpController', function () {
       })
 
       it('should call next with the error', function () {
-        this.next.calledWith(new Error('oops')).should.equal(true)
+        this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
       })
     })
   })
@@ -870,7 +870,7 @@ describe('HttpController', function () {
       })
 
       it('should call next with the error', function () {
-        this.next.calledWith(new Error('oops')).should.equal(true)
+        this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
       })
     })
   })
@@ -925,7 +925,7 @@ describe('HttpController', function () {
       })
 
       it('should call next with the error', function () {
-        this.next.calledWith(new Error('oops')).should.equal(true)
+        this.next.calledWith(sinon.match.instanceOf(Error)).should.equal(true)
       })
     })
   })

+ 1 - 1
services/document-updater/test/unit/js/LockManager/ReleasingTheLock.js

@@ -92,7 +92,7 @@ describe('LockManager - releasing the lock', function () {
 
     return it('should return an error if the lock has expired', function () {
       return this.callback
-        .calledWith(new Error('tried to release timed out lock'))
+        .calledWith(sinon.match.instanceOf(Error))
         .should.equal(true)
     })
   })

+ 7 - 3
services/document-updater/test/unit/js/LockManager/getLockTests.js

@@ -119,9 +119,13 @@ describe('LockManager - getting the lock', function () {
     })
 
     return it('should return the callback with an error', function () {
-      const e = new Error('Timeout')
-      e.doc_id = this.doc_id
-      return this.callback.calledWith(e).should.equal(true)
+      return this.callback
+        .calledWith(
+          sinon.match
+            .instanceOf(Error)
+            .and(sinon.match.has('doc_id', this.doc_id))
+        )
+        .should.equal(true)
     })
   })
 })

+ 3 - 2
services/document-updater/test/unit/js/LockManager/tryLockTests.js

@@ -142,8 +142,9 @@ describe('LockManager - trying the lock', function () {
       })
 
       return it('should return the callback with an error', function () {
-        const e = new Error('tried to release timed out lock')
-        return this.callback.calledWith(e).should.equal(true)
+        return this.callback
+          .calledWith(sinon.match.instanceOf(Error))
+          .should.equal(true)
       })
     })
   })

+ 9 - 8
services/document-updater/test/unit/js/PersistenceManager/PersistenceManagerTests.js

@@ -41,7 +41,8 @@ describe('PersistenceManager', function () {
         'logger-sharelatex': (this.logger = {
           log: sinon.stub(),
           err: sinon.stub()
-        })
+        }),
+        './Errors': Errors
       }
     })
     this.project_id = 'project-id-123'
@@ -171,7 +172,7 @@ describe('PersistenceManager', function () {
 
       it('should return a NotFoundError', function () {
         return this.callback
-          .calledWith(new Errors.NotFoundError('not found'))
+          .calledWith(sinon.match.instanceOf(Errors.NotFoundError))
           .should.equal(true)
       })
 
@@ -198,7 +199,7 @@ describe('PersistenceManager', function () {
 
       it('should return an error', function () {
         return this.callback
-          .calledWith(new Error('web api error'))
+          .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
       })
 
@@ -231,7 +232,7 @@ describe('PersistenceManager', function () {
 
       return it('should return and error', function () {
         return this.callback
-          .calledWith(new Error('web API response had no doc lines'))
+          .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
       })
     })
@@ -254,7 +255,7 @@ describe('PersistenceManager', function () {
 
       return it('should return and error', function () {
         return this.callback
-          .calledWith(new Error('web API response had no valid doc version'))
+          .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
       })
     })
@@ -277,7 +278,7 @@ describe('PersistenceManager', function () {
 
       return it('should return and error', function () {
         return this.callback
-          .calledWith(new Error('web API response had no valid doc pathname'))
+          .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
       })
     })
@@ -386,7 +387,7 @@ describe('PersistenceManager', function () {
 
       it('should return a NotFoundError', function () {
         return this.callback
-          .calledWith(new Errors.NotFoundError('not found'))
+          .calledWith(sinon.match.instanceOf(Errors.NotFoundError))
           .should.equal(true)
       })
 
@@ -418,7 +419,7 @@ describe('PersistenceManager', function () {
 
       it('should return an error', function () {
         return this.callback
-          .calledWith(new Error('web api error'))
+          .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
       })
 

+ 3 - 1
services/document-updater/test/unit/js/ProjectManager/flushAndDeleteProjectTests.js

@@ -147,7 +147,9 @@ describe('ProjectManager - flushAndDeleteProject', function () {
     })
 
     it('should call the callback with an error', function () {
-      return this.callback.calledWith(new Error()).should.equal(true)
+      return this.callback
+        .calledWith(sinon.match.instanceOf(Error))
+        .should.equal(true)
     })
 
     return it('should time the execution', function () {

+ 3 - 1
services/document-updater/test/unit/js/ProjectManager/flushProjectTests.js

@@ -136,7 +136,9 @@ describe('ProjectManager - flushProject', function () {
     })
 
     it('should call the callback with an error', function () {
-      return this.callback.calledWith(new Error()).should.equal(true)
+      return this.callback
+        .calledWith(sinon.match.instanceOf(Error))
+        .should.equal(true)
     })
 
     return it('should time the execution', function () {

+ 6 - 5
services/document-updater/test/unit/js/ProjectManager/getProjectDocsTests.js

@@ -40,7 +40,8 @@ describe('ProjectManager - getProjectDocsAndFlushIfOld', function () {
             Timer.initClass()
             return Timer
           })())
-        })
+        }),
+        './Errors': Errors
       }
     })
     this.project_id = 'project-id-123'
@@ -146,9 +147,7 @@ describe('ProjectManager - getProjectDocsAndFlushIfOld', function () {
 
     it('should call the callback with an error', function () {
       return this.callback
-        .calledWith(
-          new Errors.ProjectStateChangedError('project state changed')
-        )
+        .calledWith(sinon.match.instanceOf(Errors.ProjectStateChangedError))
         .should.equal(true)
     })
 
@@ -194,7 +193,9 @@ describe('ProjectManager - getProjectDocsAndFlushIfOld', function () {
     })
 
     it('should call the callback with an error', function () {
-      return this.callback.calledWith(new Error('oops')).should.equal(true)
+      return this.callback
+        .calledWith(sinon.match.instanceOf(Error))
+        .should.equal(true)
     })
 
     return it('should time the execution', function () {

+ 1 - 1
services/document-updater/test/unit/js/RealTimeRedisManager/RealTimeRedisManagerTests.js

@@ -118,7 +118,7 @@ describe('RealTimeRedisManager', function () {
 
       return it('should return an error to the callback', function () {
         return this.callback
-          .calledWith(new Error('JSON parse error'))
+          .calledWith(sinon.match.has('name', 'SyntaxError'))
           .should.equal(true)
       })
     })

+ 9 - 15
services/document-updater/test/unit/js/RedisManager/RedisManagerTests.js

@@ -398,7 +398,7 @@ describe('RedisManager', function () {
 
       return it('should return an error', function () {
         return this.callback
-          .calledWith(new Error('redis getDoc exceeded timeout'))
+          .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
       })
     })
@@ -426,7 +426,7 @@ describe('RedisManager', function () {
 
       return it('should return an error', function () {
         return this.callback
-          .calledWith(new Errors.NotFoundError('not found'))
+          .calledWith(sinon.match.instanceOf(Errors.NotFoundError))
           .should.equal(true)
       })
     })
@@ -543,11 +543,7 @@ describe('RedisManager', function () {
 
       it('should return an error', function () {
         return this.callback
-          .calledWith(
-            new Errors.OpRangeNotAvailableError(
-              'doc ops range is not loaded in redis'
-            )
-          )
+          .calledWith(sinon.match.instanceOf(Errors.OpRangeNotAvailableError))
           .should.equal(true)
       })
 
@@ -588,7 +584,7 @@ describe('RedisManager', function () {
 
       return it('should return an error', function () {
         return this.callback
-          .calledWith(new Error('redis getPreviousDocOps exceeded timeout'))
+          .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
       })
     })
@@ -854,9 +850,7 @@ describe('RedisManager', function () {
 
       return it('should call the callback with an error', function () {
         return this.callback
-          .calledWith(
-            new Error(`Version mismatch. '${this.doc_id}' is corrupted.`)
-          )
+          .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
       })
     })
@@ -954,7 +948,7 @@ describe('RedisManager', function () {
 
       return it('should call the callback with an error', function () {
         return this.callback
-          .calledWith(new Error('null bytes found in doc lines'))
+          .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
       })
     })
@@ -985,7 +979,7 @@ describe('RedisManager', function () {
 
       return it('should call the callback with the error', function () {
         return this.callback
-          .calledWith(new Error('ranges are too large'))
+          .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
       })
     })
@@ -1157,7 +1151,7 @@ describe('RedisManager', function () {
 
       return it('should call the callback with an error', function () {
         return this.callback
-          .calledWith(new Error('null bytes found in doc lines'))
+          .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
       })
     })
@@ -1185,7 +1179,7 @@ describe('RedisManager', function () {
 
       return it('should call the callback with the error', function () {
         return this.callback
-          .calledWith(new Error('ranges are too large'))
+          .calledWith(sinon.match.instanceOf(Error))
           .should.equal(true)
       })
     })

+ 3 - 2
services/document-updater/test/unit/js/ShareJsDB/ShareJsDBTests.js

@@ -26,7 +26,8 @@ describe('ShareJsDB', function () {
     this.callback = sinon.stub()
     this.ShareJsDB = SandboxedModule.require(modulePath, {
       requires: {
-        './RedisManager': (this.RedisManager = {})
+        './RedisManager': (this.RedisManager = {}),
+        './Errors': Errors
       }
     })
 
@@ -68,7 +69,7 @@ describe('ShareJsDB', function () {
 
       return it('should return the callback with a NotFoundError', function () {
         return this.callback
-          .calledWith(new Errors.NotFoundError('not found'))
+          .calledWith(sinon.match.instanceOf(Errors.NotFoundError))
           .should.equal(true)
       })
     })

+ 3 - 1
services/document-updater/test/unit/js/ShareJsUpdateManager/ShareJsUpdateManagerTests.js

@@ -194,7 +194,9 @@ describe('ShareJsUpdateManager', function () {
       })
 
       return it('should call the callback with the error', function () {
-        return this.callback.calledWith(this.error).should.equal(true)
+        return this.callback
+          .calledWith(sinon.match.instanceOf(Error))
+          .should.equal(true)
       })
     })
   })

Некоторые файлы не были показаны из-за большого количества измененных файлов