Merge pull request #933 from sharelatex/bg-avoid-exception-for-no-emails

fix exception when user has no emails field
This commit is contained in:
Hugh O'Brien 2018-09-19 11:33:03 +01:00 committed by GitHub
commit b377b89447
2 changed files with 13 additions and 1 deletions

View file

@ -35,7 +35,7 @@ module.exports = UserGetter =
getUserAffiliations userId, (error, affiliationsData) ->
return callback error if error?
callback null, decorateFullEmails(user.email, user.emails, affiliationsData)
callback null, decorateFullEmails(user.email, user.emails or [], affiliationsData)
getUserByMainEmail: (email, projection, callback = (error, user) ->) ->
email = email.trim()

View file

@ -98,6 +98,18 @@ describe "UserGetter", ->
]
done()
it "should get user when it has no emails field", (done)->
@fakeUser =
_id: '12390i'
email: 'email2@foo.bar'
@UserGetter.getUser = sinon.stub().callsArgWith(2, null, @fakeUser)
projection = email: 1, emails: 1
@UserGetter.getUserFullEmails @fakeUser._id, (error, fullEmails) =>
@UserGetter.getUser.called.should.equal true
@UserGetter.getUser.calledWith(@fakeUser._id, projection).should.equal true
assert.deepEqual fullEmails, []
done()
describe "getUserbyMainEmail", ->
it "query user by main email", (done)->
email = 'hello@world.com'