feat: add telegram guardrails for trials and referrals
This commit is contained in:
@@ -115,3 +115,95 @@ class WebAppTrialActivationTests(IsolatedAsyncioTestCase):
|
||||
mark_trial_activated.assert_awaited_once_with(session, 42)
|
||||
self.assertEqual(session.commit_count, 2)
|
||||
self.assertEqual(session.rollback_count, 0)
|
||||
|
||||
async def test_email_only_trial_activation_requires_telegram_when_disabled(self):
|
||||
session = _Session()
|
||||
settings = SimpleNamespace(
|
||||
TRIAL_ENABLED=True,
|
||||
TRIAL_DURATION_DAYS=7,
|
||||
TRIAL_TRAFFIC_LIMIT_GB=10,
|
||||
TRIAL_WITHOUT_TELEGRAM_ENABLED=False,
|
||||
DISPOSABLE_EMAIL_DOMAINS="",
|
||||
LOG_TRIAL_ACTIVATIONS=False,
|
||||
)
|
||||
db_user = SimpleNamespace(
|
||||
user_id=42,
|
||||
telegram_id=None,
|
||||
is_banned=False,
|
||||
email="email-only@example.com",
|
||||
)
|
||||
subscription_service = SimpleNamespace(activate_trial_subscription=AsyncMock())
|
||||
request = SimpleNamespace(
|
||||
app={
|
||||
"settings": settings,
|
||||
"async_session_factory": _SessionFactory(session),
|
||||
"subscription_service": subscription_service,
|
||||
}
|
||||
)
|
||||
|
||||
with (
|
||||
patch.object(billing_module, "_require_user_id", return_value=42),
|
||||
patch.object(
|
||||
billing_module,
|
||||
"_enforce_webapp_rate_limit",
|
||||
AsyncMock(return_value=None),
|
||||
),
|
||||
patch.object(
|
||||
billing_module.user_dal,
|
||||
"get_user_by_id",
|
||||
AsyncMock(return_value=db_user),
|
||||
),
|
||||
):
|
||||
response = await billing_module.activate_trial_route(request)
|
||||
|
||||
payload = json.loads(response.text)
|
||||
self.assertEqual(response.status, 400)
|
||||
self.assertEqual(payload["error"], "trial_telegram_required")
|
||||
self.assertEqual(payload["message"], "telegram_required")
|
||||
subscription_service.activate_trial_subscription.assert_not_awaited()
|
||||
|
||||
async def test_disposable_email_trial_activation_requires_telegram(self):
|
||||
session = _Session()
|
||||
settings = SimpleNamespace(
|
||||
TRIAL_ENABLED=True,
|
||||
TRIAL_DURATION_DAYS=7,
|
||||
TRIAL_TRAFFIC_LIMIT_GB=10,
|
||||
TRIAL_WITHOUT_TELEGRAM_ENABLED=True,
|
||||
DISPOSABLE_EMAIL_DOMAINS="mailinator.com,temp-mail.org",
|
||||
LOG_TRIAL_ACTIVATIONS=False,
|
||||
)
|
||||
db_user = SimpleNamespace(
|
||||
user_id=42,
|
||||
telegram_id=None,
|
||||
is_banned=False,
|
||||
email="person@mailinator.com",
|
||||
)
|
||||
subscription_service = SimpleNamespace(activate_trial_subscription=AsyncMock())
|
||||
request = SimpleNamespace(
|
||||
app={
|
||||
"settings": settings,
|
||||
"async_session_factory": _SessionFactory(session),
|
||||
"subscription_service": subscription_service,
|
||||
}
|
||||
)
|
||||
|
||||
with (
|
||||
patch.object(billing_module, "_require_user_id", return_value=42),
|
||||
patch.object(
|
||||
billing_module,
|
||||
"_enforce_webapp_rate_limit",
|
||||
AsyncMock(return_value=None),
|
||||
),
|
||||
patch.object(
|
||||
billing_module.user_dal,
|
||||
"get_user_by_id",
|
||||
AsyncMock(return_value=db_user),
|
||||
),
|
||||
):
|
||||
response = await billing_module.activate_trial_route(request)
|
||||
|
||||
payload = json.loads(response.text)
|
||||
self.assertEqual(response.status, 400)
|
||||
self.assertEqual(payload["error"], "trial_telegram_required")
|
||||
self.assertEqual(payload["message"], "disposable_email")
|
||||
subscription_service.activate_trial_subscription.assert_not_awaited()
|
||||
|
||||
Reference in New Issue
Block a user