deleteing user account cancels any subscription

This commit is contained in:
Henry Oswald 2014-03-03 16:22:55 +00:00
parent fe026b4b0b
commit 99dc141693
2 changed files with 22 additions and 8 deletions

View file

@ -2,6 +2,8 @@ User = require("../../models/User").User
NewsletterManager = require "../../managers/NewsletterManager" NewsletterManager = require "../../managers/NewsletterManager"
ProjectDeleter = require("../Project/ProjectDeleter") ProjectDeleter = require("../Project/ProjectDeleter")
logger = require("logger-sharelatex") logger = require("logger-sharelatex")
SubscriptionHandler = require("../Subscription/SubscriptionHandler")
async = require("async")
module.exports = module.exports =
@ -10,13 +12,19 @@ module.exports =
logger.err "user_id is null when trying to delete user" logger.err "user_id is null when trying to delete user"
return callback("no user_id") return callback("no user_id")
User.findById user_id, (err, user)-> User.findById user_id, (err, user)->
if err?
return callback(err)
logger.log user:user, "deleting user" logger.log user:user, "deleting user"
async.series [
(cb)->
NewsletterManager.unsubscribe user, cb
(cb)->
ProjectDeleter.deleteUsersProjects user._id, cb
(cb)->
SubscriptionHandler.cancelSubscription user._id, cb
(cb)->
user.remove cb
], (err)->
if err? if err?
return callback(err) logger.err err:err, user_id:user_id, "something went wrong deleteing the user"
NewsletterManager.unsubscribe user, (err)-> callback err
if err?
return callback(err)
ProjectDeleter.deleteUsersProjects user._id, (err)->
if err?
return callback(err)
user.remove callback

View file

@ -21,9 +21,12 @@ describe "UserDeleter", ->
@ProjectDeleter = @ProjectDeleter =
deleteUsersProjects: sinon.stub().callsArgWith(1) deleteUsersProjects: sinon.stub().callsArgWith(1)
@SubscriptionHandler =
cancelSubscription: sinon.stub().callsArgWith(1)
@UserDeleter = SandboxedModule.require modulePath, requires: @UserDeleter = SandboxedModule.require modulePath, requires:
"../../models/User": User: @User "../../models/User": User: @User
"../../managers/NewsletterManager": @NewsletterManager "../../managers/NewsletterManager": @NewsletterManager
"../Subscription/SubscriptionHandler": @SubscriptionHandler
"../Project/ProjectDeleter": @ProjectDeleter "../Project/ProjectDeleter": @ProjectDeleter
describe "deleteUser", -> describe "deleteUser", ->
@ -44,4 +47,7 @@ describe "UserDeleter", ->
@ProjectDeleter.deleteUsersProjects.calledWith(@user._id).should.equal true @ProjectDeleter.deleteUsersProjects.calledWith(@user._id).should.equal true
done() done()
it "should unsubscribe the user", (done)->
@UserDeleter.deleteUser @user._id, (err)=>
@SubscriptionHandler.cancelSubscription.calledWith(@user._id).should.equal true
done()