avoid exception in validateProjectName

This commit is contained in:
Brian Gough 2017-10-12 16:03:12 +01:00
parent 3d2f9f0219
commit 8cf3288187
2 changed files with 7 additions and 1 deletions

View file

@ -57,7 +57,7 @@ module.exports = ProjectDetailsHandler =
MAX_PROJECT_NAME_LENGTH: 150
validateProjectName: (name, callback = (error) ->) ->
if name.length == 0
if !name? or name.length == 0
return callback(new Errors.InvalidNameError("Project name cannot be blank"))
else if name.length > @MAX_PROJECT_NAME_LENGTH
return callback(new Errors.InvalidNameError("Project name is too long"))

View file

@ -126,6 +126,12 @@ describe 'ProjectDetailsHandler', ->
done()
describe "validateProjectName", ->
it "should reject undefined names", (done) ->
@handler.validateProjectName undefined, (error) ->
expect(error).to.exist
done()
it "should reject empty names", (done) ->
@handler.validateProjectName "", (error) ->
expect(error).to.exist