Sfoglia il codice sorgente

Merge pull request #2610 from overleaf/ta-recurly-email-update-auto

Update Recurly Email on Default Email Change

GitOrigin-RevId: e2821d7bdc4bc6befff2152d92c76952c38694f9
Eric Mc Sween 6 anni fa
parent
commit
174af14d46

+ 4 - 0
services/web/app/src/Features/User/UserUpdater.js

@@ -15,6 +15,7 @@ const FeaturesUpdater = require('../Subscription/FeaturesUpdater')
 const EmailHelper = require('../Helpers/EmailHelper')
 const EmailHelper = require('../Helpers/EmailHelper')
 const Errors = require('../Errors/Errors')
 const Errors = require('../Errors/Errors')
 const NewsletterManager = require('../Newsletter/NewsletterManager')
 const NewsletterManager = require('../Newsletter/NewsletterManager')
+const RecurlyWrapper = require('../Subscription/RecurlyWrapper')
 
 
 const UserUpdater = {
 const UserUpdater = {
   addAffiliationForNewUser(userId, email, callback) {
   addAffiliationForNewUser(userId, email, callback) {
@@ -203,6 +204,9 @@ const UserUpdater = {
             )
             )
           }
           }
         })
         })
+        RecurlyWrapper.updateAccountEmailAddress(user._id, email, _error => {
+          // errors are ignored
+        })
         callback()
         callback()
       })
       })
     })
     })

+ 7 - 1
services/web/test/unit/src/User/UserUpdaterTests.js

@@ -32,6 +32,7 @@ describe('UserUpdater', function() {
     this.removeAffiliation = sinon.stub().callsArgWith(2, null)
     this.removeAffiliation = sinon.stub().callsArgWith(2, null)
     this.refreshFeatures = sinon.stub().yields()
     this.refreshFeatures = sinon.stub().yields()
     this.NewsletterManager = { changeEmail: sinon.stub() }
     this.NewsletterManager = { changeEmail: sinon.stub() }
+    this.RecurlyWrapper = { updateAccountEmailAddress: sinon.stub() }
     this.UserUpdater = SandboxedModule.require(modulePath, {
     this.UserUpdater = SandboxedModule.require(modulePath, {
       globals: {
       globals: {
         console: console
         console: console
@@ -55,7 +56,8 @@ describe('UserUpdater', function() {
         },
         },
         'settings-sharelatex': (this.settings = {}),
         'settings-sharelatex': (this.settings = {}),
         request: (this.request = {}),
         request: (this.request = {}),
-        '../Newsletter/NewsletterManager': this.NewsletterManager
+        '../Newsletter/NewsletterManager': this.NewsletterManager,
+        '../Subscription/RecurlyWrapper': this.RecurlyWrapper
       }
       }
     })
     })
 
 
@@ -350,6 +352,7 @@ describe('UserUpdater', function() {
       ]
       ]
       this.UserGetter.getUser = sinon.stub().yields(null, this.stubbedUser)
       this.UserGetter.getUser = sinon.stub().yields(null, this.stubbedUser)
       this.NewsletterManager.changeEmail.callsArgWith(2, null)
       this.NewsletterManager.changeEmail.callsArgWith(2, null)
+      this.RecurlyWrapper.updateAccountEmailAddress.yields(null)
     })
     })
 
 
     it('set default', function(done) {
     it('set default', function(done) {
@@ -382,6 +385,9 @@ describe('UserUpdater', function() {
           this.NewsletterManager.changeEmail
           this.NewsletterManager.changeEmail
             .calledWith(this.stubbedUser, this.newEmail)
             .calledWith(this.stubbedUser, this.newEmail)
             .should.equal(true)
             .should.equal(true)
+          this.RecurlyWrapper.updateAccountEmailAddress
+            .calledWith(this.stubbedUser._id, this.newEmail)
+            .should.equal(true)
           done()
           done()
         }
         }
       )
       )