diff --git a/services/web/app/src/Features/User/UserUpdater.js b/services/web/app/src/Features/User/UserUpdater.js index 1d6cf99797..0ccdb1bd1b 100644 --- a/services/web/app/src/Features/User/UserUpdater.js +++ b/services/web/app/src/Features/User/UserUpdater.js @@ -295,7 +295,7 @@ async function maybeCreateRedundantSubscriptionNotification(userId, email) { userId ) const confirmedAffiliation = affiliations.find(a => a.email === email) - if (confirmedAffiliation.licence === 'free') { + if (!confirmedAffiliation || confirmedAffiliation.licence === 'free') { return } diff --git a/services/web/test/unit/src/User/UserUpdaterTests.js b/services/web/test/unit/src/User/UserUpdaterTests.js index 5ddf2d6e7a..02686b6e2f 100644 --- a/services/web/test/unit/src/User/UserUpdaterTests.js +++ b/services/web/test/unit/src/User/UserUpdaterTests.js @@ -928,6 +928,18 @@ describe('UserUpdater', function () { ) }) + it('should not call redundantPersonalSubscription when user is not on a commons license', async function () { + this.InstitutionsAPI.promises.getUserAffiliations.resolves([]) + this.SubscriptionLocator.promises.getUserIndividualSubscription.resolves({ + planCode: 'personal', + groupPlan: false, + }) + await this.UserUpdater.promises.confirmEmail(this.user._id, this.newEmail) + sinon.assert.notCalled( + this.NotificationsBuilder.promises.redundantPersonalSubscription + ) + }) + describe('with institution licence and subscription', function () { beforeEach(async function () { this.affiliation = {