mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-25 07:02:49 +00:00
if projectId is not defined, error out
This commit is contained in:
parent
b8e4cafd81
commit
08567ff220
2 changed files with 18 additions and 0 deletions
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue