diff --git a/tests/e2e/dashboard/test_dashboard_auth_and_sessions.py b/tests/e2e/dashboard/test_dashboard_auth_and_sessions.py index b60cf52..93293ea 100644 --- a/tests/e2e/dashboard/test_dashboard_auth_and_sessions.py +++ b/tests/e2e/dashboard/test_dashboard_auth_and_sessions.py @@ -212,16 +212,42 @@ def _delete_test_data(group_id: str, session_id: str) -> None: if not dsn: return + telegram_id = str(_telegram_id()) with psycopg2.connect(dsn) as conn: with conn.cursor() as cur: cur.execute("DELETE FROM gmrelay.session_participants WHERE session_id = %s", (session_id,)) cur.execute("DELETE FROM gmrelay.sessions WHERE id = %s", (session_id,)) cur.execute("DELETE FROM gmrelay.group_managers WHERE group_id = %s", (group_id,)) cur.execute("DELETE FROM gmrelay.game_groups WHERE id = %s", (group_id,)) + + # Only remove the player if the test created it. If the Telegram ID + # belongs to a real production user (e.g. the Toutsu account), leave + # the row intact so we do not break that account. cur.execute( - "DELETE FROM gmrelay.players WHERE external_user_id = %s AND platform = 'Telegram'", - (str(_telegram_id()),), + "SELECT id FROM gmrelay.players WHERE platform = 'Telegram' AND external_user_id = %s", + (telegram_id,), ) + if cur.fetchone() is not None: + # Determine whether this player has any other groups or sessions. + cur.execute( + "SELECT COUNT(*) FROM gmrelay.group_managers m " + "JOIN gmrelay.players p ON p.id = m.player_id " + "WHERE p.platform = 'Telegram' AND p.external_user_id = %s", + (telegram_id,), + ) + manager_count = cur.fetchone()[0] + cur.execute( + "SELECT COUNT(*) FROM gmrelay.session_participants sp " + "JOIN gmrelay.players p ON p.id = sp.player_id " + "WHERE p.platform = 'Telegram' AND p.external_user_id = %s", + (telegram_id,), + ) + participant_count = cur.fetchone()[0] + if manager_count == 0 and participant_count == 0: + cur.execute( + "DELETE FROM gmrelay.players WHERE platform = 'Telegram' AND external_user_id = %s", + (telegram_id,), + ) conn.commit() @@ -303,7 +329,7 @@ def test_dashboard_session_edit_flow() -> None: page.goto(f"{base_url}/group/{group_id}") page.wait_for_selector(f"text={original_title}", timeout=15000) - page.locator(f"text={original_title}").first.click() + page.locator("a:has-text('Изменить')").first.click() page.wait_for_selector("text=Редактирование сессии", timeout=15000) title_input = page.get_by_label("Название игры")