feat(billing): add complimentary status, fix is_paid, add has_pro_entitlement
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
41
backend/tests/test_subscription_properties.py
Normal file
41
backend/tests/test_subscription_properties.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from app.models.subscription import Subscription
|
||||
|
||||
|
||||
def make_sub(**kwargs):
|
||||
sub = Subscription()
|
||||
sub.plan = kwargs.get("plan", "free")
|
||||
sub.status = kwargs.get("status", "active")
|
||||
sub.current_period_end = kwargs.get("current_period_end")
|
||||
return sub
|
||||
|
||||
|
||||
def test_complimentary_is_active_but_not_paid():
|
||||
sub = make_sub(plan="pro", status="complimentary")
|
||||
assert sub.is_active is True
|
||||
assert sub.is_paid is False
|
||||
assert sub.has_pro_entitlement is True
|
||||
|
||||
|
||||
def test_paid_pro_active():
|
||||
sub = make_sub(plan="pro", status="active")
|
||||
assert sub.is_paid is True
|
||||
assert sub.has_pro_entitlement is True
|
||||
|
||||
|
||||
def test_trial_unexpired_has_entitlement():
|
||||
sub = make_sub(plan="pro", status="trialing", current_period_end=datetime.now(timezone.utc) + timedelta(days=5))
|
||||
assert sub.is_active is True
|
||||
assert sub.is_paid is False
|
||||
assert sub.has_pro_entitlement is True
|
||||
|
||||
|
||||
def test_trial_expired_no_entitlement():
|
||||
sub = make_sub(plan="pro", status="trialing", current_period_end=datetime.now(timezone.utc) - timedelta(hours=1))
|
||||
assert sub.has_pro_entitlement is False
|
||||
|
||||
|
||||
def test_canceled_no_entitlement():
|
||||
sub = make_sub(plan="pro", status="canceled")
|
||||
assert sub.is_active is False
|
||||
assert sub.has_pro_entitlement is False
|
||||
Reference in New Issue
Block a user