Просмотр исходного кода

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

* adding a filter condition for adding an email

* fixing failing tests

GitOrigin-RevId: 5276ad69229ab16b776da29150a103513e23d15a
Davinder Singh 2 лет назад
Родитель
Сommit
abba46978d

+ 1 - 1
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')
   }

+ 2 - 2
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: {