diff --git a/tests/unit/test_points_routes.py b/tests/unit/test_points_routes.py index 2b8a7f08b..6dc9e8968 100644 --- a/tests/unit/test_points_routes.py +++ b/tests/unit/test_points_routes.py @@ -173,33 +173,46 @@ class TestSubscriptionPlans: _spec.loader.exec_module(_mod) return _mod.list_membership_plans - def test_plans_endpoint_returns_three_tiers(self): - import os # noqa: F401 (used by _import_plans_fn) - + def test_plans_endpoint_reads_admin_table(self): + """/subscription/plans 改读管理后台 plans 表:返回 catalog 服务提供的真实档位。""" list_membership_plans = self._import_plans_fn() - resp = list_membership_plans(current_user=_make_cu()) + real_plan = { + "plan_id": "premium_yearly", + "billing_cycle": "yearly", + "name": "高级会员年卡", + "description": "高级会员年度订阅,享受全部功能", + "price_cents": 39900, + "monthly_price_cents": 3325, + "duration_days": 365, + "features": { + "4K 超清分辨率": True, + "批量渲染": True, + "优先处理队列": True, + "credits_per_month": 500, + }, + } + with patch( + "packages.application.catalog.admin_catalog.get_membership_plans", + return_value=[real_plan], + ): + resp = list_membership_plans(current_user=_make_cu()) plans = resp["plans"] - plan_ids = {p["plan_id"] for p in plans} - assert plan_ids == {"monthly", "quarterly", "yearly"} - for p in plans: - assert p["price_cents"] > 0 - assert p["duration_days"] in (30, 90, 365) - assert 0 < p["points_discount"] <= 1.0 - assert "max_resolution" in p["features"] - - def test_longer_plans_cheaper_per_month(self): - import os # noqa: F401 + assert len(plans) == 1 + p0 = plans[0] + assert p0["plan_id"] == "premium_yearly" + assert p0["price_cents"] == 39900 + assert p0["duration_days"] == 365 + assert p0["features"]["4K 超清分辨率"] is True + def test_plans_endpoint_empty_when_all_disabled(self): + """后台停用全部套餐时,用户端返回空列表。""" list_membership_plans = self._import_plans_fn() - resp = list_membership_plans(current_user=_make_cu()) - plans = resp["plans"] - monthly = next(p for p in plans if p["plan_id"] == "monthly") - quarterly = next(p for p in plans if p["plan_id"] == "quarterly") - yearly = next(p for p in plans if p["plan_id"] == "yearly") - assert monthly["monthly_price_cents"] == 1990 - assert quarterly["monthly_price_cents"] < monthly["monthly_price_cents"] - assert yearly["monthly_price_cents"] < quarterly["monthly_price_cents"] - + with patch( + "packages.application.catalog.admin_catalog.get_membership_plans", + return_value=[], + ): + resp = list_membership_plans(current_user=_make_cu()) + assert resp["plans"] == [] # ── P1-7: multiplier consistency ──────────────────────────────────────