fix(e2e): correct edit link selector and protect production player cleanup
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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("Название игры")
|
||||
|
||||
Reference in New Issue
Block a user