diff --git a/services/web/app/src/Features/History/RestoreManager.js b/services/web/app/src/Features/History/RestoreManager.js index 1d210b2fdc..5f2c8244e6 100644 --- a/services/web/app/src/Features/History/RestoreManager.js +++ b/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( diff --git a/services/web/test/unit/src/History/RestoreManagerTests.js b/services/web/test/unit/src/History/RestoreManagerTests.js index 93929cc64e..603d484b93 100644 --- a/services/web/test/unit/src/History/RestoreManagerTests.js +++ b/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' }) }) })