if projectId is not defined, error out

This commit is contained in:
Shane Kilkelly 2017-05-10 15:25:23 +01:00
parent b8e4cafd81
commit 08567ff220
2 changed files with 18 additions and 0 deletions

View file

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

View file

@ -70,3 +70,19 @@ describe "CooldownMiddlewear", ->
@CooldownMiddlewear.freezeProject @req, @res, @next @CooldownMiddlewear.freezeProject @req, @res, @next
@next.callCount.should.equal 1 @next.callCount.should.equal 1
expect(@next.lastCall.args[0]).to.be.instanceof Error 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