From 87bca3601da9058265a9c658e1262e2f07554169 Mon Sep 17 00:00:00 2001 From: M Fahru Date: Thu, 24 Apr 2025 09:12:49 -0700 Subject: [PATCH] Merge pull request #25065 from overleaf/mf-schedule-refresh-features-stripe [web] Refresh user features for stripe subscripton GitOrigin-RevId: e0600e80bfc264f2c0229090f0d5ff7ef845d28e --- .../Subscription/SubscriptionUpdater.js | 12 +++++-- .../Subscription/SubscriptionUpdaterTests.js | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) 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) + }) + }) })