Fix affichage jours d'essai
This commit is contained in:
@@ -29,9 +29,7 @@ def _plan_card(meta: dict, trial: int | None, trial_used: bool):
|
|||||||
className="text-muted mb-2",
|
className="text-muted mb-2",
|
||||||
)
|
)
|
||||||
elif trial:
|
elif trial:
|
||||||
badge = html.Div(
|
badge = html.Div(f"{trial} jours d'essai gratuit", className="mb-2")
|
||||||
f"{trial} jours d'essai gratuit", className="text-success mb-2"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
badge = None
|
badge = None
|
||||||
return dbc.Card(
|
return dbc.Card(
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ def _handle(env_name: str) -> str:
|
|||||||
PLANS = {
|
PLANS = {
|
||||||
"simple": {
|
"simple": {
|
||||||
"env": "FRISBII_PLAN_SIMPLE",
|
"env": "FRISBII_PLAN_SIMPLE",
|
||||||
"label": "Abonnement simple",
|
"label": "Abonnement",
|
||||||
"prix_ht": 20,
|
"prix_ht": 20,
|
||||||
"description": "Accès à des fonctionnalités supplémentaires de decp.info.",
|
"description": "Accès à des fonctionnalités supplémentaires de decp.info.",
|
||||||
},
|
},
|
||||||
@@ -50,14 +50,11 @@ def plan_meta(key: str) -> dict | None:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _parse_trial_interval(value) -> int | None:
|
def _parse_trial_interval(plan: dict) -> int | None:
|
||||||
# Reepay/Frisbii renvoie une durée type "2d" (jours), "1m" (mois), etc.
|
unit = plan.get("trial_interval_unit", "")
|
||||||
# On ne sait afficher que les jours pour l'instant ; format à confirmer.
|
length = plan.get("trial_interval_length")
|
||||||
if not value or not isinstance(value, str):
|
if unit == "days" and isinstance(length, int) and length > 0:
|
||||||
return None
|
return length
|
||||||
value = value.strip().lower()
|
|
||||||
if value.endswith("d") and value[:-1].isdigit():
|
|
||||||
return int(value[:-1])
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -77,6 +74,6 @@ def trial_days(key: str) -> int | None:
|
|||||||
# L'API Frisbii/Reepay renvoie une liste de versions ; on prend la dernière (la plus récente).
|
# L'API Frisbii/Reepay renvoie une liste de versions ; on prend la dernière (la plus récente).
|
||||||
if isinstance(plan, list):
|
if isinstance(plan, list):
|
||||||
plan = plan[-1] if plan else {}
|
plan = plan[-1] if plan else {}
|
||||||
days = _parse_trial_interval(plan.get("trial_interval"))
|
days = _parse_trial_interval(plan)
|
||||||
_trial_cache[handle] = (now, days)
|
_trial_cache[handle] = (now, days)
|
||||||
return days
|
return days
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ def test_trial_days_parses_and_caches(monkeypatch):
|
|||||||
|
|
||||||
def fake_get_plan(handle):
|
def fake_get_plan(handle):
|
||||||
calls.append(handle)
|
calls.append(handle)
|
||||||
return {"trial_interval": "2d"}
|
return {"trial_interval_unit": "days", "trial_interval_length": 2}
|
||||||
|
|
||||||
monkeypatch.setattr(client, "get_plan", fake_get_plan)
|
monkeypatch.setattr(client, "get_plan", fake_get_plan)
|
||||||
assert plans.trial_days("simple") == 2
|
assert plans.trial_days("simple") == 2
|
||||||
@@ -37,7 +37,7 @@ def test_trial_days_none_on_error(monkeypatch):
|
|||||||
|
|
||||||
|
|
||||||
def test_trial_days_none_when_no_trial(monkeypatch):
|
def test_trial_days_none_when_no_trial(monkeypatch):
|
||||||
monkeypatch.setattr(client, "get_plan", lambda h: {"trial_interval": None})
|
monkeypatch.setattr(client, "get_plan", lambda h: {})
|
||||||
assert plans.trial_days("simple") is None
|
assert plans.trial_days("simple") is None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user