From abba46978defa9a45d6d5700e90a14de6f399140 Mon Sep 17 00:00:00 2001 From: Davinder Singh Date: Tue, 28 Nov 2023 16:04:58 +0000 Subject: [PATCH] adding a filter condition for adding an email (#15914) * adding a filter condition for adding an email * fixing failing tests GitOrigin-RevId: 5276ad69229ab16b776da29150a103513e23d15a --- services/web/app/src/Features/User/UserUpdater.js | 2 +- services/web/test/unit/src/User/UserUpdaterTests.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/web/app/src/Features/User/UserUpdater.js b/services/web/app/src/Features/User/UserUpdater.js index b705819e05..baf905a7e6 100644 --- a/services/web/app/src/Features/User/UserUpdater.js +++ b/services/web/app/src/Features/User/UserUpdater.js @@ -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') } diff --git a/services/web/test/unit/src/User/UserUpdaterTests.js b/services/web/test/unit/src/User/UserUpdaterTests.js index 0635abc857..641b0251b8 100644 --- a/services/web/test/unit/src/User/UserUpdaterTests.js +++ b/services/web/test/unit/src/User/UserUpdaterTests.js @@ -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: {