forked from GithubBackups/healthchecks
Make sure account limits are reset when user cancels their subscription.
This commit is contained in:
parent
dde2910c59
commit
4c39aeea83
@ -150,11 +150,36 @@ class SetPlanTestCase(BaseTestCase):
|
||||
|
||||
@patch("hc.payments.models.braintree")
|
||||
def test_subscription_creation_failure(self, mock):
|
||||
self._setup_mock(mock)
|
||||
|
||||
mock.Subscription.create.return_value.is_success = False
|
||||
mock.Subscription.create.return_value.message = "sub failure"
|
||||
|
||||
r = self.run_set_plan()
|
||||
self.assertRedirects(r, "/accounts/profile/billing/")
|
||||
self.assertContains(r, "sub failure")
|
||||
|
||||
@patch("hc.payments.models.braintree")
|
||||
def test_failed_plan_change_resets_limits(self, mock):
|
||||
# Initial state: the user has a subscription and a high check limit:
|
||||
sub = Subscription.objects.for_user(self.alice)
|
||||
sub.subscription_id = "old-sub-id"
|
||||
sub.save()
|
||||
|
||||
self.profile.check_limit = 1000
|
||||
self.profile.save()
|
||||
|
||||
# Simulate a subscription creation failure:
|
||||
mock.Subscription.create.return_value.is_success = False
|
||||
mock.Subscription.create.return_value.message = "sub failure"
|
||||
|
||||
r = self.run_set_plan()
|
||||
|
||||
# It should cancel the current plan
|
||||
self.assertTrue(mock.Subscription.cancel.called)
|
||||
|
||||
# It should clear out the limits:
|
||||
self.profile.refresh_from_db()
|
||||
self.assertEqual(self.profile.check_limit, 20)
|
||||
|
||||
# And it should show the error message from API:
|
||||
self.assertRedirects(r, "/accounts/profile/billing/")
|
||||
self.assertContains(r, "sub failure")
|
||||
|
@ -105,15 +105,17 @@ def set_plan(request):
|
||||
if sub.plan_id == plan_id:
|
||||
return redirect("hc-billing")
|
||||
|
||||
# Cancel the previous plan
|
||||
# Cancel the previous plan and reset limits:
|
||||
sub.cancel()
|
||||
|
||||
profile = request.user.profile
|
||||
profile.ping_log_limit = 100
|
||||
profile.check_limit = 20
|
||||
profile.team_limit = 2
|
||||
profile.sms_limit = 0
|
||||
profile.save()
|
||||
|
||||
if plan_id == "":
|
||||
profile = request.user.profile
|
||||
profile.ping_log_limit = 100
|
||||
profile.check_limit = 20
|
||||
profile.team_limit = 2
|
||||
profile.sms_limit = 0
|
||||
profile.save()
|
||||
return redirect("hc-billing")
|
||||
|
||||
result = sub.setup(plan_id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user