Sfoglia il codice sorgente

if projectId is not defined, error out

Shane Kilkelly 9 anni fa
parent
commit
08567ff220

+ 2 - 0
services/web/app/coffee/Features/Cooldown/CooldownMiddlewear.coffee

@@ -6,6 +6,8 @@ module.exports = CooldownMiddlewear =
 
 	freezeProject: (req, res, next) ->
 			projectId = req.params.Project_id
+			if !projectId?
+				return next(new Error('[Cooldown] No projectId parameter on route'))
 			CooldownManager.isProjectOnCooldown projectId, (err, projectIsOnCooldown) ->
 				if err?
 					return next(err)

+ 16 - 0
services/web/test/UnitTests/coffee/Cooldown/CooldownMiddlewearTests.coffee

@@ -70,3 +70,19 @@ describe "CooldownMiddlewear", ->
 				@CooldownMiddlewear.freezeProject @req, @res, @next
 				@next.callCount.should.equal 1
 				expect(@next.lastCall.args[0]).to.be.instanceof Error
+
+		describe 'when projectId is not part of route', ->
+			beforeEach ->
+				@CooldownManager.isProjectOnCooldown = sinon.stub().callsArgWith(1, null, true)
+				@req = {params: {lol: 'abc'}}
+				@res = {sendStatus: sinon.stub()}
+				@next = sinon.stub()
+
+			it 'call next with an error', ->
+				@CooldownMiddlewear.freezeProject @req, @res, @next
+				@next.callCount.should.equal 1
+				expect(@next.lastCall.args[0]).to.be.instanceof Error
+
+			it 'should not call CooldownManager.isProjectOnCooldown', ->
+				@CooldownMiddlewear.freezeProject @req, @res, @next
+				@CooldownManager.isProjectOnCooldown.callCount.should.equal 0