mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #1380 from sharelatex/ew-fix-project-getter-error
fix callback is not a function error GitOrigin-RevId: 1bbe80f4086a17576f21ca9fc7b96f59d1b0614c
This commit is contained in:
parent
4360a55fdc
commit
a107b0cc33
2 changed files with 82 additions and 37 deletions
|
@ -24,13 +24,11 @@ module.exports = ProjectGetter =
|
|||
ProjectGetter.getProject project_id, excludes, callback
|
||||
|
||||
getProject: (project_id, projection, callback) ->
|
||||
if !project_id?
|
||||
return callback(new Error("no project_id provided"))
|
||||
|
||||
if typeof(projection) == "function" && !callback?
|
||||
callback = projection
|
||||
projection = {}
|
||||
|
||||
if !project_id?
|
||||
return callback(new Error("no project_id provided"))
|
||||
if typeof(projection) != "object"
|
||||
return callback(new Error("projection is not an object"))
|
||||
|
||||
|
@ -43,13 +41,11 @@ module.exports = ProjectGetter =
|
|||
ProjectGetter.getProjectWithoutLock project_id, projection, callback
|
||||
|
||||
getProjectWithoutLock: (project_id, projection, callback) ->
|
||||
if !project_id?
|
||||
return callback(new Error("no project_id provided"))
|
||||
|
||||
if typeof(projection) == "function" && !callback?
|
||||
callback = projection
|
||||
projection = {}
|
||||
|
||||
if !project_id?
|
||||
return callback(new Error("no project_id provided"))
|
||||
if typeof(projection) != "object"
|
||||
return callback(new Error("projection is not an object"))
|
||||
|
||||
|
|
|
@ -109,46 +109,95 @@ describe "ProjectGetter", ->
|
|||
_id: @project_id = "56d46b0a1d3422b87c5ebcb1"
|
||||
@db.projects.find = sinon.stub().callsArgWith(2, null, [@project])
|
||||
|
||||
describe "passing an id", ->
|
||||
describe "without projection", ->
|
||||
describe "with project id", ->
|
||||
beforeEach ->
|
||||
@ProjectGetter.getProjectWithOnlyFolders @project_id, @callback
|
||||
@ProjectGetter.getProject @project_id, @callback
|
||||
|
||||
it "should call find with the project id", ->
|
||||
expect(@db.projects.find.callCount).to.equal 1
|
||||
expect(@db.projects.find.lastCall.args[0]).to.deep.equal {
|
||||
_id: ObjectId(@project_id)
|
||||
}
|
||||
|
||||
it "should exclude the docs and files linesaaaa", ->
|
||||
excludes =
|
||||
"rootFolder.docs": 0
|
||||
"rootFolder.fileRefs": 0
|
||||
"rootFolder.folders.docs": 0
|
||||
"rootFolder.folders.fileRefs": 0
|
||||
"rootFolder.folders.folders.docs": 0
|
||||
"rootFolder.folders.folders.fileRefs": 0
|
||||
"rootFolder.folders.folders.folders.docs": 0
|
||||
"rootFolder.folders.folders.folders.fileRefs": 0
|
||||
"rootFolder.folders.folders.folders.folders.docs": 0
|
||||
"rootFolder.folders.folders.folders.folders.fileRefs": 0
|
||||
"rootFolder.folders.folders.folders.folders.folders.docs": 0
|
||||
"rootFolder.folders.folders.folders.folders.folders.fileRefs": 0
|
||||
"rootFolder.folders.folders.folders.folders.folders.folders.docs": 0
|
||||
"rootFolder.folders.folders.folders.folders.folders.folders.fileRefs": 0
|
||||
"rootFolder.folders.folders.folders.folders.folders.folders.folders.docs": 0
|
||||
"rootFolder.folders.folders.folders.folders.folders.folders.folders.fileRefs": 0
|
||||
@db.projects.find.calledWith(sinon.match.any, excludes).should.equal true
|
||||
describe "without project id", ->
|
||||
beforeEach ->
|
||||
@ProjectGetter.getProject null, @callback
|
||||
|
||||
it "should call the callback with the project", ->
|
||||
@callback.calledWith(null, @project).should.equal true
|
||||
it "should callback with error", ->
|
||||
expect(@db.projects.find.callCount).to.equal 0
|
||||
expect(@callback.lastCall.args[0]).to.be.instanceOf Error
|
||||
|
||||
describe "with projection", ->
|
||||
beforeEach ->
|
||||
@projection = {_id: 1}
|
||||
|
||||
describe "with project id", ->
|
||||
beforeEach ->
|
||||
@ProjectGetter.getProject @project_id, @projection, @callback
|
||||
|
||||
describe "getProject", ->
|
||||
it "should call find with the project id", ->
|
||||
expect(@db.projects.find.callCount).to.equal 1
|
||||
expect(@db.projects.find.lastCall.args[0]).to.deep.equal {
|
||||
_id: ObjectId(@project_id)
|
||||
}
|
||||
expect(@db.projects.find.lastCall.args[1]).to.deep.equal @projection
|
||||
|
||||
describe "without project id", ->
|
||||
beforeEach ->
|
||||
@ProjectGetter.getProject null, @callback
|
||||
|
||||
it "should callback with error", ->
|
||||
expect(@db.projects.find.callCount).to.equal 0
|
||||
expect(@callback.lastCall.args[0]).to.be.instanceOf Error
|
||||
|
||||
describe "getProjectWithoutLock", ->
|
||||
beforeEach ()->
|
||||
@project =
|
||||
_id: @project_id = "56d46b0a1d3422b87c5ebcb1"
|
||||
@db.projects.find = sinon.stub().callsArgWith(2, null, [@project])
|
||||
|
||||
describe "without projection", ->
|
||||
describe "with project id", ->
|
||||
beforeEach ->
|
||||
@ProjectGetter.getProjectWithoutLock @project_id, @callback
|
||||
|
||||
it "should call find with the project id", ->
|
||||
expect(@db.projects.find.callCount).to.equal 1
|
||||
expect(@db.projects.find.lastCall.args[0]).to.deep.equal {
|
||||
_id: ObjectId(@project_id)
|
||||
}
|
||||
|
||||
describe "without project id", ->
|
||||
beforeEach ->
|
||||
@ProjectGetter.getProjectWithoutLock null, @callback
|
||||
|
||||
it "should callback with error", ->
|
||||
expect(@db.projects.find.callCount).to.equal 0
|
||||
expect(@callback.lastCall.args[0]).to.be.instanceOf Error
|
||||
|
||||
describe "with projection", ->
|
||||
beforeEach ->
|
||||
@projection = {_id: 1}
|
||||
|
||||
describe "with project id", ->
|
||||
beforeEach ->
|
||||
@ProjectGetter.getProjectWithoutLock @project_id, @projection, @callback
|
||||
|
||||
it "should call find with the project id", ->
|
||||
expect(@db.projects.find.callCount).to.equal 1
|
||||
expect(@db.projects.find.lastCall.args[0]).to.deep.equal {
|
||||
_id: ObjectId(@project_id)
|
||||
}
|
||||
expect(@db.projects.find.lastCall.args[1]).to.deep.equal @projection
|
||||
|
||||
describe "without project id", ->
|
||||
beforeEach ->
|
||||
@ProjectGetter.getProjectWithoutLock null, @callback
|
||||
|
||||
it "should callback with error", ->
|
||||
expect(@db.projects.find.callCount).to.equal 0
|
||||
expect(@callback.lastCall.args[0]).to.be.instanceOf Error
|
||||
|
||||
describe "findAllUsersProjects", ->
|
||||
beforeEach ->
|
||||
|
|
Loading…
Reference in a new issue