add filter to query on emails attribute

This commit is contained in:
Tim Alby 2018-06-06 14:52:09 +02:00
parent 5681a76f4c
commit e4da748257
2 changed files with 6 additions and 2 deletions

View file

@ -37,7 +37,8 @@ module.exports = UserGetter =
if arguments.length == 2
callback = projection
projection = {}
db.users.findOne 'emails.email': email, projection, (error, user) =>
query = emails: { $exists: true }, 'emails.email': email
db.users.findOne query, projection, (error, user) =>
return callback(error, user) if error? or user?
# While multiple emails are being rolled out, check for the main email as

View file

@ -60,9 +60,12 @@ describe "UserGetter", ->
describe "getUserByAnyEmail", ->
it "query user for any email", (done)->
email = 'hello@world.com'
expectedQuery =
emails: { $exists: true }
'emails.email': email
projection = emails: 1
@UserGetter.getUserByAnyEmail " #{email} ", projection, (error, user) =>
@findOne.calledWith('emails.email': email, projection).should.equal true
@findOne.calledWith(expectedQuery, projection).should.equal true
user.should.deep.equal @fakeUser
done()