| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869 |
- const SandboxedModule = require('sandboxed-module')
- const sinon = require('sinon')
- const modulePath = require('path').join(
- __dirname,
- '../../../../app/src/Features/History/RestoreManager'
- )
- const Errors = require('../../../../app/src/Features/Errors/Errors')
- const tk = require('timekeeper')
- const moment = require('moment')
- const { expect } = require('chai')
- describe('RestoreManager', function () {
- beforeEach(function () {
- tk.freeze(Date.now()) // freeze the time for these tests
- this.RestoreManager = SandboxedModule.require(modulePath, {
- requires: {
- '@overleaf/settings': {},
- '../../infrastructure/FileWriter': (this.FileWriter = { promises: {} }),
- '../Uploads/FileSystemImportManager': (this.FileSystemImportManager = {
- promises: {},
- }),
- '../Editor/EditorController': (this.EditorController = {
- promises: {},
- }),
- '../Project/ProjectLocator': (this.ProjectLocator = { promises: {} }),
- '../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 =
- {}),
- '../Project/ProjectGetter': (this.ProjectGetter = { promises: {} }),
- '../Project/ProjectEntityHandler': (this.ProjectEntityHandler = {
- promises: {},
- }),
- },
- })
- this.user_id = 'mock-user-id'
- this.project_id = 'mock-project-id'
- this.version = 42
- })
- afterEach(function () {
- tk.reset()
- })
- describe('restoreFileFromV2', function () {
- beforeEach(function () {
- this.RestoreManager.promises._writeFileVersionToDisk = sinon
- .stub()
- .resolves((this.fsPath = '/tmp/path/on/disk'))
- this.RestoreManager.promises._findOrCreateFolder = sinon
- .stub()
- .resolves((this.folder_id = 'mock-folder-id'))
- this.FileSystemImportManager.promises.addEntity = sinon
- .stub()
- .resolves((this.entity = 'mock-entity'))
- })
- describe('with a file not in a folder', function () {
- beforeEach(async function () {
- this.pathname = 'foo.tex'
- this.result = await this.RestoreManager.promises.restoreFileFromV2(
- this.user_id,
- this.project_id,
- this.version,
- this.pathname
- )
- })
- it('should write the file version to disk', function () {
- this.RestoreManager.promises._writeFileVersionToDisk
- .calledWith(this.project_id, this.version, this.pathname)
- .should.equal(true)
- })
- it('should find the root folder', function () {
- this.RestoreManager.promises._findOrCreateFolder
- .calledWith(this.project_id, '', this.user_id)
- .should.equal(true)
- })
- it('should add the entity', function () {
- this.FileSystemImportManager.promises.addEntity
- .calledWith(
- this.user_id,
- this.project_id,
- this.folder_id,
- 'foo.tex',
- this.fsPath,
- false
- )
- .should.equal(true)
- })
- it('should return the entity', function () {
- expect(this.result).to.equal(this.entity)
- })
- })
- describe('with a file in a folder', function () {
- beforeEach(async function () {
- this.pathname = 'foo/bar.tex'
- await this.RestoreManager.promises.restoreFileFromV2(
- this.user_id,
- this.project_id,
- this.version,
- this.pathname
- )
- })
- it('should find the folder', function () {
- this.RestoreManager.promises._findOrCreateFolder
- .calledWith(this.project_id, 'foo', this.user_id)
- .should.equal(true)
- })
- it('should add the entity by its basename', function () {
- this.FileSystemImportManager.promises.addEntity
- .calledWith(
- this.user_id,
- this.project_id,
- this.folder_id,
- 'bar.tex',
- this.fsPath,
- false
- )
- .should.equal(true)
- })
- })
- })
- describe('_findOrCreateFolder', function () {
- beforeEach(async function () {
- this.EditorController.promises.mkdirp = sinon.stub().resolves({
- newFolders: [],
- lastFolder: { _id: (this.folder_id = 'mock-folder-id') },
- })
- this.result = await this.RestoreManager.promises._findOrCreateFolder(
- this.project_id,
- 'folder/name',
- this.user_id
- )
- })
- it('should look up or create the folder', function () {
- this.EditorController.promises.mkdirp
- .calledWith(this.project_id, 'folder/name', this.user_id)
- .should.equal(true)
- })
- it('should return the folder_id', function () {
- expect(this.result).to.equal(this.folder_id)
- })
- })
- describe('_addEntityWithUniqueName', function () {
- beforeEach(function () {
- this.addEntityWithName = sinon.stub()
- this.name = 'foo.tex'
- })
- describe('with a valid name', function () {
- beforeEach(async function () {
- this.addEntityWithName.resolves((this.entity = 'mock-entity'))
- this.result =
- await this.RestoreManager.promises._addEntityWithUniqueName(
- this.addEntityWithName,
- this.name
- )
- })
- it('should add the entity', function () {
- this.addEntityWithName.calledWith(this.name).should.equal(true)
- })
- it('should return the entity', function () {
- expect(this.result).to.equal(this.entity)
- })
- })
- describe('with a duplicate name', function () {
- beforeEach(async function () {
- this.addEntityWithName.rejects(new Errors.DuplicateNameError())
- this.addEntityWithName
- .onSecondCall()
- .resolves((this.entity = 'mock-entity'))
- this.result =
- await this.RestoreManager.promises._addEntityWithUniqueName(
- this.addEntityWithName,
- this.name
- )
- })
- it('should try to add the entity with its original name', function () {
- this.addEntityWithName.calledWith('foo.tex').should.equal(true)
- })
- it('should try to add the entity with a unique name', function () {
- const date = moment(new Date()).format('Do MMM YY H:mm:ss')
- this.addEntityWithName
- .calledWith(`foo (Restored on ${date}).tex`)
- .should.equal(true)
- })
- it('should return the entity', function () {
- expect(this.result).to.equal(this.entity)
- })
- })
- })
- describe('revertFile', function () {
- beforeEach(function () {
- this.ProjectGetter.promises.getProject = sinon.stub()
- this.ProjectGetter.promises.getProject
- .withArgs(this.project_id)
- .resolves({ overleaf: { history: { rangesSupportEnabled: true } } })
- this.RestoreManager.promises._writeFileVersionToDisk = sinon
- .stub()
- .resolves((this.fsPath = '/tmp/path/on/disk'))
- this.RestoreManager.promises._findOrCreateFolder = sinon
- .stub()
- .resolves((this.folder_id = 'mock-folder-id'))
- this.FileSystemImportManager.promises.addEntity = sinon
- .stub()
- .resolves((this.entity = 'mock-entity'))
- this.RestoreManager.promises._getRangesFromHistory = sinon
- .stub()
- .rejects()
- this.RestoreManager.promises._getMetadataFromHistory = sinon
- .stub()
- .resolves({ metadata: undefined })
- })
- describe('reverting a project without ranges support', function () {
- beforeEach(function () {
- this.ProjectGetter.promises.getProject = sinon.stub().resolves({
- overleaf: { history: { rangesSupportEnabled: false } },
- })
- })
- it('should throw an error', async function () {
- await expect(
- this.RestoreManager.promises.revertFile(
- this.user_id,
- this.project_id,
- this.version,
- this.pathname
- )
- ).to.eventually.be.rejectedWith('project does not have ranges support')
- })
- })
- describe('reverting a document with ranges', function () {
- beforeEach(function () {
- this.pathname = 'foo.tex'
- this.comments = [
- { op: { t: 'comment-in-other-doc', p: 0, c: 'foo' } },
- { op: { t: 'single-comment', p: 10, c: 'bar' } },
- { op: { t: 'deleted-comment', p: 20, c: 'baz' } },
- ]
- this.remappedComments = [
- { op: { t: 'duplicate-comment', p: 0, c: 'foo' } },
- { op: { t: 'single-comment', p: 10, c: 'bar' } },
- ]
- this.ProjectLocator.promises.findElementByPath = sinon.stub().rejects()
- this.DocstoreManager.promises.getAllRanges = sinon.stub().resolves([
- {
- ranges: {
- comments: this.comments.slice(0, 1),
- },
- },
- ])
- this.ChatApiHandler.promises.duplicateCommentThreads = sinon
- .stub()
- .resolves({
- newThreads: {
- 'comment-in-other-doc': {
- duplicateId: 'duplicate-comment',
- },
- },
- })
- this.ChatApiHandler.promises.generateThreadData = sinon.stub().resolves(
- (this.threadData = {
- 'single-comment': {
- messages: [
- {
- content: 'message-content',
- timestamp: '2024-01-01T00:00:00.000Z',
- user_id: 'user-1',
- },
- ],
- },
- 'duplicate-comment': {
- messages: [
- {
- content: 'another message',
- timestamp: '2024-01-01T00:00:00.000Z',
- user_id: 'user-1',
- },
- ],
- },
- })
- )
- this.ChatManager.promises.injectUserInfoIntoThreads = sinon
- .stub()
- .resolves(this.threadData)
- this.EditorRealTimeController.emitToRoom = sinon.stub()
- this.tracked_changes = [
- {
- op: { pos: 4, i: 'bar' },
- metadata: { ts: '2024-01-01T00:00:00.000Z', user_id: 'user-1' },
- },
- {
- op: { pos: 8, d: 'qux' },
- metadata: { ts: '2024-01-01T00:00:00.000Z', user_id: 'user-2' },
- },
- ]
- this.FileSystemImportManager.promises.importFile = sinon
- .stub()
- .resolves({ type: 'doc', lines: ['foo', 'bar', 'baz'] })
- this.RestoreManager.promises._getRangesFromHistory = sinon
- .stub()
- .resolves({
- changes: this.tracked_changes,
- comments: this.comments,
- })
- this.RestoreManager.promises._getUpdatesFromHistory = sinon
- .stub()
- .resolves([
- { toV: this.version, meta: { end_ts: (this.endTs = new Date()) } },
- ])
- this.EditorController.promises.addDocWithRanges = sinon
- .stub()
- .resolves((this.addedFile = { _id: 'mock-doc', type: 'doc' }))
- })
- 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.deep.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: 'file', 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 file', async function () {
- expect(
- this.EditorController.promises.deleteEntity
- ).to.have.been.calledWith(
- this.project_id,
- 'mock-file-id',
- 'file',
- {
- kind: 'file-restore',
- path: this.pathname,
- version: this.version,
- timestamp: new Date(this.endTs).toISOString(),
- },
- this.user_id
- )
- })
- })
- describe('with an existing document 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',
- {
- kind: 'file-restore',
- path: this.pathname,
- version: this.version,
- timestamp: new Date(this.endTs).toISOString(),
- },
- 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 },
- {
- kind: 'file-restore',
- path: this.pathname,
- version: this.version,
- timestamp: new Date(this.endTs).toISOString(),
- }
- )
- })
- it('should return the created entity', function () {
- expect(this.data).to.deep.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('reverting a file or document with metadata', function () {
- beforeEach(function () {
- this.ProjectLocator.promises.findElementByPath = sinon.stub().rejects()
- this.EditorController.promises.addDocWithRanges = sinon.stub()
- this.RestoreManager.promises._getUpdatesFromHistory = sinon
- .stub()
- .resolves([
- { toV: this.version, meta: { end_ts: (this.endTs = new Date()) } },
- ])
- this.EditorController.promises.upsertFile = sinon
- .stub()
- .resolves({ _id: 'mock-file-id', type: 'file' })
- this.RestoreManager.promises._getRangesFromHistory = sinon
- .stub()
- .resolves({
- changes: [],
- comments: [],
- })
- this.EditorController.promises.addDocWithRanges = sinon
- .stub()
- .resolves((this.addedFile = { _id: 'mock-doc-id', type: 'doc' }))
- 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()
- })
- describe('when reverting a linked file', function () {
- beforeEach(async function () {
- this.pathname = 'foo.png'
- this.FileSystemImportManager.promises.importFile = sinon
- .stub()
- .resolves({ type: 'file' })
- this.RestoreManager.promises._getMetadataFromHistory = sinon
- .stub()
- .resolves({ metadata: { provider: 'bar' } })
- this.result = await this.RestoreManager.promises.revertFile(
- this.user_id,
- this.project_id,
- this.version,
- this.pathname
- )
- })
- it('should revert it as a file', function () {
- expect(this.result).to.deep.equal({
- _id: 'mock-file-id',
- type: 'file',
- })
- })
- it('should upload to the project as a file', function () {
- expect(
- this.EditorController.promises.upsertFile
- ).to.have.been.calledWith(
- this.project_id,
- 'mock-folder-id',
- 'foo.png',
- this.fsPath,
- { provider: 'bar' },
- {
- kind: 'file-restore',
- path: this.pathname,
- version: this.version,
- timestamp: new Date(this.endTs).toISOString(),
- },
- this.user_id
- )
- })
- it('should not look up ranges', function () {
- expect(this.RestoreManager.promises._getRangesFromHistory).to.not.have
- .been.called
- })
- it('should not try to add a document', function () {
- expect(this.EditorController.promises.addDocWithRanges).to.not.have
- .been.called
- })
- })
- describe('when reverting a linked document with provider', function () {
- beforeEach(async function () {
- this.pathname = 'foo.tex'
- this.FileSystemImportManager.promises.importFile = sinon
- .stub()
- .resolves({ type: 'doc', lines: ['foo', 'bar', 'baz'] })
- this.RestoreManager.promises._getMetadataFromHistory = sinon
- .stub()
- .resolves({ metadata: { provider: 'bar' } })
- this.result = await this.RestoreManager.promises.revertFile(
- this.user_id,
- this.project_id,
- this.version,
- this.pathname
- )
- })
- it('should revert it as a file', function () {
- expect(this.result).to.deep.equal({
- _id: 'mock-file-id',
- type: 'file',
- })
- })
- it('should upload to the project as a file', function () {
- expect(
- this.EditorController.promises.upsertFile
- ).to.have.been.calledWith(
- this.project_id,
- 'mock-folder-id',
- 'foo.tex',
- this.fsPath,
- { provider: 'bar' },
- {
- kind: 'file-restore',
- path: this.pathname,
- version: this.version,
- timestamp: new Date(this.endTs).toISOString(),
- },
- this.user_id
- )
- })
- it('should not look up ranges', function () {
- expect(this.RestoreManager.promises._getRangesFromHistory).to.not.have
- .been.called
- })
- it('should not try to add a document', function () {
- expect(this.EditorController.promises.addDocWithRanges).to.not.have
- .been.called
- })
- })
- describe('when reverting a linked document with { main: true }', function () {
- beforeEach(async function () {
- this.pathname = 'foo.tex'
- this.FileSystemImportManager.promises.importFile = sinon
- .stub()
- .resolves({ type: 'doc', lines: ['foo', 'bar', 'baz'] })
- this.RestoreManager.promises._getMetadataFromHistory = sinon
- .stub()
- .resolves({ metadata: { main: true } })
- this.result = await this.RestoreManager.promises.revertFile(
- this.user_id,
- this.project_id,
- this.version,
- this.pathname
- )
- })
- it('should revert it as a document', function () {
- expect(this.result).to.deep.equal({
- _id: 'mock-doc-id',
- type: 'doc',
- })
- })
- it('should not upload to the project as a file', function () {
- expect(this.EditorController.promises.upsertFile).to.not.have.been
- .called
- })
- it('should look up ranges', function () {
- expect(this.RestoreManager.promises._getRangesFromHistory).to.have
- .been.called
- })
- it('should add the document', function () {
- expect(
- this.EditorController.promises.addDocWithRanges
- ).to.have.been.calledWith(
- this.project_id,
- this.folder_id,
- 'foo.tex',
- ['foo', 'bar', 'baz'],
- { changes: [], comments: [] }
- )
- })
- })
- })
- 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' })
- this.EditorController.promises.deleteEntity = sinon.stub().resolves()
- this.RestoreManager.promises._getUpdatesFromHistory = sinon
- .stub()
- .resolves([{ toV: this.version, meta: { end_ts: Date.now() } }])
- })
- it('should return the created entity if file exists', async function () {
- this.ProjectLocator.promises.findElementByPath = sinon
- .stub()
- .resolves({ type: 'file', element: { _id: 'existing-file-id' } })
- 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('revertProject', function () {
- beforeEach(function () {
- this.ProjectGetter.promises.getProject = sinon.stub()
- this.ProjectGetter.promises.getProject
- .withArgs(this.project_id)
- .resolves({ overleaf: { history: { rangesSupportEnabled: true } } })
- this.RestoreManager.promises.revertFile = sinon.stub().resolves()
- this.RestoreManager.promises._getProjectPathsAtVersion = sinon
- .stub()
- .resolves([])
- this.ProjectEntityHandler.promises.getAllEntities = sinon
- .stub()
- .resolves({ docs: [], files: [] })
- this.EditorController.promises.deleteEntityWithPath = sinon
- .stub()
- .resolves()
- this.RestoreManager.promises._getUpdatesFromHistory = sinon
- .stub()
- .resolves([
- { toV: this.version, meta: { end_ts: (this.end_ts = Date.now()) } },
- ])
- })
- describe('reverting a project without ranges support', function () {
- beforeEach(function () {
- this.ProjectGetter.promises.getProject = sinon.stub().resolves({
- overleaf: { history: { rangesSupportEnabled: false } },
- })
- })
- it('should throw an error', async function () {
- await expect(
- this.RestoreManager.promises.revertProject(
- this.user_id,
- this.project_id,
- this.version
- )
- ).to.eventually.be.rejectedWith('project does not have ranges support')
- })
- })
- describe('for a project with overlap in current files and old files', function () {
- beforeEach(async function () {
- this.ProjectEntityHandler.promises.getAllEntities = sinon
- .stub()
- .resolves({
- docs: [{ path: '/main.tex' }, { path: '/new-file.tex' }],
- files: [{ path: '/figures/image.png' }],
- })
- this.RestoreManager.promises._getProjectPathsAtVersion = sinon
- .stub()
- .resolves(['main.tex', 'figures/image.png', 'since-deleted.tex'])
- await this.RestoreManager.promises.revertProject(
- this.user_id,
- this.project_id,
- this.version
- )
- this.origin = {
- kind: 'project-restore',
- version: this.version,
- timestamp: new Date(this.end_ts).toISOString(),
- }
- })
- it('should delete the old files', function () {
- expect(
- this.EditorController.promises.deleteEntityWithPath
- ).to.have.been.calledWith(
- this.project_id,
- 'new-file.tex',
- this.origin,
- this.user_id
- )
- })
- it('should not delete the current files', function () {
- expect(
- this.EditorController.promises.deleteEntityWithPath
- ).to.not.have.been.calledWith(
- this.project_id,
- 'main.tex',
- this.origin,
- this.user_id
- )
- expect(
- this.EditorController.promises.deleteEntityWithPath
- ).to.not.have.been.calledWith(
- this.project_id,
- 'figures/image.png',
- this.origin,
- this.user_id
- )
- })
- it('should revert the old files', function () {
- expect(this.RestoreManager.promises.revertFile).to.have.been.calledWith(
- this.user_id,
- this.project_id,
- this.version,
- 'main.tex'
- )
- expect(this.RestoreManager.promises.revertFile).to.have.been.calledWith(
- this.user_id,
- this.project_id,
- this.version,
- 'figures/image.png'
- )
- expect(this.RestoreManager.promises.revertFile).to.have.been.calledWith(
- this.user_id,
- this.project_id,
- this.version,
- 'since-deleted.tex'
- )
- })
- it('should not revert the current files', function () {
- expect(
- this.RestoreManager.promises.revertFile
- ).to.not.have.been.calledWith(
- this.user_id,
- this.project_id,
- this.version,
- 'new-file.tex'
- )
- })
- })
- })
- })
|