|
|
@@ -24,7 +24,16 @@ describe('RestoreManager', function () {
|
|
|
}),
|
|
|
'../Project/ProjectLocator': (this.ProjectLocator = { promises: {} }),
|
|
|
'../DocumentUpdater/DocumentUpdaterHandler':
|
|
|
- (this.DocumentUpdaterHandler = { promises: {} }),
|
|
|
+ (this.DocumentUpdaterHandler = {
|
|
|
+ promises: { flushProjectToMongo: sinon.stub().resolves() },
|
|
|
+ }),
|
|
|
+ '../Docstore/DocstoreManager': (this.DocstoreManager = {
|
|
|
+ promises: {},
|
|
|
+ }),
|
|
|
+ '../Chat/ChatApiHandler': (this.ChatApiHandler = { promises: {} }),
|
|
|
+ '../Chat/ChatManager': (this.ChatManager = { promises: {} }),
|
|
|
+ '../Editor/EditorRealTimeController': (this.EditorRealTimeController =
|
|
|
+ {}),
|
|
|
},
|
|
|
})
|
|
|
this.user_id = 'mock-user-id'
|
|
|
@@ -231,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,
|
|
|
@@ -242,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' })
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -297,7 +320,34 @@ describe('RestoreManager', function () {
|
|
|
describe("when reverting a file that doesn't current exist", function () {
|
|
|
beforeEach(async function () {
|
|
|
this.pathname = 'foo.tex'
|
|
|
+ this.comments = [
|
|
|
+ (this.comment = { op: { t: 'comment-1', p: 0, c: 'foo' } }),
|
|
|
+ ]
|
|
|
+ this.remappedComments = [{ op: { t: 'comment-2', p: 0, c: 'foo' } }]
|
|
|
this.ProjectLocator.promises.findElementByPath = sinon.stub().rejects()
|
|
|
+ this.DocstoreManager.promises.getAllRanges = sinon.stub().resolves([
|
|
|
+ {
|
|
|
+ ranges: {
|
|
|
+ comments: [this.comment],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ])
|
|
|
+ this.ChatApiHandler.promises.duplicateCommentThreads = sinon
|
|
|
+ .stub()
|
|
|
+ .resolves({
|
|
|
+ newThreads: {
|
|
|
+ 'comment-1': {
|
|
|
+ duplicateId: 'comment-2',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ })
|
|
|
+ this.ChatApiHandler.promises.generateThreadData = sinon
|
|
|
+ .stub()
|
|
|
+ .resolves({})
|
|
|
+ this.ChatManager.promises.injectUserInfoIntoThreads = sinon
|
|
|
+ .stub()
|
|
|
+ .resolves()
|
|
|
+ this.EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
this.tracked_changes = [
|
|
|
{
|
|
|
op: { pos: 4, i: 'bar' },
|
|
|
@@ -308,13 +358,12 @@ describe('RestoreManager', function () {
|
|
|
metadata: { ts: '2024-01-01T00:00:00.000Z', user_id: 'user-2' },
|
|
|
},
|
|
|
]
|
|
|
- this.comments = [{ op: { t: 'comment-1', p: 0, c: 'foo' } }]
|
|
|
this.FileSystemImportManager.promises.importFile = sinon
|
|
|
.stub()
|
|
|
.resolves({ type: 'doc', lines: ['foo', 'bar', 'baz'] })
|
|
|
this.RestoreManager.promises._getRangesFromHistory = sinon
|
|
|
.stub()
|
|
|
- .resolves({ changes: this.tracked_changes, comment: this.comments })
|
|
|
+ .resolves({ changes: this.tracked_changes, comments: this.comments })
|
|
|
this.EditorController.promises.addDocWithRanges = sinon
|
|
|
.stub()
|
|
|
.resolves(
|
|
|
@@ -336,7 +385,7 @@ describe('RestoreManager', function () {
|
|
|
this.folder_id,
|
|
|
'foo.tex',
|
|
|
['foo', 'bar', 'baz'],
|
|
|
- { changes: this.tracked_changes, comment: this.comments }
|
|
|
+ { changes: this.tracked_changes, comments: this.remappedComments }
|
|
|
)
|
|
|
})
|
|
|
|