Parcourir la source

Merge pull request #17822 from overleaf/jel-dash-usersBestSubscription

[web] Limit data sent to dash for best subscription when group

GitOrigin-RevId: d52101bec69cbb7931e9702e085b4aeb65d9d603
Jessica Lawshe il y a 2 ans
Parent
commit
0cfcdf5e4d

+ 5 - 1
services/web/app/src/Features/Subscription/SubscriptionViewModelBuilder.js

@@ -404,10 +404,14 @@ async function getBestSubscription(user) {
         groupSubscription.planCode
         groupSubscription.planCode
       )
       )
       if (_isPlanEqualOrBetter(plan, bestSubscription.plan)) {
       if (_isPlanEqualOrBetter(plan, bestSubscription.plan)) {
+        const groupDataForView = {}
+        if (groupSubscription.teamName) {
+          groupDataForView.teamName = groupSubscription.teamName
+        }
         const remainingTrialDays = _getRemainingTrialDays(groupSubscription)
         const remainingTrialDays = _getRemainingTrialDays(groupSubscription)
         bestSubscription = {
         bestSubscription = {
           type: 'group',
           type: 'group',
-          subscription: groupSubscription,
+          subscription: groupDataForView,
           plan,
           plan,
           remainingTrialDays,
           remainingTrialDays,
         }
         }

+ 21 - 3
services/web/test/unit/src/Subscription/SubscriptionViewModelBuilderTests.js

@@ -269,7 +269,25 @@ describe('SubscriptionViewModelBuilder', function () {
         )
         )
       assert.deepEqual(usersBestSubscription, {
       assert.deepEqual(usersBestSubscription, {
         type: 'group',
         type: 'group',
-        subscription: this.groupSubscription,
+        subscription: {},
+        plan: this.groupPlan,
+        remainingTrialDays: -1,
+      })
+    })
+
+    it('should return a group subscription with team name when user has one', async function () {
+      this.SubscriptionLocator.promises.getMemberSubscriptions
+        .withArgs(this.user)
+        .resolves([
+          Object.assign({}, this.groupSubscription, { teamName: 'test team' }),
+        ])
+      const usersBestSubscription =
+        await this.SubscriptionViewModelBuilder.promises.getBestSubscription(
+          this.user
+        )
+      assert.deepEqual(usersBestSubscription, {
+        type: 'group',
+        subscription: { teamName: 'test team' },
         plan: this.groupPlan,
         plan: this.groupPlan,
         remainingTrialDays: -1,
         remainingTrialDays: -1,
       })
       })
@@ -345,7 +363,7 @@ describe('SubscriptionViewModelBuilder', function () {
 
 
       assert.deepEqual(usersBestSubscription, {
       assert.deepEqual(usersBestSubscription, {
         type: 'group',
         type: 'group',
-        subscription: this.groupSubscription,
+        subscription: {},
         plan: this.groupPlan,
         plan: this.groupPlan,
         remainingTrialDays: -1,
         remainingTrialDays: -1,
       })
       })
@@ -434,7 +452,7 @@ describe('SubscriptionViewModelBuilder', function () {
 
 
       assert.deepEqual(usersBestSubscription, {
       assert.deepEqual(usersBestSubscription, {
         type: 'group',
         type: 'group',
-        subscription: this.groupSubscription,
+        subscription: {},
         plan: this.groupPlan,
         plan: this.groupPlan,
         remainingTrialDays: -1,
         remainingTrialDays: -1,
       })
       })