Merge pull request #5984 from overleaf/em-unnecessarily-async-functions
Clean up unnecessarily async functions GitOrigin-RevId: 59f0f0a76b4436f3b99a09b747670d443bac4582
This commit is contained in:
@@ -13,7 +13,7 @@ describe('ClsiManager', function () {
|
||||
_getServerId: sinon.stub(),
|
||||
}
|
||||
this.ClsiStateManager = {
|
||||
computeHash: sinon.stub().callsArgWith(2, null, '01234567890abcdef'),
|
||||
computeHash: sinon.stub().returns('01234567890abcdef'),
|
||||
}
|
||||
this.ClsiFormatChecker = {
|
||||
checkRecoursesForProblems: sinon.stub().callsArgWith(1),
|
||||
@@ -645,13 +645,10 @@ describe('ClsiManager', function () {
|
||||
|
||||
describe('with the incremental compile option', function () {
|
||||
beforeEach(function (done) {
|
||||
this.project_state_hash = '01234567890abcdef'
|
||||
this.ClsiStateManager.computeHash = sinon
|
||||
.stub()
|
||||
.callsArgWith(
|
||||
2,
|
||||
null,
|
||||
(this.project_state_hash = '01234567890abcdef')
|
||||
)
|
||||
.returns(this.project_state_hash)
|
||||
this.DocumentUpdaterHandler.getProjectDocsIfMatch = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, [
|
||||
@@ -659,7 +656,7 @@ describe('ClsiManager', function () {
|
||||
])
|
||||
this.ProjectEntityHandler.getAllDocPathsFromProject = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, { 'mock-doc-id-1': 'main.tex' })
|
||||
.returns({ 'mock-doc-id-1': 'main.tex' })
|
||||
this.ClsiManager._buildRequest(
|
||||
this.project_id,
|
||||
{
|
||||
@@ -732,13 +729,10 @@ describe('ClsiManager', function () {
|
||||
|
||||
describe('when the root doc is set and not in the docupdater', function () {
|
||||
beforeEach(function (done) {
|
||||
this.project_state_hash = '01234567890abcdef'
|
||||
this.ClsiStateManager.computeHash = sinon
|
||||
.stub()
|
||||
.callsArgWith(
|
||||
2,
|
||||
null,
|
||||
(this.project_state_hash = '01234567890abcdef')
|
||||
)
|
||||
.returns(this.project_state_hash)
|
||||
this.DocumentUpdaterHandler.getProjectDocsIfMatch = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, [
|
||||
@@ -746,7 +740,7 @@ describe('ClsiManager', function () {
|
||||
])
|
||||
this.ProjectEntityHandler.getAllDocPathsFromProject = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, {
|
||||
.returns({
|
||||
'mock-doc-id-1': 'main.tex',
|
||||
'mock-doc-id-2': '/chapters/chapter1.tex',
|
||||
})
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('ClsiStateManager', function () {
|
||||
})
|
||||
|
||||
describe('computeHash', function () {
|
||||
beforeEach(function (done) {
|
||||
beforeEach(function () {
|
||||
this.docs = [
|
||||
{ path: '/main.tex', doc: { _id: 'doc-id-1' } },
|
||||
{ path: '/folder/sub.tex', doc: { _id: 'doc-id-2' } },
|
||||
@@ -48,30 +48,17 @@ describe('ClsiStateManager', function () {
|
||||
]
|
||||
this.ProjectEntityHandler.getAllEntitiesFromProject = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, this.docs, this.files)
|
||||
return this.ClsiStateManager.computeHash(
|
||||
this.project,
|
||||
this.options,
|
||||
(err, hash) => {
|
||||
this.hash0 = hash
|
||||
return done()
|
||||
}
|
||||
)
|
||||
.returns({ docs: this.docs, files: this.files })
|
||||
this.hash0 = this.ClsiStateManager.computeHash(this.project, this.options)
|
||||
})
|
||||
|
||||
describe('with a sample project', function () {
|
||||
beforeEach(function () {
|
||||
return this.ClsiStateManager.computeHash(
|
||||
this.project,
|
||||
this.options,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
beforeEach(function () {})
|
||||
|
||||
it('should call the callback with a hash value', function () {
|
||||
return this.callback
|
||||
.calledWith(null, '21b1ab73aa3892bec452baf8ffa0956179e1880f')
|
||||
.should.equal(true)
|
||||
it('should return a hash value', function () {
|
||||
expect(
|
||||
this.ClsiStateManager.computeHash(this.project, this.options)
|
||||
).to.equal('21b1ab73aa3892bec452baf8ffa0956179e1880f')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -82,213 +69,135 @@ describe('ClsiStateManager', function () {
|
||||
this.files[1],
|
||||
this.files[0],
|
||||
])
|
||||
return this.ClsiStateManager.computeHash(
|
||||
this.project,
|
||||
this.options,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with the same hash value', function () {
|
||||
return this.callback.calledWith(null, this.hash0).should.equal(true)
|
||||
it('should return the same hash value', function () {
|
||||
expect(
|
||||
this.ClsiStateManager.computeHash(this.project, this.options)
|
||||
).to.equal(this.hash0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a doc is renamed', function () {
|
||||
beforeEach(function (done) {
|
||||
beforeEach(function () {
|
||||
this.docs[0].path = '/new.tex'
|
||||
return this.ClsiStateManager.computeHash(
|
||||
this.project,
|
||||
this.options,
|
||||
(err, hash) => {
|
||||
this.hash1 = hash
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a different hash value', function () {
|
||||
return this.callback
|
||||
.neverCalledWith(null, this.hash0)
|
||||
.should.equal(true)
|
||||
it('should return a different hash value', function () {
|
||||
expect(
|
||||
this.ClsiStateManager.computeHash(this.project, this.options)
|
||||
).not.to.equal(this.hash0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a file is renamed', function () {
|
||||
beforeEach(function (done) {
|
||||
beforeEach(function () {
|
||||
this.files[0].path = '/newfigure.pdf'
|
||||
return this.ClsiStateManager.computeHash(
|
||||
this.project,
|
||||
this.options,
|
||||
(err, hash) => {
|
||||
this.hash1 = hash
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a different hash value', function () {
|
||||
return this.callback
|
||||
.neverCalledWith(null, this.hash0)
|
||||
.should.equal(true)
|
||||
it('should return a different hash value', function () {
|
||||
expect(
|
||||
this.ClsiStateManager.computeHash(this.project, this.options)
|
||||
).not.to.equal(this.hash0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a doc is added', function () {
|
||||
beforeEach(function (done) {
|
||||
beforeEach(function () {
|
||||
this.docs.push({ path: '/newdoc.tex', doc: { _id: 'newdoc-id' } })
|
||||
return this.ClsiStateManager.computeHash(
|
||||
this.project,
|
||||
this.options,
|
||||
(err, hash) => {
|
||||
this.hash1 = hash
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a different hash value', function () {
|
||||
return this.callback
|
||||
.neverCalledWith(null, this.hash0)
|
||||
.should.equal(true)
|
||||
it('should return a different hash value', function () {
|
||||
expect(
|
||||
this.ClsiStateManager.computeHash(this.project, this.options)
|
||||
).not.to.equal(this.hash0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a file is added', function () {
|
||||
beforeEach(function (done) {
|
||||
beforeEach(function () {
|
||||
this.files.push({
|
||||
path: '/newfile.tex',
|
||||
file: { _id: 'newfile-id', rev: 123 },
|
||||
})
|
||||
return this.ClsiStateManager.computeHash(
|
||||
this.project,
|
||||
this.options,
|
||||
(err, hash) => {
|
||||
this.hash1 = hash
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a different hash value', function () {
|
||||
return this.callback
|
||||
.neverCalledWith(null, this.hash0)
|
||||
.should.equal(true)
|
||||
it('should return a different hash value', function () {
|
||||
expect(
|
||||
this.ClsiStateManager.computeHash(this.project, this.options)
|
||||
).not.to.equal(this.hash0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a doc is removed', function () {
|
||||
beforeEach(function (done) {
|
||||
beforeEach(function () {
|
||||
this.docs.pop()
|
||||
return this.ClsiStateManager.computeHash(
|
||||
this.project,
|
||||
this.options,
|
||||
(err, hash) => {
|
||||
this.hash1 = hash
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a different hash value', function () {
|
||||
return this.callback
|
||||
.neverCalledWith(null, this.hash0)
|
||||
.should.equal(true)
|
||||
it('should return a different hash value', function () {
|
||||
expect(
|
||||
this.ClsiStateManager.computeHash(this.project, this.options)
|
||||
).not.to.equal(this.hash0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a file is removed', function () {
|
||||
beforeEach(function (done) {
|
||||
beforeEach(function () {
|
||||
this.files.pop()
|
||||
return this.ClsiStateManager.computeHash(
|
||||
this.project,
|
||||
this.options,
|
||||
(err, hash) => {
|
||||
this.hash1 = hash
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a different hash value', function () {
|
||||
return this.callback
|
||||
.neverCalledWith(null, this.hash0)
|
||||
.should.equal(true)
|
||||
it('should return a different hash value', function () {
|
||||
expect(
|
||||
this.ClsiStateManager.computeHash(this.project, this.options)
|
||||
).not.to.equal(this.hash0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when a file's revision is updated", function () {
|
||||
beforeEach(function (done) {
|
||||
beforeEach(function () {
|
||||
this.files[0].file.rev++
|
||||
return this.ClsiStateManager.computeHash(
|
||||
this.project,
|
||||
this.options,
|
||||
(err, hash) => {
|
||||
this.hash1 = hash
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a different hash value', function () {
|
||||
return this.callback
|
||||
.neverCalledWith(null, this.hash0)
|
||||
.should.equal(true)
|
||||
it('should return a different hash value', function () {
|
||||
expect(
|
||||
this.ClsiStateManager.computeHash(this.project, this.options)
|
||||
).not.to.equal(this.hash0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when a file's date is updated", function () {
|
||||
beforeEach(function (done) {
|
||||
beforeEach(function () {
|
||||
this.files[0].file.created = 'zzzzzz'
|
||||
return this.ClsiStateManager.computeHash(
|
||||
this.project,
|
||||
this.options,
|
||||
(err, hash) => {
|
||||
this.hash1 = hash
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a different hash value', function () {
|
||||
return this.callback
|
||||
.neverCalledWith(null, this.hash0)
|
||||
.should.equal(true)
|
||||
it('should return a different hash value', function () {
|
||||
expect(
|
||||
this.ClsiStateManager.computeHash(this.project, this.options)
|
||||
).not.to.equal(this.hash0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the compile options are changed', function () {
|
||||
beforeEach(function (done) {
|
||||
beforeEach(function () {
|
||||
this.options.draft = !this.options.draft
|
||||
return this.ClsiStateManager.computeHash(
|
||||
this.project,
|
||||
this.options,
|
||||
(err, hash) => {
|
||||
this.hash1 = hash
|
||||
return done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with a different hash value', function () {
|
||||
return this.callback
|
||||
.neverCalledWith(null, this.hash0)
|
||||
.should.equal(true)
|
||||
it('should return a different hash value', function () {
|
||||
expect(
|
||||
this.ClsiStateManager.computeHash(this.project, this.options)
|
||||
).not.to.equal(this.hash0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the isAutoCompile option is changed', function () {
|
||||
beforeEach(function () {
|
||||
this.options.isAutoCompile = !this.options.isAutoCompile
|
||||
return this.ClsiStateManager.computeHash(
|
||||
this.project,
|
||||
this.options,
|
||||
this.callback
|
||||
)
|
||||
})
|
||||
|
||||
it('should call the callback with the same hash value', function () {
|
||||
return this.callback.calledWith(null, this.hash0).should.equal(true)
|
||||
it('should return the same hash value', function () {
|
||||
expect(
|
||||
this.ClsiStateManager.computeHash(this.project, this.options)
|
||||
).to.equal(this.hash0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user