Prevent Group subscription admins from deleting their own group subscription when invited to join

GitOrigin-RevId: a467a690cf4ee8b1a1081496205559a7f183a1f9
This commit is contained in:
Simon Gardner
2025-10-07 08:06:00 +00:00
committed by Copybot
parent 14356f2675
commit 1bef1bb1d4
2 changed files with 71 additions and 33 deletions
@@ -344,12 +344,27 @@ describe('TeamInvitesHandler', function () {
email: 'tyrion@example.com',
}
this.user_subscription = {
id: '66264b9125930b976cc0811e',
_id: new ObjectId('66264b9125930b976cc0811e'),
groupPlan: false,
recurlySubscription_id: 'fa1b2cfa156gh',
admin_id: '123456789',
member_ids: [],
teamInvites: [],
save: sinon.stub().resolves(),
}
this.ipAddress = '127.0.0.1'
this.UserGetter.promises.getUserByAnyEmail
.withArgs(this.user.email)
.resolves(this.user)
this.SubscriptionLocator.promises.getUsersSubscription
.withArgs(this.user.id)
.resolves(this.user_subscription)
this.subscription.teamInvites.push({
email: 'john.snow@example.com',
token: 'dddddddd',
@@ -421,12 +436,12 @@ describe('TeamInvitesHandler', function () {
)
sinon.assert.calledWith(
this.SubscriptionUpdater.promises.deleteSubscription,
this.subscription,
this.user_subscription,
{ id: this.user.id, ip: this.ipAddress }
)
sinon.assert.calledWith(
this.RecurlyClient.promises.terminateSubscriptionByUuid,
this.subscription.recurlySubscription_id
this.user_subscription.recurlySubscription_id
)
sinon.assert.calledWith(
this.Modules.promises.hooks.fire,
@@ -435,6 +450,23 @@ describe('TeamInvitesHandler', function () {
this.subscription
)
})
it('should not delete the users subscription if that subscription is also the join target', async function () {
this.subscription.managedUsersEnabled = true
this.SubscriptionLocator.promises.getUsersSubscription
.withArgs(this.user.id)
.resolves(this.subscription)
await this.TeamInvitesHandler.promises.acceptInvite(
'dddddddd',
this.user.id,
this.ipAddress
)
sinon.assert.notCalled(
this.SubscriptionUpdater.promises.deleteSubscription
)
})
})
describe('with group SSO enabled', function () {