Handle future subscriptions and trial overlap correctly
This commit is contained in:
@@ -64,3 +64,39 @@ def test_ensure_signup_trial_grants_three_day_subscription(monkeypatch):
|
||||
)
|
||||
assert subscription_insert["json"]["user_id"] == "user-1"
|
||||
assert subscription_insert["json"]["source"] == "signup_trial"
|
||||
|
||||
|
||||
def test_latest_active_subscription_ignores_future_start(monkeypatch):
|
||||
monkeypatch.setenv("SUPABASE_URL", "https://example.supabase.co")
|
||||
monkeypatch.setenv("SUPABASE_ANON_KEY", "anon-key")
|
||||
monkeypatch.setenv("SUPABASE_SERVICE_ROLE_KEY", "service-role")
|
||||
|
||||
service = SupabaseEntitlementService()
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
current_trial = {
|
||||
"id": 1,
|
||||
"user_id": "user-1",
|
||||
"status": "active",
|
||||
"plan_code": "signup_trial_3d",
|
||||
"starts_at": (now - timedelta(days=1)).isoformat(),
|
||||
"expires_at": (now + timedelta(days=2)).isoformat(),
|
||||
}
|
||||
future_paid = {
|
||||
"id": 2,
|
||||
"user_id": "user-1",
|
||||
"status": "active",
|
||||
"plan_code": "pro_monthly",
|
||||
"starts_at": (now + timedelta(days=2)).isoformat(),
|
||||
"expires_at": (now + timedelta(days=32)).isoformat(),
|
||||
}
|
||||
|
||||
def _fake_get(url, headers=None, params=None, timeout=None):
|
||||
return _Response(200, [future_paid, current_trial])
|
||||
|
||||
monkeypatch.setattr(entitlement_module.requests, "get", _fake_get)
|
||||
|
||||
result = service._query_latest_active_subscription("user-1")
|
||||
|
||||
assert result is not None
|
||||
assert result["plan_code"] == "signup_trial_3d"
|
||||
|
||||
Reference in New Issue
Block a user