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

[web] Revert existing file by deleting it first

GitOrigin-RevId: ec9ed5c709c2631ff08dbc2e0f3633d303f12836
This commit is contained in:
Mathias Jakobsen 2024-06-07 12:08:03 +01:00 committed by Copybot
parent 110b83aea0
commit d470093174
2 changed files with 29 additions and 15 deletions

View file

@ -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(

View file

@ -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' })
})
})