diff --git a/services/web/app/coffee/Features/Cooldown/CooldownMiddlewear.coffee b/services/web/app/coffee/Features/Cooldown/CooldownMiddlewear.coffee index b073541945..6d1e158699 100644 --- a/services/web/app/coffee/Features/Cooldown/CooldownMiddlewear.coffee +++ b/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) diff --git a/services/web/test/UnitTests/coffee/Cooldown/CooldownMiddlewearTests.coffee b/services/web/test/UnitTests/coffee/Cooldown/CooldownMiddlewearTests.coffee index 694ca11fce..646e7ffbde 100644 --- a/services/web/test/UnitTests/coffee/Cooldown/CooldownMiddlewearTests.coffee +++ b/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