From 747bd76c3e8b7fda7cd5269048c6e3bf7e14bdec Mon Sep 17 00:00:00 2001 From: Toutsu Date: Tue, 16 Jun 2026 13:35:05 +0300 Subject: [PATCH] fix(e2e): correct edit link selector and protect production player cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue #150 follow-up: clicking the session title only expands participants, so click the explicit 'Изменить' edit link. Cleanup now only deletes the player row when the test was the sole owner, avoiding accidental removal of the real Toutsu account from production. Co-Authored-By: Claude Opus 4.8 --- .../test_dashboard_auth_and_sessions.py | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) 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("Название игры")