Merge pull request #5984 from overleaf/em-unnecessarily-async-functions

Clean up unnecessarily async functions

GitOrigin-RevId: 59f0f0a76b4436f3b99a09b747670d443bac4582
This commit is contained in:
Eric Mc Sween
2021-12-06 10:27:12 -05:00
committed by Copybot
parent d27918bf40
commit b22df1dcba
13 changed files with 268 additions and 404 deletions
@@ -1743,7 +1743,7 @@ describe('ProjectController', function () {
.callsArgWith(1, null, this.project)
this.ProjectEntityHandler.getAllEntitiesFromProject = sinon
.stub()
.callsArgWith(1, null, this.docs, this.files)
.returns({ docs: this.docs, files: this.files })
})
it('should produce a list of entities', function (done) {
@@ -161,18 +161,19 @@ describe('ProjectEntityHandler', function () {
rev: (this.rev2 = 2),
},
]
this.callback = sinon.stub()
this.ProjectEntityHandler.getAllDocPathsFromProject(
this.project,
this.callback
)
})
it('should call the callback with the path for each docId', function () {
this.expected = {}
this.expected[this.doc1._id] = `/${this.doc1.name}`
this.expected[this.doc2._id] = `/folder1/${this.doc2.name}`
this.callback.calledWith(null, this.expected).should.equal(true)
const expected = {
[this.doc1._id]: `/${this.doc1.name}`,
[this.doc2._id]: `/folder1/${this.doc2.name}`,
}
expect(
this.ProjectEntityHandler.getAllDocPathsFromProject(
this.project,
this.callback
)
).to.deep.equal(expected)
})
})
@@ -254,13 +255,13 @@ describe('ProjectEntityHandler', function () {
)
})
it('should call the callback with the folders', function () {
this.callback
.calledWith(null, [
{ path: '/', folder: this.project.rootFolder[0] },
{ path: '/folder1', folder: this.folder1 },
])
.should.equal(true)
it('should return the folders', function () {
expect(
this.ProjectEntityHandler._getAllFoldersFromProject(this.project)
).to.deep.equal([
{ path: '/', folder: this.project.rootFolder[0] },
{ path: '/folder1', folder: this.folder1 },
])
})
})
})
@@ -74,9 +74,7 @@ describe('ProjectEntityMongoUpdateHandler', function () {
this.DeletedFileMock = sinon.mock(DeletedFile)
this.ProjectMock = sinon.mock(Project)
this.ProjectEntityHandler = {
promises: {
getAllEntitiesFromProject: sinon.stub(),
},
getAllEntitiesFromProject: sinon.stub(),
}
this.ProjectLocator = {
promises: {
@@ -635,12 +633,12 @@ describe('ProjectEntityMongoUpdateHandler', function () {
this.newDocs = ['new-doc']
this.newFiles = ['new-file']
this.ProjectEntityHandler.promises.getAllEntitiesFromProject
this.ProjectEntityHandler.getAllEntitiesFromProject
.onFirstCall()
.resolves({ docs: this.oldDocs, files: this.oldFiles })
this.ProjectEntityHandler.promises.getAllEntitiesFromProject
.returns({ docs: this.oldDocs, files: this.oldFiles })
this.ProjectEntityHandler.getAllEntitiesFromProject
.onSecondCall()
.resolves({ docs: this.newDocs, files: this.newFiles })
.returns({ docs: this.newDocs, files: this.newFiles })
this.ProjectMock.expects('findOneAndUpdate')
.withArgs(
@@ -751,12 +749,12 @@ describe('ProjectEntityMongoUpdateHandler', function () {
this.newDocs = ['new-doc']
this.newFiles = ['new-file']
this.ProjectEntityHandler.promises.getAllEntitiesFromProject
this.ProjectEntityHandler.getAllEntitiesFromProject
.onFirstCall()
.resolves({ docs: this.oldDocs, files: this.oldFiles })
this.ProjectEntityHandler.promises.getAllEntitiesFromProject
.returns({ docs: this.oldDocs, files: this.oldFiles })
this.ProjectEntityHandler.getAllEntitiesFromProject
.onSecondCall()
.resolves({ docs: this.newDocs, files: this.newFiles })
.returns({ docs: this.newDocs, files: this.newFiles })
this.ProjectMock.expects('findOneAndUpdate')
.withArgs(
@@ -1932,12 +1932,12 @@ describe('ProjectEntityUpdateHandler', function () {
path: 'universe.png',
},
]
this.ProjectEntityHandler.getAllEntitiesFromProject.yields(
null,
const folders = []
this.ProjectEntityHandler.getAllEntitiesFromProject.returns({
docs,
files,
[]
)
folders,
})
this.ProjectEntityUpdateHandler.resyncProjectHistory(
projectId,
this.callback
@@ -2019,12 +2019,11 @@ describe('ProjectEntityUpdateHandler', function () {
path: 'another dupe (22)',
},
]
this.ProjectEntityHandler.getAllEntitiesFromProject.yields(
null,
this.docs,
this.files,
[]
)
this.ProjectEntityHandler.getAllEntitiesFromProject.returns({
docs: this.docs,
files: this.files,
folders: [],
})
this.ProjectEntityUpdateHandler.resyncProjectHistory(projectId, done)
})
@@ -2121,12 +2120,11 @@ describe('ProjectEntityUpdateHandler', function () {
path: 'A_.png',
},
]
this.ProjectEntityHandler.getAllEntitiesFromProject.yields(
null,
this.docs,
this.files,
[]
)
this.ProjectEntityHandler.getAllEntitiesFromProject.returns({
docs: this.docs,
files: this.files,
folders: [],
})
this.ProjectEntityUpdateHandler.resyncProjectHistory(projectId, done)
})
@@ -2209,12 +2207,11 @@ describe('ProjectEntityUpdateHandler', function () {
},
]
const files = []
this.ProjectEntityHandler.getAllEntitiesFromProject.yields(
null,
this.ProjectEntityHandler.getAllEntitiesFromProject.returns({
docs,
files,
folders
)
folders,
})
this.ProjectEntityUpdateHandler.resyncProjectHistory(projectId, done)
})
@@ -2261,12 +2258,11 @@ describe('ProjectEntityUpdateHandler', function () {
},
]
const files = []
this.ProjectEntityHandler.getAllEntitiesFromProject.yields(
null,
this.ProjectEntityHandler.getAllEntitiesFromProject.returns({
docs,
files,
folders
)
folders,
})
this.ProjectEntityUpdateHandler.resyncProjectHistory(projectId, done)
})