Merge branch 'dev' into feature/new-tariffs

# Conflicts:
#	.gitignore
#	bot/app/web/subscription_webapp.py
#	tests/test_settings.py
This commit is contained in:
3252a8
2026-04-30 10:52:20 +03:00
39 changed files with 6813 additions and 8192 deletions
+75
View File
@@ -1,3 +1,4 @@
import json
import os
import tempfile
import unittest
@@ -6,9 +7,83 @@ from types import SimpleNamespace
from unittest.mock import patch
from bot.app.web import subscription_webapp
from config.settings import Settings
class WebAppAssetTests(unittest.IsolatedAsyncioTestCase):
def test_serialize_plans_prefers_tariffs_config_over_legacy_packages(self):
with tempfile.TemporaryDirectory() as tmpdir:
path = Path(tmpdir) / "tariffs.json"
path.write_text(
json.dumps(
{
"default_tariff": "standard",
"tariffs": [
{
"key": "standard",
"names": {"en": "Standard"},
"descriptions": {"en": "100 GB monthly"},
"squad_uuids": ["uuid"],
"billing_model": "period",
"monthly_gb": 100,
"prices_rub": {"1": 150},
"prices_stars": {"1": 0},
"enabled_periods": [1],
"enabled": True,
},
{
"key": "traffic",
"names": {"en": "Traffic"},
"descriptions": {"en": "Pay as you go"},
"squad_uuids": ["uuid"],
"billing_model": "traffic",
"traffic_packages": {
"rub": [{"gb": 50, "price": 799}],
"stars": [{"gb": 50, "price": 2500}],
},
"enabled": True,
},
],
}
),
encoding="utf-8",
)
settings = Settings(
_env_file=None,
BOT_TOKEN="token",
POSTGRES_USER="app_user",
POSTGRES_PASSWORD="app_password",
TARIFFS_CONFIG_PATH=str(path),
TRAFFIC_PACKAGES="10:199",
)
plans = subscription_webapp._serialize_plans(settings, "en")
self.assertEqual([plan["tariff_key"] for plan in plans], ["standard", "traffic"])
self.assertEqual(plans[0]["sale_mode"], "subscription")
self.assertEqual(plans[0]["months"], 1)
self.assertEqual(plans[1]["sale_mode"], "traffic_package")
self.assertEqual(plans[1]["traffic_gb"], 50.0)
self.assertEqual(plans[1]["stars_price"], 2500)
def test_serialize_plans_uses_traffic_packages_in_traffic_mode(self):
settings = Settings(
_env_file=None,
BOT_TOKEN="token",
POSTGRES_USER="app_user",
POSTGRES_PASSWORD="app_password",
TARIFFS_CONFIG_PATH="missing-tariffs.json",
TRAFFIC_PACKAGES="10:199,50:799",
STARS_TRAFFIC_PACKAGES="50:2500",
)
plans = subscription_webapp._serialize_plans(settings, "en")
self.assertEqual([plan["traffic_gb"] for plan in plans], [10.0, 50.0])
self.assertEqual(plans[0]["sale_mode"], "traffic")
self.assertEqual(plans[0]["price"], 199.0)
self.assertEqual(plans[1]["stars_price"], 2500)
def test_resolve_webapp_js_asset_name_prefers_latest_minified_build(self):
with tempfile.TemporaryDirectory() as tmpdir:
asset_dir = Path(tmpdir)