Просмотр исходного кода

Merge pull request #18737 from overleaf/mj-chat-revert-existing-file

[web] Revert existing file by deleting it first

GitOrigin-RevId: ec9ed5c709c2631ff08dbc2e0f3633d303f12836
Mathias Jakobsen 2 лет назад
Родитель
Сommit
d470093174

+ 8 - 8
services/web/app/src/Features/History/RestoreManager.js

@@ -93,17 +93,17 @@ const RestoreManager = {
     }
 
     if (file) {
-      await DocumentUpdaterHandler.promises.setDocument(
+      logger.debug(
+        { projectId, fileId: file.element._id, type: importInfo.type },
+        'deleting entity before reverting it'
+      )
+      await EditorController.promises.deleteEntity(
         projectId,
         file.element._id,
-        userId,
-        importInfo.lines,
-        source
+        importInfo.type,
+        'revert',
+        userId
       )
-      return {
-        _id: file.element._id,
-        type: importInfo.type,
-      }
     }
 
     const ranges = await RestoreManager._getRangesFromHistory(

+ 21 - 7
services/web/test/unit/src/History/RestoreManagerTests.js

@@ -240,10 +240,25 @@ describe('RestoreManager', function () {
         this.DocumentUpdaterHandler.promises.setDocument = sinon
           .stub()
           .resolves()
+        this.EditorController.promises.deleteEntity = sinon.stub().resolves()
+        this.RestoreManager.promises._getRangesFromHistory = sinon
+          .stub()
+          .resolves({ changes: [], comments: [] })
+        this.DocstoreManager.promises.getAllRanges = sinon.stub().resolves([])
+        this.ChatApiHandler.promises.generateThreadData = sinon
+          .stub()
+          .resolves({})
+        this.ChatManager.promises.injectUserInfoIntoThreads = sinon
+          .stub()
+          .resolves()
+        this.EditorRealTimeController.emitToRoom = sinon.stub()
+        this.EditorController.promises.addDocWithRanges = sinon
+          .stub()
+          .resolves()
       })
 
-      it('should call setDocument in document updater and revert file', async function () {
-        const revertRes = await this.RestoreManager.promises.revertFile(
+      it('should delete the existing document', async function () {
+        await this.RestoreManager.promises.revertFile(
           this.user_id,
           this.project_id,
           this.version,
@@ -251,15 +266,14 @@ describe('RestoreManager', function () {
         )
 
         expect(
-          this.DocumentUpdaterHandler.promises.setDocument
+          this.EditorController.promises.deleteEntity
         ).to.have.been.calledWith(
           this.project_id,
           'mock-file-id',
-          this.user_id,
-          ['foo', 'bar', 'baz'],
-          'file-revert'
+          'doc',
+          'revert',
+          this.user_id
         )
-        expect(revertRes).to.deep.equal({ _id: 'mock-file-id', type: 'doc' })
       })
     })