mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Merge pull request #25065 from overleaf/mf-schedule-refresh-features-stripe
[web] Refresh user features for stripe subscripton GitOrigin-RevId: e0600e80bfc264f2c0229090f0d5ff7ef845d28e
This commit is contained in:
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user