Comportement SYSTÉMATIQUE à chaque création de jeu (admin compris), pas une formalité réservée à l'inscription : /onboarding (routes/onboarding/) devient le point d'entrée unique — 4 cartes retournables (survol = explication au dos), défilement horizontal animé vers le nom du jeu. Un admin y repasse à volonté (pas de project_slug dédié, jamais bloqué/ redirigé vers un projet précédent) ; un compte "user" n'en a plus qu'un créé d'office (routes/auth/register_2fa.py), guidé ici à la place. - db/games/game_type_catalog.py : catalogue des 4 types (Quiz/ Embranchement-escape game/RPG/Créer mon jeu de A à Z), _meta['onboarding_type'] décide du "kind" du premier écran créé et si le tableau de bord complet reste accessible. - routes/games/game_dashboard.py, templates/game_dashboard_simple.html : un type restreint (quiz/embranchement/rpg) voit désormais SON tableau de bord (même route que "custom"), rendu en version simplifiée — juste ses écrans en cartes avec un aperçu RÉEL du contenu (scène mise à l'échelle par container query CSS, adaptée à la largeur réelle de la carte). "+ Ajouter un écran" n'y propose pas de choix de type : imposé par le projet (routes/screens/screens_new.py), verrouillé aussi côté serveur. - core/auth_guard.py : plus de blocage de game_dashboard par type — la restriction se fait au rendu, pas à l'accès à la route. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
172 lines
7.6 KiB
Python
172 lines
7.6 KiB
Python
"""Onboarding guidé (routes/onboarding/onboarding_new.py) : un compte
|
|
"user" fraîchement inscrit choisit un type de jeu (Quiz/Embranchement/
|
|
RPG/Créer mon jeu de A à Z) avant d'avoir accès à quoi que ce soit — voir
|
|
le plan "Fusion des deux moteurs + structure de dossiers + onboarding
|
|
guidé". Réutilise les fixtures de test_auth.py (inscription/2FA)."""
|
|
import os
|
|
|
|
import auth
|
|
import db
|
|
import screens
|
|
|
|
from tests.test_auth import _register, _confirm_2fa, _complete_onboarding, _cleanup_project, anon_client # noqa: F401
|
|
|
|
|
|
def test_account_without_a_project_is_redirected_to_onboarding(anon_client):
|
|
_register(anon_client, "needsonboarding@example.com")
|
|
_confirm_2fa(anon_client)
|
|
try:
|
|
resp = anon_client.get("/", follow_redirects=False)
|
|
assert resp.status_code == 302
|
|
assert resp.headers["Location"] == "/onboarding"
|
|
|
|
resp = anon_client.get("/onboarding")
|
|
assert resp.status_code == 200
|
|
assert "Quiz" in resp.get_data(as_text=True)
|
|
finally:
|
|
_cleanup_project("needsonboarding@example.com")
|
|
|
|
|
|
def test_quiz_lands_on_simplified_dashboard_with_one_document_screen(anon_client):
|
|
"""Le dashboard simplifié (routes/games/game_dashboard.py) — un compte
|
|
restreint (quiz/embranchement/rpg) atterrit maintenant sur SON
|
|
tableau de bord (même route que "custom"), juste rendu en version
|
|
simplifiée : que des écrans en cartes, pas d'onglets Objets/Éléments
|
|
de jeu/Variables (réservés à "Créer mon jeu de A à Z")."""
|
|
_register(anon_client, "quizuser@example.com")
|
|
_confirm_2fa(anon_client)
|
|
try:
|
|
resp = _complete_onboarding(anon_client, name="Mon Quiz", onboarding_type="quiz")
|
|
assert resp.status_code == 302
|
|
user = auth.get_user_by_email("quizuser@example.com")
|
|
slug = user["project_slug"]
|
|
assert resp.headers["Location"] == f"/game/{slug}"
|
|
assert db.get_onboarding_type(slug) == "quiz"
|
|
|
|
screen_list = screens.list_screens(slug)
|
|
assert len(screen_list) == 1
|
|
assert screen_list[0]["kind"] == "document"
|
|
|
|
html = anon_client.get(f"/game/{slug}").get_data(as_text=True)
|
|
assert "screenCardGrid" in html
|
|
assert "+ Ajouter un écran" in html
|
|
assert 'name="kind"' not in html # pas de choix de type à l'ajout
|
|
assert "openNewObjectPanel" not in html # onglet Objets du dashboard complet absent
|
|
|
|
# L'éditeur de l'écran, lui, reste atteignable comme avant.
|
|
edit_html = anon_client.get(f"/game/{slug}/screens/{screen_list[0]['id']}/edit").get_data(as_text=True)
|
|
assert "scene-editor.js" not in edit_html
|
|
finally:
|
|
_cleanup_project("quizuser@example.com")
|
|
|
|
|
|
def test_rpg_dashboard_shows_scene_preview_and_forces_jeu2d_on_new_screens(anon_client):
|
|
_register(anon_client, "rpguser@example.com")
|
|
_confirm_2fa(anon_client)
|
|
try:
|
|
resp = _complete_onboarding(anon_client, name="Mon RPG", onboarding_type="rpg")
|
|
slug = auth.get_user_by_email("rpguser@example.com")["project_slug"]
|
|
assert resp.headers["Location"] == f"/game/{slug}"
|
|
screen_list = screens.list_screens(slug)
|
|
assert screen_list[0]["kind"] == "jeu_2d"
|
|
|
|
html = anon_client.get(f"/game/{slug}").get_data(as_text=True)
|
|
assert "screenPreviewScene" in html
|
|
assert 'name="kind"' not in html
|
|
|
|
# "+ Ajouter un écran" ne propose pas de choix de type — imposé
|
|
# jeu_2d par le projet, même en tentant de forcer "document" via
|
|
# un POST direct (défense en profondeur, pas seulement l'UI).
|
|
anon_client.post(f"/game/{slug}/screens/new", data={"name": "Scène 2", "kind": "document"}, follow_redirects=False)
|
|
new_screen_list = screens.list_screens(slug)
|
|
assert len(new_screen_list) == 2
|
|
assert new_screen_list[1]["kind"] == "jeu_2d"
|
|
|
|
edit_html = anon_client.get(f"/game/{slug}/screens/{screen_list[0]['id']}/edit").get_data(as_text=True)
|
|
assert "scene-editor.js" in edit_html
|
|
finally:
|
|
_cleanup_project("rpguser@example.com")
|
|
|
|
|
|
def test_custom_keeps_todays_full_dashboard_behavior(anon_client):
|
|
_register(anon_client, "customuser@example.com")
|
|
_confirm_2fa(anon_client)
|
|
try:
|
|
resp = _complete_onboarding(anon_client, name="Mon jeu complet", onboarding_type="custom")
|
|
assert resp.status_code == 302
|
|
|
|
slug = auth.get_user_by_email("customuser@example.com")["project_slug"]
|
|
assert resp.headers["Location"] == f"/game/{slug}"
|
|
|
|
html = anon_client.get(f"/game/{slug}").get_data(as_text=True)
|
|
assert "Tableau de bord" in html or "gameNavLink" in html
|
|
finally:
|
|
_cleanup_project("customuser@example.com")
|
|
|
|
|
|
def test_onboarding_rejects_unknown_type(anon_client):
|
|
_register(anon_client, "badtype@example.com")
|
|
_confirm_2fa(anon_client)
|
|
try:
|
|
resp = anon_client.post("/onboarding", data={"onboarding_type": "n_importe_quoi", "name": "Test"})
|
|
assert resp.status_code == 200
|
|
assert auth.get_user_by_email("badtype@example.com")["project_slug"] is None
|
|
finally:
|
|
_cleanup_project("badtype@example.com")
|
|
|
|
|
|
def test_revisiting_onboarding_after_completion_redirects_without_recreating(anon_client):
|
|
_register(anon_client, "revisit@example.com")
|
|
_confirm_2fa(anon_client)
|
|
try:
|
|
first = _complete_onboarding(anon_client, name="Premier jeu", onboarding_type="custom")
|
|
first_slug = auth.get_user_by_email("revisit@example.com")["project_slug"]
|
|
|
|
resp = anon_client.get("/onboarding", follow_redirects=False)
|
|
assert resp.status_code == 302
|
|
assert resp.headers["Location"] == first.headers["Location"]
|
|
|
|
again = anon_client.post("/onboarding", data={"onboarding_type": "quiz", "name": "Second jeu"}, follow_redirects=False)
|
|
assert auth.get_user_by_email("revisit@example.com")["project_slug"] == first_slug
|
|
assert again.headers["Location"] == first.headers["Location"]
|
|
finally:
|
|
_cleanup_project("revisit@example.com")
|
|
|
|
|
|
def test_admin_is_never_redirected_to_onboarding(client, game):
|
|
resp = client.get("/", follow_redirects=False)
|
|
assert resp.status_code == 200
|
|
|
|
|
|
def test_admin_can_create_several_games_of_different_types_via_onboarding(client):
|
|
"""Comportement systématique à CHAQUE création de jeu, pas une
|
|
formalité réservée à la toute première inscription (voir le plan) —
|
|
un admin, illimité (pas de project_slug dédié), doit pouvoir repasser
|
|
par /onboarding autant de fois qu'il crée un nouveau jeu, sans jamais
|
|
être bloqué/redirigé vers un projet précédent."""
|
|
resp1 = _complete_onboarding(client, name="Jeu Quiz Admin", onboarding_type="quiz")
|
|
assert resp1.status_code == 302
|
|
slug1 = resp1.headers["Location"].split("/game/", 1)[1].split("/", 1)[0]
|
|
slug2 = None
|
|
try:
|
|
# project_slug reste NON posé sur le compte admin (voir
|
|
# auth/create_user.py — colonne réservée à un compte "user" à
|
|
# projet unique) : repasser sur /onboarding ne redirige PAS vers
|
|
# le premier projet créé, la page de choix s'affiche à nouveau.
|
|
resp = client.get("/onboarding")
|
|
assert resp.status_code == 200
|
|
assert "Quiz" in resp.get_data(as_text=True)
|
|
|
|
resp2 = _complete_onboarding(client, name="Jeu RPG Admin", onboarding_type="rpg")
|
|
assert resp2.status_code == 302
|
|
slug2 = resp2.headers["Location"].split("/game/", 1)[1].split("/", 1)[0]
|
|
assert slug2 != slug1
|
|
|
|
slugs = {g["slug"] for g in db.list_games()}
|
|
assert slug1 in slugs
|
|
assert slug2 in slugs
|
|
finally:
|
|
for slug in (slug1, slug2):
|
|
if slug and os.path.isdir(db.game_dir(slug)):
|
|
db.delete_game(slug)
|