diff --git a/services/web/app/src/Features/Subscription/SubscriptionUpdater.js b/services/web/app/src/Features/Subscription/SubscriptionUpdater.js index edaf74bcd4..482d81ff41 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionUpdater.js +++ b/services/web/app/src/Features/Subscription/SubscriptionUpdater.js @@ -165,7 +165,7 @@ async function deleteSubscription(subscription, deleterData) { await Subscription.deleteOne({ _id: subscription._id }).exec() // 4. refresh users features - await _scheduleRefreshFeatures(subscription) + await scheduleRefreshFeatures(subscription) } async function restoreSubscription(subscriptionId) { @@ -206,7 +206,11 @@ async function refreshUsersFeatures(subscription) { } } -async function _scheduleRefreshFeatures(subscription) { +/** + * + * @param {Subscription} subscription + */ +async function scheduleRefreshFeatures(subscription) { const userIds = [subscription.admin_id].concat(subscription.member_ids || []) for (const userId of userIds) { await FeaturesUpdater.promises.scheduleRefreshFeatures( @@ -367,7 +371,7 @@ async function updateSubscriptionFromRecurly( AnalyticsManager.registerAccountMapping(accountMapping) } - await _scheduleRefreshFeatures(subscription) + await scheduleRefreshFeatures(subscription) } async function _sendUserGroupPlanCodeUserProperty(userId) { @@ -449,6 +453,7 @@ module.exports = { deleteWithV1Id: callbackify(deleteWithV1Id), restoreSubscription: callbackify(restoreSubscription), updateSubscriptionFromRecurly: callbackify(updateSubscriptionFromRecurly), + scheduleRefreshFeatures: callbackify(scheduleRefreshFeatures), promises: { updateAdmin, syncSubscription, @@ -462,5 +467,6 @@ module.exports = { deleteWithV1Id, restoreSubscription, updateSubscriptionFromRecurly, + scheduleRefreshFeatures, }, } diff --git a/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js b/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js index 666f7ffda9..09644bc7b1 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js +++ b/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js @@ -801,4 +801,38 @@ describe('SubscriptionUpdater', function () { } }) }) + + describe('scheduleRefreshFeatures', function () { + it('should call upgrades feature for personal subscription from admin_id', async function () { + this.subscription = { + _id: new ObjectId().toString(), + mock: 'subscription', + admin_id: new ObjectId(), + } + + await this.SubscriptionUpdater.promises.scheduleRefreshFeatures( + this.subscription + ) + + expect( + this.FeaturesUpdater.promises.scheduleRefreshFeatures + ).to.have.been.calledOnceWith(this.subscription.admin_id) + }) + + it('should call upgrades feature for group subscription from admin_id and member_ids', async function () { + this.subscription = { + _id: new ObjectId().toString(), + mock: 'subscription', + admin_id: new ObjectId(), + member_ids: [new ObjectId(), new ObjectId(), new ObjectId()], + } + await this.SubscriptionUpdater.promises.scheduleRefreshFeatures( + this.subscription + ) + + expect( + this.FeaturesUpdater.promises.scheduleRefreshFeatures.callCount + ).to.equal(4) + }) + }) })