Просмотр исходного кода

Merge pull request #1380 from sharelatex/ew-fix-project-getter-error

fix callback is not a function error

GitOrigin-RevId: 1bbe80f4086a17576f21ca9fc7b96f59d1b0614c
Simon Detheridge 7 лет назад
Родитель
Сommit
a107b0cc33

+ 4 - 8
services/web/app/coffee/Features/Project/ProjectGetter.coffee

@@ -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"))
 

+ 78 - 29
services/web/test/unit/coffee/Project/ProjectGetterTests.coffee

@@ -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.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 ->
-				@ProjectGetter.getProjectWithOnlyFolders @project_id, @callback
-
-			it "should call find with the project id", ->
-				expect(@db.projects.find.lastCall.args[0]).to.deep.equal {
-					_id: ObjectId(@project_id)
-				}
+				@projection = {_id: 1}
 
-			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 "with project id", ->
+				beforeEach ->
+					@ProjectGetter.getProject @project_id, @projection, @callback
 
-			it "should call the callback with the project", ->
-				@callback.calledWith(null, @project).should.equal true
+				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 "getProject", ->
+	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 ->