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
|
ProjectGetter.getProject project_id, excludes, callback
|
||||||
|
|
||||||
getProject: (project_id, projection, callback) ->
|
getProject: (project_id, projection, callback) ->
|
||||||
if !project_id?
|
|
||||||
return callback(new Error("no project_id provided"))
|
|
||||||
|
|
||||||
if typeof(projection) == "function" && !callback?
|
if typeof(projection) == "function" && !callback?
|
||||||
callback = projection
|
callback = projection
|
||||||
projection = {}
|
projection = {}
|
||||||
|
if !project_id?
|
||||||
|
return callback(new Error("no project_id provided"))
|
||||||
if typeof(projection) != "object"
|
if typeof(projection) != "object"
|
||||||
return callback(new Error("projection is not an object"))
|
return callback(new Error("projection is not an object"))
|
||||||
|
|
||||||
|
@ -43,13 +41,11 @@ module.exports = ProjectGetter =
|
||||||
ProjectGetter.getProjectWithoutLock project_id, projection, callback
|
ProjectGetter.getProjectWithoutLock project_id, projection, callback
|
||||||
|
|
||||||
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?
|
if typeof(projection) == "function" && !callback?
|
||||||
callback = projection
|
callback = projection
|
||||||
projection = {}
|
projection = {}
|
||||||
|
if !project_id?
|
||||||
|
return callback(new Error("no project_id provided"))
|
||||||
if typeof(projection) != "object"
|
if typeof(projection) != "object"
|
||||||
return callback(new Error("projection is not an object"))
|
return callback(new Error("projection is not an object"))
|
||||||
|
|
||||||
|
|
|
@ -109,46 +109,95 @@ describe "ProjectGetter", ->
|
||||||
_id: @project_id = "56d46b0a1d3422b87c5ebcb1"
|
_id: @project_id = "56d46b0a1d3422b87c5ebcb1"
|
||||||
@db.projects.find = sinon.stub().callsArgWith(2, null, [@project])
|
@db.projects.find = sinon.stub().callsArgWith(2, null, [@project])
|
||||||
|
|
||||||
describe "passing an id", ->
|
describe "without projection", ->
|
||||||
|
describe "with project id", ->
|
||||||
|
beforeEach ->
|
||||||
|
@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)
|
||||||
|
}
|
||||||
|
|
||||||
|
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 "with projection", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@ProjectGetter.getProjectWithOnlyFolders @project_id, @callback
|
@projection = {_id: 1}
|
||||||
|
|
||||||
it "should call find with the project id", ->
|
describe "with project id", ->
|
||||||
expect(@db.projects.find.lastCall.args[0]).to.deep.equal {
|
beforeEach ->
|
||||||
_id: ObjectId(@project_id)
|
@ProjectGetter.getProject @project_id, @projection, @callback
|
||||||
}
|
|
||||||
|
|
||||||
it "should exclude the docs and files linesaaaa", ->
|
it "should call find with the project id", ->
|
||||||
excludes =
|
expect(@db.projects.find.callCount).to.equal 1
|
||||||
"rootFolder.docs": 0
|
expect(@db.projects.find.lastCall.args[0]).to.deep.equal {
|
||||||
"rootFolder.fileRefs": 0
|
_id: ObjectId(@project_id)
|
||||||
"rootFolder.folders.docs": 0
|
}
|
||||||
"rootFolder.folders.fileRefs": 0
|
expect(@db.projects.find.lastCall.args[1]).to.deep.equal @projection
|
||||||
"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
|
|
||||||
|
|
||||||
it "should call the callback with the project", ->
|
describe "without project id", ->
|
||||||
@callback.calledWith(null, @project).should.equal true
|
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", ->
|
||||||
describe "getProject", ->
|
|
||||||
beforeEach ()->
|
beforeEach ()->
|
||||||
@project =
|
@project =
|
||||||
_id: @project_id = "56d46b0a1d3422b87c5ebcb1"
|
_id: @project_id = "56d46b0a1d3422b87c5ebcb1"
|
||||||
@db.projects.find = sinon.stub().callsArgWith(2, null, [@project])
|
@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", ->
|
describe "findAllUsersProjects", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
Loading…
Reference in a new issue