Skip to content

Commit

Permalink
feat: Map helper functions to available plans (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
RulaKhaled authored Dec 19, 2024
1 parent 2674ae9 commit 3616116
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
17 changes: 17 additions & 0 deletions shared/plan/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion shared/plan/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/plan/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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(
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3616116

Please sign in to comment.