Fix error-handling in setPublicAccessLevel

This commit is contained in:
Shane Kilkelly 2017-10-26 16:39:24 +01:00
parent 18443b55cb
commit ec94e59388
2 changed files with 16 additions and 1 deletions

View file

@ -74,7 +74,7 @@ module.exports = ProjectDetailsHandler =
PublicAccessLevels.TOKEN_BASED
], newAccessLevel
Project.update {_id:project_id},{publicAccesLevel:newAccessLevel}, (err)->
callback()
callback(err)
ensureTokensArePresent: (project_id, callback=(err, tokens)->) ->
ProjectGetter.getProject project_id, {tokens: 1}, (err, project) ->

View file

@ -150,6 +150,21 @@ describe 'ProjectDetailsHandler', ->
@ProjectModel.update.calledWith({_id: @project_id}, {publicAccesLevel: @accessLevel}).should.equal true
done()
it 'should not produce an error', (done) ->
@handler.setPublicAccessLevel @project_id, @accessLevel, (err) =>
expect(err).to.not.exist
done()
describe 'when update produces an error', ->
beforeEach ->
@ProjectModel.update.callsArgWith(2, new Error('woops'))
it 'should produce an error', (done) ->
@handler.setPublicAccessLevel @project_id, @accessLevel, (err) =>
expect(err).to.exist
expect(err).to.be.instanceof Error
done()
describe "ensureTokensArePresent", ->
beforeEach ->