2014-02-12 05:23:40 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
modulePath = "../../../../app/js/Features/User/UserDeleter.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "UserDeleter", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@user =
|
|
|
|
_id:"12390i"
|
|
|
|
email: "bob@bob.com"
|
|
|
|
remove: sinon.stub().callsArgWith(0)
|
|
|
|
|
|
|
|
@User =
|
|
|
|
findById : sinon.stub().callsArgWith(1, null, @user)
|
|
|
|
|
|
|
|
@NewsletterManager =
|
|
|
|
unsubscribe: sinon.stub().callsArgWith(1)
|
|
|
|
|
|
|
|
@ProjectDeleter =
|
|
|
|
deleteUsersProjects: sinon.stub().callsArgWith(1)
|
|
|
|
|
2014-03-03 11:22:55 -05:00
|
|
|
@SubscriptionHandler =
|
|
|
|
cancelSubscription: sinon.stub().callsArgWith(1)
|
2018-06-27 12:43:20 -04:00
|
|
|
|
|
|
|
@deleteAffiliations = sinon.stub().callsArgWith(1)
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
@UserDeleter = SandboxedModule.require modulePath, requires:
|
|
|
|
"../../models/User": User: @User
|
2014-04-04 10:47:27 -04:00
|
|
|
"../Newsletter/NewsletterManager": @NewsletterManager
|
2014-03-03 11:22:55 -05:00
|
|
|
"../Subscription/SubscriptionHandler": @SubscriptionHandler
|
2014-02-12 05:23:40 -05:00
|
|
|
"../Project/ProjectDeleter": @ProjectDeleter
|
2018-07-10 15:49:24 -04:00
|
|
|
"../Institutions/InstitutionsAPI":
|
2018-06-27 12:43:20 -04:00
|
|
|
deleteAffiliations: @deleteAffiliations
|
2015-03-18 11:57:01 -04:00
|
|
|
"logger-sharelatex": @logger = { log: sinon.stub() }
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
describe "deleteUser", ->
|
|
|
|
|
|
|
|
it "should delete the user in mongo", (done)->
|
|
|
|
@UserDeleter.deleteUser @user._id, (err)=>
|
|
|
|
@User.findById.calledWith(@user._id).should.equal true
|
|
|
|
@user.remove.called.should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should unsubscribe the user from the news letter", (done)->
|
|
|
|
@UserDeleter.deleteUser @user._id, (err)=>
|
|
|
|
@NewsletterManager.unsubscribe.calledWith(@user).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should delete all the projects of a user", (done)->
|
|
|
|
@UserDeleter.deleteUser @user._id, (err)=>
|
|
|
|
@ProjectDeleter.deleteUsersProjects.calledWith(@user._id).should.equal true
|
|
|
|
done()
|
|
|
|
|
2014-03-03 11:22:55 -05:00
|
|
|
it "should unsubscribe the user", (done)->
|
|
|
|
@UserDeleter.deleteUser @user._id, (err)=>
|
2015-01-02 05:37:59 -05:00
|
|
|
@SubscriptionHandler.cancelSubscription.calledWith(@user).should.equal true
|
2014-03-03 11:22:55 -05:00
|
|
|
done()
|
2018-06-27 12:43:20 -04:00
|
|
|
|
|
|
|
it "should delete user affiliations", (done)->
|
|
|
|
@UserDeleter.deleteUser @user._id, (err)=>
|
|
|
|
@deleteAffiliations.calledWith(@user._id).should.equal true
|
|
|
|
done()
|