|
@@ -225,100 +225,8 @@ describe('RestoreManager', function () {
|
|
|
.rejects()
|
|
.rejects()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- describe('with an existing file in the current project', function () {
|
|
|
|
|
|
|
+ describe('reverting a document', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
- this.pathname = 'foo.tex'
|
|
|
|
|
- this.FileSystemImportManager.promises.importFile = sinon
|
|
|
|
|
- .stub()
|
|
|
|
|
- .resolves({ type: 'doc' })
|
|
|
|
|
- this.ProjectLocator.promises.findElementByPath = sinon
|
|
|
|
|
- .stub()
|
|
|
|
|
- .resolves({ type: 'doc', element: { _id: 'mock-file-id' } })
|
|
|
|
|
- this.FileSystemImportManager.promises.importFile = sinon
|
|
|
|
|
- .stub()
|
|
|
|
|
- .resolves({ type: 'doc', lines: ['foo', 'bar', 'baz'] })
|
|
|
|
|
- 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 delete the existing document', async function () {
|
|
|
|
|
- await this.RestoreManager.promises.revertFile(
|
|
|
|
|
- this.user_id,
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- this.version,
|
|
|
|
|
- this.pathname
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- expect(
|
|
|
|
|
- this.EditorController.promises.deleteEntity
|
|
|
|
|
- ).to.have.been.calledWith(
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- 'mock-file-id',
|
|
|
|
|
- 'doc',
|
|
|
|
|
- 'revert',
|
|
|
|
|
- this.user_id
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- describe('when reverting a binary file', function () {
|
|
|
|
|
- beforeEach(async function () {
|
|
|
|
|
- this.pathname = 'foo.png'
|
|
|
|
|
- this.FileSystemImportManager.promises.importFile = sinon
|
|
|
|
|
- .stub()
|
|
|
|
|
- .resolves({ type: 'file' })
|
|
|
|
|
- this.EditorController.promises.upsertFile = sinon
|
|
|
|
|
- .stub()
|
|
|
|
|
- .resolves({ _id: 'mock-file-id', type: 'file' })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should return the created entity if file exists', async function () {
|
|
|
|
|
- this.ProjectLocator.promises.findElementByPath = sinon
|
|
|
|
|
- .stub()
|
|
|
|
|
- .resolves({ type: 'file' })
|
|
|
|
|
-
|
|
|
|
|
- const revertRes = await this.RestoreManager.promises.revertFile(
|
|
|
|
|
- this.user_id,
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- this.version,
|
|
|
|
|
- this.pathname
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- expect(revertRes).to.deep.equal({ _id: 'mock-file-id', type: 'file' })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should return the created entity if file does not exists', async function () {
|
|
|
|
|
- this.ProjectLocator.promises.findElementByPath = sinon.stub().rejects()
|
|
|
|
|
-
|
|
|
|
|
- const revertRes = await this.RestoreManager.promises.revertFile(
|
|
|
|
|
- this.user_id,
|
|
|
|
|
- this.project_id,
|
|
|
|
|
- this.version,
|
|
|
|
|
- this.pathname
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- expect(revertRes).to.deep.equal({ _id: 'mock-file-id', type: 'file' })
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- describe("when reverting a file that doesn't current exist", function () {
|
|
|
|
|
- beforeEach(async function () {
|
|
|
|
|
this.pathname = 'foo.tex'
|
|
this.pathname = 'foo.tex'
|
|
|
this.comments = [
|
|
this.comments = [
|
|
|
(this.comment = { op: { t: 'comment-1', p: 0, c: 'foo' } }),
|
|
(this.comment = { op: { t: 'comment-1', p: 0, c: 'foo' } }),
|
|
@@ -341,12 +249,23 @@ describe('RestoreManager', function () {
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
- this.ChatApiHandler.promises.generateThreadData = sinon
|
|
|
|
|
- .stub()
|
|
|
|
|
- .resolves({})
|
|
|
|
|
|
|
+ this.ChatApiHandler.promises.generateThreadData = sinon.stub().resolves(
|
|
|
|
|
+ (this.threadData = {
|
|
|
|
|
+ 'comment-2': {
|
|
|
|
|
+ messages: [
|
|
|
|
|
+ {
|
|
|
|
|
+ content: 'message-content',
|
|
|
|
|
+ timestamp: '2024-01-01T00:00:00.000Z',
|
|
|
|
|
+ user_id: 'user-1',
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
|
|
+ )
|
|
|
this.ChatManager.promises.injectUserInfoIntoThreads = sinon
|
|
this.ChatManager.promises.injectUserInfoIntoThreads = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
- .resolves()
|
|
|
|
|
|
|
+ .resolves(this.threadData)
|
|
|
|
|
+
|
|
|
this.EditorRealTimeController.emitToRoom = sinon.stub()
|
|
this.EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
this.tracked_changes = [
|
|
this.tracked_changes = [
|
|
|
{
|
|
{
|
|
@@ -363,40 +282,170 @@ describe('RestoreManager', function () {
|
|
|
.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,
|
|
|
|
|
+ comments: this.comments,
|
|
|
|
|
+ })
|
|
|
this.EditorController.promises.addDocWithRanges = sinon
|
|
this.EditorController.promises.addDocWithRanges = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
.resolves(
|
|
.resolves(
|
|
|
(this.addedFile = { doc: 'mock-doc', folderId: 'mock-folder' })
|
|
(this.addedFile = { doc: 'mock-doc', folderId: 'mock-folder' })
|
|
|
)
|
|
)
|
|
|
- this.data = await this.RestoreManager.promises.revertFile(
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ describe("when reverting a file that doesn't current exist", function () {
|
|
|
|
|
+ beforeEach(async function () {
|
|
|
|
|
+ this.data = await this.RestoreManager.promises.revertFile(
|
|
|
|
|
+ this.user_id,
|
|
|
|
|
+ this.project_id,
|
|
|
|
|
+ this.version,
|
|
|
|
|
+ this.pathname
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should flush the document before fetching ranges', function () {
|
|
|
|
|
+ expect(
|
|
|
|
|
+ this.DocumentUpdaterHandler.promises.flushProjectToMongo
|
|
|
|
|
+ ).to.have.been.calledBefore(
|
|
|
|
|
+ this.DocstoreManager.promises.getAllRanges
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should import the file', function () {
|
|
|
|
|
+ expect(
|
|
|
|
|
+ this.EditorController.promises.addDocWithRanges
|
|
|
|
|
+ ).to.have.been.calledWith(
|
|
|
|
|
+ this.project_id,
|
|
|
|
|
+ this.folder_id,
|
|
|
|
|
+ 'foo.tex',
|
|
|
|
|
+ ['foo', 'bar', 'baz'],
|
|
|
|
|
+ { changes: this.tracked_changes, comments: this.remappedComments }
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should return the created entity', function () {
|
|
|
|
|
+ expect(this.data).to.equal(this.addedFile)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should look up ranges', function () {
|
|
|
|
|
+ expect(
|
|
|
|
|
+ this.RestoreManager.promises._getRangesFromHistory
|
|
|
|
|
+ ).to.have.been.calledWith(
|
|
|
|
|
+ this.project_id,
|
|
|
|
|
+ this.version,
|
|
|
|
|
+ this.pathname
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ describe('with an existing file in the current project', function () {
|
|
|
|
|
+ beforeEach(async function () {
|
|
|
|
|
+ this.ProjectLocator.promises.findElementByPath = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves({ type: 'doc', element: { _id: 'mock-file-id' } })
|
|
|
|
|
+ this.EditorController.promises.deleteEntity = sinon.stub().resolves()
|
|
|
|
|
+
|
|
|
|
|
+ this.data = await this.RestoreManager.promises.revertFile(
|
|
|
|
|
+ this.user_id,
|
|
|
|
|
+ this.project_id,
|
|
|
|
|
+ this.version,
|
|
|
|
|
+ this.pathname
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should delete the existing document', async function () {
|
|
|
|
|
+ expect(
|
|
|
|
|
+ this.EditorController.promises.deleteEntity
|
|
|
|
|
+ ).to.have.been.calledWith(
|
|
|
|
|
+ this.project_id,
|
|
|
|
|
+ 'mock-file-id',
|
|
|
|
|
+ 'doc',
|
|
|
|
|
+ 'revert',
|
|
|
|
|
+ this.user_id
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should delete the document before flushing', function () {
|
|
|
|
|
+ expect(
|
|
|
|
|
+ this.EditorController.promises.deleteEntity
|
|
|
|
|
+ ).to.have.been.calledBefore(
|
|
|
|
|
+ this.DocumentUpdaterHandler.promises.flushProjectToMongo
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should flush the document before fetching ranges', function () {
|
|
|
|
|
+ expect(
|
|
|
|
|
+ this.DocumentUpdaterHandler.promises.flushProjectToMongo
|
|
|
|
|
+ ).to.have.been.calledBefore(
|
|
|
|
|
+ this.DocstoreManager.promises.getAllRanges
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should import the file', function () {
|
|
|
|
|
+ expect(
|
|
|
|
|
+ this.EditorController.promises.addDocWithRanges
|
|
|
|
|
+ ).to.have.been.calledWith(
|
|
|
|
|
+ this.project_id,
|
|
|
|
|
+ this.folder_id,
|
|
|
|
|
+ 'foo.tex',
|
|
|
|
|
+ ['foo', 'bar', 'baz'],
|
|
|
|
|
+ { changes: this.tracked_changes, comments: this.remappedComments }
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should return the created entity', function () {
|
|
|
|
|
+ expect(this.data).to.equal(this.addedFile)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should look up ranges', function () {
|
|
|
|
|
+ expect(
|
|
|
|
|
+ this.RestoreManager.promises._getRangesFromHistory
|
|
|
|
|
+ ).to.have.been.calledWith(
|
|
|
|
|
+ this.project_id,
|
|
|
|
|
+ this.version,
|
|
|
|
|
+ this.pathname
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ describe('when reverting a binary file', function () {
|
|
|
|
|
+ beforeEach(async function () {
|
|
|
|
|
+ this.pathname = 'foo.png'
|
|
|
|
|
+ this.FileSystemImportManager.promises.importFile = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves({ type: 'file' })
|
|
|
|
|
+ this.EditorController.promises.upsertFile = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves({ _id: 'mock-file-id', type: 'file' })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should return the created entity if file exists', async function () {
|
|
|
|
|
+ this.ProjectLocator.promises.findElementByPath = sinon
|
|
|
|
|
+ .stub()
|
|
|
|
|
+ .resolves({ type: 'file' })
|
|
|
|
|
+
|
|
|
|
|
+ const revertRes = await this.RestoreManager.promises.revertFile(
|
|
|
this.user_id,
|
|
this.user_id,
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
this.version,
|
|
this.version,
|
|
|
this.pathname
|
|
this.pathname
|
|
|
)
|
|
)
|
|
|
|
|
+
|
|
|
|
|
+ expect(revertRes).to.deep.equal({ _id: 'mock-file-id', type: 'file' })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should import the file', function () {
|
|
|
|
|
- expect(
|
|
|
|
|
- this.EditorController.promises.addDocWithRanges
|
|
|
|
|
- ).to.have.been.calledWith(
|
|
|
|
|
|
|
+ it('should return the created entity if file does not exists', async function () {
|
|
|
|
|
+ this.ProjectLocator.promises.findElementByPath = sinon.stub().rejects()
|
|
|
|
|
+
|
|
|
|
|
+ const revertRes = await this.RestoreManager.promises.revertFile(
|
|
|
|
|
+ this.user_id,
|
|
|
this.project_id,
|
|
this.project_id,
|
|
|
- this.folder_id,
|
|
|
|
|
- 'foo.tex',
|
|
|
|
|
- ['foo', 'bar', 'baz'],
|
|
|
|
|
- { changes: this.tracked_changes, comments: this.remappedComments }
|
|
|
|
|
|
|
+ this.version,
|
|
|
|
|
+ this.pathname
|
|
|
)
|
|
)
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should return the created entity', function () {
|
|
|
|
|
- expect(this.data).to.equal(this.addedFile)
|
|
|
|
|
- })
|
|
|
|
|
|
|
|
|
|
- it('should look up ranges', function () {
|
|
|
|
|
- expect(
|
|
|
|
|
- this.RestoreManager.promises._getRangesFromHistory
|
|
|
|
|
- ).to.have.been.calledWith(this.project_id, this.version, this.pathname)
|
|
|
|
|
|
|
+ expect(revertRes).to.deep.equal({ _id: 'mock-file-id', type: 'file' })
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|