|
@@ -18,21 +18,27 @@ describe "UserUpdater", ->
|
|
|
getUserEmail: sinon.stub()
|
|
getUserEmail: sinon.stub()
|
|
|
getUserByAnyEmail: sinon.stub()
|
|
getUserByAnyEmail: sinon.stub()
|
|
|
ensureUniqueEmailAddress: sinon.stub()
|
|
ensureUniqueEmailAddress: sinon.stub()
|
|
|
- @logger = err: sinon.stub(), log: ->
|
|
|
|
|
|
|
+ @logger =
|
|
|
|
|
+ err: sinon.stub()
|
|
|
|
|
+ log: ->
|
|
|
|
|
+ warn: ->
|
|
|
@addAffiliation = sinon.stub().yields()
|
|
@addAffiliation = sinon.stub().yields()
|
|
|
@removeAffiliation = sinon.stub().callsArgWith(2, null)
|
|
@removeAffiliation = sinon.stub().callsArgWith(2, null)
|
|
|
@refreshFeatures = sinon.stub().yields()
|
|
@refreshFeatures = sinon.stub().yields()
|
|
|
|
|
+ @NewsletterManager =
|
|
|
|
|
+ changeEmail:sinon.stub()
|
|
|
@UserUpdater = SandboxedModule.require modulePath, requires:
|
|
@UserUpdater = SandboxedModule.require modulePath, requires:
|
|
|
"logger-sharelatex": @logger
|
|
"logger-sharelatex": @logger
|
|
|
|
|
+ "../../infrastructure/mongojs":@mongojs
|
|
|
|
|
+ "metrics-sharelatex": timeAsyncMethod: sinon.stub()
|
|
|
"./UserGetter": @UserGetter
|
|
"./UserGetter": @UserGetter
|
|
|
'../Institutions/InstitutionsAPI':
|
|
'../Institutions/InstitutionsAPI':
|
|
|
addAffiliation: @addAffiliation
|
|
addAffiliation: @addAffiliation
|
|
|
removeAffiliation: @removeAffiliation
|
|
removeAffiliation: @removeAffiliation
|
|
|
'../Subscription/FeaturesUpdater': refreshFeatures: @refreshFeatures
|
|
'../Subscription/FeaturesUpdater': refreshFeatures: @refreshFeatures
|
|
|
- "../../infrastructure/mongojs":@mongojs
|
|
|
|
|
- "metrics-sharelatex": timeAsyncMethod: sinon.stub()
|
|
|
|
|
"settings-sharelatex": @settings = {}
|
|
"settings-sharelatex": @settings = {}
|
|
|
"request": @request = {}
|
|
"request": @request = {}
|
|
|
|
|
+ "../Newsletter/NewsletterManager": @NewsletterManager
|
|
|
|
|
|
|
|
@stubbedUser =
|
|
@stubbedUser =
|
|
|
_id: "3131231"
|
|
_id: "3131231"
|
|
@@ -174,6 +180,10 @@ describe "UserUpdater", ->
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
describe 'setDefaultEmailAddress', ->
|
|
describe 'setDefaultEmailAddress', ->
|
|
|
|
|
+ beforeEach ->
|
|
|
|
|
+ @UserGetter.getUserEmail.callsArgWith(1, null, @stubbedUser.email)
|
|
|
|
|
+ @NewsletterManager.changeEmail.callsArgWith(2, null)
|
|
|
|
|
+
|
|
|
it 'set default', (done)->
|
|
it 'set default', (done)->
|
|
|
@UserUpdater.updateUser = sinon.stub().callsArgWith(2, null, n: 1)
|
|
@UserUpdater.updateUser = sinon.stub().callsArgWith(2, null, n: 1)
|
|
|
|
|
|
|
@@ -185,6 +195,16 @@ describe "UserUpdater", ->
|
|
|
).should.equal true
|
|
).should.equal true
|
|
|
done()
|
|
done()
|
|
|
|
|
|
|
|
|
|
+ it 'set changed the email in newsletter', (done)->
|
|
|
|
|
+ @UserUpdater.updateUser = sinon.stub().callsArgWith(2, null, n: 1)
|
|
|
|
|
+
|
|
|
|
|
+ @UserUpdater.setDefaultEmailAddress @stubbedUser._id, @newEmail, (err)=>
|
|
|
|
|
+ should.not.exist(err)
|
|
|
|
|
+ @NewsletterManager.changeEmail.calledWith(
|
|
|
|
|
+ @stubbedUser.email, @newEmail
|
|
|
|
|
+ ).should.equal true
|
|
|
|
|
+ done()
|
|
|
|
|
+
|
|
|
it 'handle error', (done)->
|
|
it 'handle error', (done)->
|
|
|
@UserUpdater.updateUser = sinon.stub().callsArgWith(2, new Error('nope'))
|
|
@UserUpdater.updateUser = sinon.stub().callsArgWith(2, new Error('nope'))
|
|
|
|
|
|