Merge pull request #22379 from overleaf/ls-sync-with-recurly-after-mutation

sync with recurly after mutate subscription

GitOrigin-RevId: 451914f7bde344f82ad4523bee20f1af2297cbd8
This commit is contained in:
ilkin-overleaf
2024-12-09 15:22:30 +02:00
committed by Copybot
parent e422cb9485
commit bd967ce1df
2 changed files with 18 additions and 1 deletions
@@ -6,6 +6,7 @@ const { Subscription } = require('../../models/Subscription')
const SessionManager = require('../Authentication/SessionManager')
const RecurlyClient = require('./RecurlyClient')
const PlansLocator = require('./PlansLocator')
const SubscriptionHandler = require('./SubscriptionHandler')
const PLAN_UPGRADE_MAP = {
group_collaborator: 'group_professional',
@@ -139,8 +140,13 @@ async function previewAddSeatsSubscriptionChange(req) {
}
async function createAddSeatsSubscriptionChange(req) {
const { changeRequest } = await _addSeatsSubscriptionChange(req)
const { changeRequest, userId, recurlySubscription } =
await _addSeatsSubscriptionChange(req)
await RecurlyClient.promises.applySubscriptionChangeRequest(changeRequest)
await SubscriptionHandler.promises.syncSubscription(
{ uuid: recurlySubscription.id },
userId
)
return { adding: req.body.adding }
}
@@ -187,6 +193,10 @@ async function getGroupPlanUpgradePreview(ownerId) {
async function upgradeGroupPlan(ownerId) {
const changeRequest = await _getGroupPlanUpgradeChangeRequest(ownerId)
await RecurlyClient.promises.applySubscriptionChangeRequest(changeRequest)
await SubscriptionHandler.promises.syncSubscription(
{ uuid: changeRequest.subscription.id },
ownerId
)
}
module.exports = {
@@ -48,11 +48,18 @@ describe('SubscriptionGroupHandler', function () {
promises: {},
}
this.SubscriptionHandler = {
promises: {
syncSubscription: sinon.stub().resolves(),
},
}
this.Handler = SandboxedModule.require(modulePath, {
requires: {
'./SubscriptionUpdater': this.SubscriptionUpdater,
'./SubscriptionLocator': this.SubscriptionLocator,
'./SubscriptionController': this.SubscriptionController,
'./SubscriptionHandler': this.SubscriptionHandler,
'../../models/Subscription': {
Subscription: this.Subscription,
},