adding a filter condition for adding an email (#15914)

* adding a filter condition for adding an email

* fixing failing tests

GitOrigin-RevId: 5276ad69229ab16b776da29150a103513e23d15a
This commit is contained in:
Davinder Singh 2023-11-28 16:04:58 +00:00 committed by Copybot
parent 53708fb03e
commit abba46978d
2 changed files with 3 additions and 3 deletions

View file

@ -104,7 +104,7 @@ async function addEmailAddress(userId, newEmail, affiliationOptions, auditLog) {
emails: { email: newEmail, createdAt: new Date(), reversedHostname },
},
}
await updateUser(userId, update)
await updateUser({ _id: userId, 'emails.email': { $ne: newEmail } }, update)
} catch (error) {
throw OError.tag(error, 'problem updating users emails')
}

View file

@ -199,7 +199,7 @@ describe('UserUpdater', function () {
it('adds the new email', function () {
expect(this.db.users.updateOne).to.have.been.calledWith(
{ _id: this.user._id },
{ _id: this.user._id, 'emails.email': { $ne: this.newEmail } },
{
$push: {
emails: sinon.match({ email: this.newEmail }),
@ -281,7 +281,7 @@ describe('UserUpdater', function () {
.reverse()
.join('')
this.db.users.updateOne.should.have.been.calledWith(
{ _id: this.user._id },
{ _id: this.user._id, 'emails.email': { $ne: this.newEmail } },
{
$push: {
emails: {