diff --git a/services/web/app/coffee/Features/User/UserGetter.coffee b/services/web/app/coffee/Features/User/UserGetter.coffee index f3aa4ad4d6..7309b611c7 100644 --- a/services/web/app/coffee/Features/User/UserGetter.coffee +++ b/services/web/app/coffee/Features/User/UserGetter.coffee @@ -34,7 +34,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() diff --git a/services/web/test/unit/coffee/User/UserGetterTests.coffee b/services/web/test/unit/coffee/User/UserGetterTests.coffee index 79d9032283..374576cb1f 100644 --- a/services/web/test/unit/coffee/User/UserGetterTests.coffee +++ b/services/web/test/unit/coffee/User/UserGetterTests.coffee @@ -93,6 +93,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'