diff --git a/shared/plan/constants.py b/shared/plan/constants.py index a0242a44..91a0b7fa 100644 --- a/shared/plan/constants.py +++ b/shared/plan/constants.py @@ -90,6 +90,23 @@ class PlanData: monthly_uploads_limit: Optional[MonthlyUploadLimits] trial_days: Optional[TrialDaysAmount] + def convert_to_DTO(self) -> dict: + return { + "marketing_name": self.marketing_name, + "value": self.value, + "billing_rate": self.billing_rate, + "base_unit_price": self.base_unit_price, + "benefits": self.benefits, + "tier_name": self.tier_name, + "monthly_uploads_limit": self.monthly_uploads_limit, + "trial_days": self.trial_days, + "is_free_plan": self.tier_name == TierName.BASIC, + "is_pro_plan": self.tier_name == TierName.PRO, + "is_team_plan": self.tier_name == TierName.TEAM, + "is_enterprise_plan": self.tier_name == TierName.ENTERPRISE, + "is_sentry_plan": self.value in SENTRY_PAID_USER_PLAN_REPRESENTATIONS, + } + NON_PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS = { PlanName.CODECOV_PRO_MONTHLY_LEGACY.value: PlanData( diff --git a/shared/plan/service.py b/shared/plan/service.py index 66ffdf1f..55f81eb4 100644 --- a/shared/plan/service.py +++ b/shared/plan/service.py @@ -173,7 +173,7 @@ def available_plans(self, owner: Owner) -> List[PlanData]: ): available_plans += TEAM_PLAN_REPRESENTATIONS.values() - return available_plans + return [plan.convert_to_DTO() for plan in available_plans] def _start_trial_helper( self, diff --git a/tests/unit/plan/test_plan.py b/tests/unit/plan/test_plan.py index de6f4880..c82cd105 100644 --- a/tests/unit/plan/test_plan.py +++ b/tests/unit/plan/test_plan.py @@ -349,6 +349,7 @@ def test_available_plans_for_basic_plan_non_trial( expected_result.append(BASIC_PLAN) expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -365,6 +366,7 @@ def test_available_plans_for_free_plan_non_trial( expected_result.append(FREE_PLAN) expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -380,6 +382,7 @@ def test_available_plans_for_team_plan_non_trial( expected_result.append(BASIC_PLAN) expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -393,6 +396,7 @@ def test_available_plans_for_pro_plan_non_trial(self): expected_result.append(BASIC_PLAN) expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -411,6 +415,7 @@ def test_available_plans_for_sentry_customer_basic_plan_non_trial( expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -429,6 +434,7 @@ def test_available_plans_for_sentry_customer_team_plan_non_trial( expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -445,6 +451,7 @@ def test_available_plans_for_sentry_plan_non_trial(self, is_sentry_user): expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -481,6 +488,7 @@ def test_available_plans_for_basic_plan_expired_trial_less_than_10_users( expected_result.append(BASIC_PLAN) expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -496,6 +504,7 @@ def test_available_plans_for_team_plan_expired_trial_less_than_10_users( expected_result.append(BASIC_PLAN) expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -509,6 +518,7 @@ def test_available_plans_for_pro_plan_expired_trial_less_than_10_users(self): expected_result.append(BASIC_PLAN) expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -527,6 +537,7 @@ def test_available_plans_for_sentry_customer_basic_plan_expired_trial_less_than_ expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -545,6 +556,7 @@ def test_available_plans_for_sentry_customer_team_plan_expired_trial_less_than_1 expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -563,6 +575,7 @@ def test_available_plans_for_sentry_plan_expired_trial_less_than_10_users( expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -594,6 +607,7 @@ def test_available_plans_for_pro_plan_expired_trial_more_than_10_users(self): expected_result = [] expected_result.append(BASIC_PLAN) expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -611,6 +625,7 @@ def test_available_plans_for_sentry_customer_basic_plan_expired_trial_more_than_ expected_result.append(BASIC_PLAN) expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -628,6 +643,7 @@ def test_available_plans_for_sentry_plan_expired_trial_more_than_10_users( expected_result.append(BASIC_PLAN) expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] assert plan_service.available_plans(owner=self.owner) == expected_result @@ -643,6 +659,9 @@ def setUp(self): self.expected_result.append(BASIC_PLAN) self.expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() self.expected_result += TEAM_PLAN_REPRESENTATIONS.values() + self.expected_result = [ + result.convert_to_DTO() for result in self.expected_result + ] def test_currently_team_plan(self): self.current_org = OwnerFactory( @@ -700,6 +719,10 @@ def test_trial_not_started(self): self.expected_result.append(BASIC_PLAN) self.expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() self.expected_result += TEAM_PLAN_REPRESENTATIONS.values() + self.expected_result = [ + result.convert_to_DTO() for result in self.expected_result + ] + assert ( self.plan_service.available_plans(owner=self.owner) == self.expected_result ) @@ -734,6 +757,7 @@ def test_non_sentry_user(self): expected_result.append(BASIC_PLAN) expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] # Can do Team plan when plan_activated_users is null assert self.plan_service.available_plans(owner=self.owner) == expected_result @@ -751,6 +775,7 @@ def test_non_sentry_user(self): expected_result = [] expected_result.append(BASIC_PLAN) expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] # Can not do Team plan when at 11 activated users assert self.plan_service.available_plans(owner=self.owner) == expected_result @@ -765,6 +790,7 @@ def test_sentry_user(self, is_sentry_user): expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += TEAM_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] # Can do Team plan when plan_activated_users is null assert self.plan_service.available_plans(owner=self.owner) == expected_result @@ -783,6 +809,7 @@ def test_sentry_user(self, is_sentry_user): expected_result.append(BASIC_PLAN) expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values() expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values() + expected_result = [result.convert_to_DTO() for result in expected_result] # Can not do Team plan when at 11 activated users assert self.plan_service.available_plans(owner=self.owner) == expected_result