Skip to content

Commit

Permalink
fix: Update available plan to remove trial condition (#379)
Browse files Browse the repository at this point in the history
* fix: Update available plan to remove trial condition

* Update tests

* local tests take forever
  • Loading branch information
RulaKhaled authored Feb 8, 2024
1 parent df07ebd commit 3124dbf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 74 deletions.
69 changes: 5 additions & 64 deletions api/internal/tests/views/test_account_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,62 +849,6 @@ def test_update_must_fail_if_quantity_and_plan_are_equal_to_the_owners_current_o
== "Quantity or plan for paid plan must be different from the existing one"
)

def test_update_team_plan_must_fail_if_not_trialing(self):
self.current_owner.plan = PlanName.BASIC_PLAN_NAME.value
self.current_owner.plan_user_count = 1
self.current_owner.trial_status = TrialStatus.NOT_STARTED
self.current_owner.save()
desired_plans = [
{"value": PlanName.TEAM_MONTHLY.value, "quantity": 1},
{"value": PlanName.TEAM_YEARLY.value, "quantity": 1},
]

for desired_plan in desired_plans:
response = self._update(
kwargs={
"service": self.current_owner.service,
"owner_username": self.current_owner.username,
},
data={"plan": desired_plan},
)

assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.json() == {
"plan": {
"value": [
f"Invalid value for plan: {desired_plan['value']}; must be one of ['users-basic', 'users-pr-inappm', 'users-pr-inappy']"
]
}
}

def test_update_team_plan_must_fail_if_cannot_trial(self):
self.current_owner.plan = PlanName.BASIC_PLAN_NAME.value
self.current_owner.plan_user_count = 1
self.current_owner.trial_status = TrialStatus.CANNOT_TRIAL
self.current_owner.save()
desired_plans = [
{"value": PlanName.TEAM_MONTHLY.value, "quantity": 1},
{"value": PlanName.TEAM_YEARLY.value, "quantity": 1},
]

for desired_plan in desired_plans:
response = self._update(
kwargs={
"service": self.current_owner.service,
"owner_username": self.current_owner.username,
},
data={"plan": desired_plan},
)

assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.json() == {
"plan": {
"value": [
f"Invalid value for plan: {desired_plan['value']}; must be one of ['users-basic', 'users-pr-inappm', 'users-pr-inappy']"
]
}
}

def test_update_team_plan_must_fail_if_too_many_activated_users_during_trial(self):
self.current_owner.plan = PlanName.BASIC_PLAN_NAME.value
self.current_owner.plan_user_count = 1
Expand Down Expand Up @@ -975,13 +919,10 @@ def test_update_must_fail_if_team_plan_and_too_many_users(self):
)

assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.json() == {
"plan": {
"value": [
f"Invalid value for plan: {desired_plan['value']}; must be one of ['users-basic', 'users-pr-inappm', 'users-pr-inappy']"
]
}
}
assert (
response.data["plan"]["non_field_errors"][0]
== "Quantity for Team plan cannot exceed 10"
)

def test_update_quantity_must_be_at_least_2_if_paid_plan(self):
desired_plan = {"value": PlanName.CODECOV_PRO_YEARLY.value, "quantity": 1}
Expand Down Expand Up @@ -1285,7 +1226,7 @@ def test_update_sentry_plan_non_sentry_user(
assert res.json() == {
"plan": {
"value": [
"Invalid value for plan: users-sentrym; must be one of ['users-basic', 'users-pr-inappm', 'users-pr-inappy']"
"Invalid value for plan: users-sentrym; must be one of ['users-basic', 'users-pr-inappm', 'users-pr-inappy', 'users-teamm', 'users-teamy']"
]
}
}
Expand Down
2 changes: 2 additions & 0 deletions graphql_api/tests/test_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ def test_owner_available_plans(self):
{"planName": "users-basic"},
{"planName": "users-pr-inappm"},
{"planName": "users-pr-inappy"},
{"planName": "users-teamm"},
{"planName": "users-teamy"},
]

def test_owner_query_with_no_service(self):
Expand Down
14 changes: 4 additions & 10 deletions plan/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,12 @@ def available_plans(self, owner: Owner) -> List[PlanData]:
if owner and sentry.is_sentry_user(owner=owner):
available_plans += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values()

# If user is already in team plan or is/have trialed
# If number of activated users is less than or equal to TEAM_PLAN_MAX_USERS
if (
self.plan_name in TEAM_PLAN_REPRESENTATIONS
or self.trial_status == TrialStatus.EXPIRED.value
or self.trial_status == TrialStatus.ONGOING.value
self.plan_activated_users is None
or len(self.plan_activated_users) <= TEAM_PLAN_MAX_USERS
):
# If number of activated users is less than or equal to TEAM_PLAN_MAX_USERS
if (
self.plan_activated_users is None
or len(self.plan_activated_users) <= TEAM_PLAN_MAX_USERS
):
available_plans += TEAM_PLAN_REPRESENTATIONS.values()
available_plans += TEAM_PLAN_REPRESENTATIONS.values()

return available_plans

Expand Down
6 changes: 6 additions & 0 deletions plan/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def test_available_plans_for_basic_plan_non_trial(
expected_result = []
expected_result.append(BASIC_PLAN)
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
expected_result += TEAM_PLAN_REPRESENTATIONS.values()

assert plan_service.available_plans(owner=self.owner) == expected_result

Expand All @@ -362,6 +363,7 @@ def test_available_plans_for_free_plan_non_trial(
expected_result.append(BASIC_PLAN)
expected_result.append(FREE_PLAN)
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
expected_result += TEAM_PLAN_REPRESENTATIONS.values()

assert plan_service.available_plans(owner=self.owner) == expected_result

Expand Down Expand Up @@ -389,6 +391,7 @@ def test_available_plans_for_pro_plan_non_trial(self):
expected_result = []
expected_result.append(BASIC_PLAN)
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
expected_result += TEAM_PLAN_REPRESENTATIONS.values()

assert plan_service.available_plans(owner=self.owner) == expected_result

Expand All @@ -406,6 +409,7 @@ def test_available_plans_for_sentry_customer_basic_plan_non_trial(
expected_result.append(BASIC_PLAN)
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values()
expected_result += TEAM_PLAN_REPRESENTATIONS.values()

assert plan_service.available_plans(owner=self.owner) == expected_result

Expand Down Expand Up @@ -439,6 +443,7 @@ def test_available_plans_for_sentry_plan_non_trial(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 += TEAM_PLAN_REPRESENTATIONS.values()

assert plan_service.available_plans(owner=self.owner) == expected_result

Expand Down Expand Up @@ -693,6 +698,7 @@ def test_trial_not_started(self):
self.expected_result = []
self.expected_result.append(BASIC_PLAN)
self.expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
self.expected_result += TEAM_PLAN_REPRESENTATIONS.values()
assert (
self.plan_service.available_plans(owner=self.owner) == self.expected_result
)
Expand Down

0 comments on commit 3124dbf

Please sign in to comment.