From 7794e03dcbda72c562c6d994c739f57eefe8ee09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Alby?= Date: Tue, 14 Jun 2022 10:14:10 +0200 Subject: [PATCH] Merge pull request #8363 from overleaf/jel-affiliation-check [web] Handle when no affiliation found for redundant subscription check GitOrigin-RevId: c0e653b944b994c5eafaa2d4f2d54f3cb57d67fa --- services/web/app/src/Features/User/UserUpdater.js | 2 +- services/web/test/unit/src/User/UserUpdaterTests.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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 = {