mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Add SubscriptionUpdater.deleteSubscription
This commit is contained in:
parent
e3bf4c539b
commit
10f362a77a
2 changed files with 42 additions and 0 deletions
|
@ -62,6 +62,15 @@ module.exports = SubscriptionUpdater =
|
|||
invited_emails: email
|
||||
}, callback
|
||||
|
||||
deleteSubscription: (subscription_id, callback = (error) ->) ->
|
||||
SubscriptionLocator.getSubscription subscription_id, (err, subscription) ->
|
||||
return callback(err) if err?
|
||||
affected_user_ids = [subscription.admin_id].concat(subscription.member_ids or [])
|
||||
logger.log {subscription_id, affected_user_ids}, "deleting subscription and downgrading users"
|
||||
Subscription.remove {_id: ObjectId(subscription_id)}, (err) ->
|
||||
return callback(err) if err?
|
||||
async.mapSeries affected_user_ids, SubscriptionUpdater._setUsersMinimumFeatures, callback
|
||||
|
||||
_createNewSubscription: (adminUser_id, callback)->
|
||||
logger.log adminUser_id:adminUser_id, "creating new subscription"
|
||||
subscription = new Subscription(admin_id:adminUser_id)
|
||||
|
|
|
@ -37,6 +37,7 @@ describe "SubscriptionUpdater", ->
|
|||
constructor: (opts)->
|
||||
subscription.admin_id = opts.admin_id
|
||||
return subscription
|
||||
@remove: sinon.stub().yields()
|
||||
@SubscriptionModel.update = @updateStub
|
||||
@SubscriptionModel.findAndModify = @findAndModifyStub
|
||||
|
||||
|
@ -230,3 +231,35 @@ describe "SubscriptionUpdater", ->
|
|||
@ReferalAllocator.assignBonus.calledWith(@adminuser_id).should.equal true
|
||||
done()
|
||||
|
||||
describe "deleteSubscription", ->
|
||||
beforeEach (done) ->
|
||||
@subscription_id = ObjectId().toString()
|
||||
@subscription = {
|
||||
"mock": "subscription",
|
||||
admin_id: ObjectId(),
|
||||
member_ids: [ ObjectId(), ObjectId(), ObjectId() ]
|
||||
}
|
||||
@SubscriptionLocator.getSubscription = sinon.stub().yields(null, @subscription)
|
||||
@SubscriptionUpdater._setUsersMinimumFeatures = sinon.stub().yields()
|
||||
@SubscriptionUpdater.deleteSubscription @subscription_id, done
|
||||
|
||||
it "should look up the subscription", ->
|
||||
@SubscriptionLocator.getSubscription
|
||||
.calledWith(@subscription_id)
|
||||
.should.equal true
|
||||
|
||||
it "should remove the subscription", ->
|
||||
@SubscriptionModel.remove
|
||||
.calledWith({_id: ObjectId(@subscription_id)})
|
||||
.should.equal true
|
||||
|
||||
it "should downgrade the admin_id", ->
|
||||
@SubscriptionUpdater._setUsersMinimumFeatures
|
||||
.calledWith(@subscription.admin_id)
|
||||
.should.equal true
|
||||
|
||||
it "should downgrade all of the members", ->
|
||||
for user_id in @subscription.member_ids
|
||||
@SubscriptionUpdater._setUsersMinimumFeatures
|
||||
.calledWith(user_id)
|
||||
.should.equal true
|
||||
|
|
Loading…
Reference in a new issue