Merge pull request #29982 from overleaf/ls-group-ownership-transfer

Stripe subscription ownership transfer

GitOrigin-RevId: 8285f635ecc220595782fbea6def74fdc9a92f36
This commit is contained in:
Liangjun Song
2025-12-11 09:05:57 +00:00
committed by Copybot
parent 427419e6a5
commit 7effe4630f
3 changed files with 135 additions and 23 deletions
@@ -303,6 +303,81 @@ describe('SubscriptionUpdater', function () {
})
})
describe('transferSubscriptionOwnership', function () {
it('should transfer the subscription ownership for group subscriptions', async function (ctx) {
ctx.subscription.groupPlan = true
ctx.subscription.paymentProvider = {
id: 'stripe-123',
name: 'stripe-us',
}
await ctx.SubscriptionUpdater.promises.transferSubscriptionOwnership(
ctx.subscription,
ctx.otherUserId,
false
)
const query = {
_id: new ObjectId(ctx.subscription._id),
}
const update = {
$set: {
admin_id: new ObjectId(ctx.otherUserId),
previousPaymentProvider: ctx.subscription.paymentProvider,
},
$addToSet: { manager_ids: new ObjectId(ctx.otherUserId) },
}
ctx.SubscriptionModel.updateOne.should.have.been.calledOnce
ctx.SubscriptionModel.updateOne.should.have.been.calledWith(query, update)
})
it('should transfer the subscription ownership for non-group subscriptions', async function (ctx) {
ctx.subscription.paymentProvider = {
id: 'stripe-123',
name: 'stripe-us',
}
await ctx.SubscriptionUpdater.promises.transferSubscriptionOwnership(
ctx.subscription,
ctx.otherUserId,
false
)
const query = {
_id: new ObjectId(ctx.subscription._id),
}
const update = {
$set: {
admin_id: new ObjectId(ctx.otherUserId),
manager_ids: [new ObjectId(ctx.otherUserId)],
previousPaymentProvider: ctx.subscription.paymentProvider,
},
}
ctx.SubscriptionModel.updateOne.should.have.been.calledOnce
ctx.SubscriptionModel.updateOne.should.have.been.calledWith(query, update)
})
it('should clear previousPaymentProvider when clearPreviousPaymentProvider is true', async function (ctx) {
ctx.subscription.paymentProvider = {
id: 'stripe-123',
name: 'stripe-us',
}
await ctx.SubscriptionUpdater.promises.transferSubscriptionOwnership(
ctx.subscription,
ctx.otherUserId,
true
)
const query = {
_id: new ObjectId(ctx.subscription._id),
}
const update = {
$set: {
admin_id: new ObjectId(ctx.otherUserId),
manager_ids: [new ObjectId(ctx.otherUserId)],
},
$unset: { previousPaymentProvider: 1 },
}
ctx.SubscriptionModel.updateOne.should.have.been.calledOnce
ctx.SubscriptionModel.updateOne.should.have.been.calledWith(query, update)
})
})
describe('syncSubscription', function () {
beforeEach(function (ctx) {
ctx.SubscriptionLocator.promises.getUsersSubscription.resolves(