|
@@ -24,16 +24,7 @@ describe('RestoreManager', function () {
|
|
|
}),
|
|
}),
|
|
|
'../Project/ProjectLocator': (this.ProjectLocator = { promises: {} }),
|
|
'../Project/ProjectLocator': (this.ProjectLocator = { promises: {} }),
|
|
|
'../DocumentUpdater/DocumentUpdaterHandler':
|
|
'../DocumentUpdater/DocumentUpdaterHandler':
|
|
|
- (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.DocumentUpdaterHandler = { promises: {} }),
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
this.user_id = 'mock-user-id'
|
|
this.user_id = 'mock-user-id'
|
|
@@ -240,25 +231,10 @@ describe('RestoreManager', function () {
|
|
|
this.DocumentUpdaterHandler.promises.setDocument = sinon
|
|
this.DocumentUpdaterHandler.promises.setDocument = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
.resolves()
|
|
.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 delete the existing document', async function () {
|
|
|
|
|
- await this.RestoreManager.promises.revertFile(
|
|
|
|
|
|
|
+ it('should call setDocument in document updater and revert file', async function () {
|
|
|
|
|
+ const revertRes = await this.RestoreManager.promises.revertFile(
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.version,
|
|
this.version,
|
|
@@ -266,14 +242,15 @@ describe('RestoreManager', function () {
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
expect(
|
|
expect(
|
|
|
- this.EditorController.promises.deleteEntity
|
|
|
|
|
|
|
+ this.DocumentUpdaterHandler.promises.setDocument
|
|
|
).to.have.been.calledWith(
|
|
).to.have.been.calledWith(
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
'mock-file-id',
|
|
'mock-file-id',
|
|
|
- 'doc',
|
|
|
|
|
- 'revert',
|
|
|
|
|
- this.user_id
|
|
|
|
|
|
|
+ this.user_id,
|
|
|
|
|
+ ['foo', 'bar', 'baz'],
|
|
|
|
|
+ 'file-revert'
|
|
|
)
|
|
)
|
|
|
|
|
+ expect(revertRes).to.deep.equal({ _id: 'mock-file-id', type: 'doc' })
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -320,34 +297,7 @@ describe('RestoreManager', function () {
|
|
|
describe("when reverting a file that doesn't current exist", function () {
|
|
describe("when reverting a file that doesn't current exist", function () {
|
|
|
beforeEach(async function () {
|
|
beforeEach(async function () {
|
|
|
this.pathname = 'foo.tex'
|
|
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.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 = [
|
|
this.tracked_changes = [
|
|
|
{
|
|
{
|
|
|
op: { pos: 4, i: 'bar' },
|
|
op: { pos: 4, i: 'bar' },
|
|
@@ -358,12 +308,13 @@ describe('RestoreManager', function () {
|
|
|
metadata: { ts: '2024-01-01T00:00:00.000Z', user_id: 'user-2' },
|
|
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
|
|
this.FileSystemImportManager.promises.importFile = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
.resolves({ type: 'doc', lines: ['foo', 'bar', 'baz'] })
|
|
.resolves({ type: 'doc', lines: ['foo', 'bar', 'baz'] })
|
|
|
this.RestoreManager.promises._getRangesFromHistory = sinon
|
|
this.RestoreManager.promises._getRangesFromHistory = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .resolves({ changes: this.tracked_changes, comments: this.comments })
|
|
|
|
|
|
|
+ .resolves({ changes: this.tracked_changes, comment: this.comments })
|
|
|
this.EditorController.promises.addDocWithRanges = sinon
|
|
this.EditorController.promises.addDocWithRanges = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
.resolves(
|
|
.resolves(
|
|
@@ -385,7 +336,7 @@ describe('RestoreManager', function () {
|
|
|
this.folder_id,
|
|
this.folder_id,
|
|
|
'foo.tex',
|
|
'foo.tex',
|
|
|
['foo', 'bar', 'baz'],
|
|
['foo', 'bar', 'baz'],
|
|
|
- { changes: this.tracked_changes, comments: this.remappedComments }
|
|
|
|
|
|
|
+ { changes: this.tracked_changes, comment: this.comments }
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|