Группы: приглашения вместо авто-добавления (согласиться/отказаться)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-17 20:07:20 +03:00
co-authored by Claude Opus 4.8
parent 66370c7df4
commit a5c54512a5
20 changed files with 742 additions and 98 deletions
+14 -36
View File
@@ -3,7 +3,7 @@ from __future__ import annotations
from fastapi.testclient import TestClient
from tests.conftest import csrf_headers, finish_match, login, start_match
from tests.conftest import add_group_member, csrf_headers, finish_match, login, start_match
def _expansion_id(client: TestClient, code: str) -> int:
@@ -12,7 +12,7 @@ def _expansion_id(client: TestClient, code: str) -> int:
return next(e["id"] for e in r.json() if e["code"] == code)
def test_full_flow(client: TestClient, make_admin):
def test_full_flow(client: TestClient, make_admin, engine):
# 1) Вход игрока A — групп ещё нет.
me = login(client, "Иван")
assert me["groups"] == []
@@ -44,18 +44,8 @@ def test_full_flow(client: TestClient, make_admin):
me = client.get("/api/users/me").json()
assert me["active_group_id"] == gid
# 4) Создать игрока B и добавить в группу по нику.
rb = client.post(
"/api/auth/dev/users", json={"nickname": "Олег"}, headers=csrf_headers(client)
)
assert rb.status_code == 200, rb.text
r = client.post(
f"/api/groups/{gid}/members",
json={"nickname": "Олег"},
headers=csrf_headers(client),
)
assert r.status_code == 200, r.text
b_id = r.json()["user_id"]
# 4) Игрок B в группе (прямое добавление — подготовка данных; UX-путь теперь приглашения).
b_id = add_group_member(engine, gid, "Олег")
# 5) Доступные фракции = база (4) + Forgotten Worlds (4) = 8.
factions = client.get(f"/api/groups/{gid}/factions").json()
@@ -150,15 +140,12 @@ def test_full_flow(client: TestClient, make_admin):
assert {"Иван", "Олег"}.issubset(nicks)
def test_in_progress_excluded_and_win_reason_required(client: TestClient):
def test_in_progress_excluded_and_win_reason_required(client: TestClient, engine):
me = login(client, "Хост")
gid = client.post(
"/api/groups", json={"name": "Группа", "expansion_ids": []}, headers=csrf_headers(client)
).json()["id"]
client.post("/api/auth/dev/users", json={"nickname": "Гость2"}, headers=csrf_headers(client))
b = client.post(
f"/api/groups/{gid}/members", json={"nickname": "Гость2"}, headers=csrf_headers(client)
).json()["user_id"]
b = add_group_member(engine, gid, "Гость2")
factions = client.get(f"/api/groups/{gid}/factions").json()
f1, f2 = factions[0]["id"], factions[1]["id"]
@@ -202,16 +189,13 @@ def test_in_progress_excluded_and_win_reason_required(client: TestClient):
assert all(x["id"] != mid for x in client.get("/api/home").json()["in_progress"])
def test_owner_can_finish_member_started_match(client: TestClient):
def test_owner_can_finish_member_started_match(client: TestClient, engine):
"""Владелец группы может завершить партию, начатую другим участником (can_modify с бэкенда)."""
a = login(client, "Хозяин")
gid = client.post(
"/api/groups", json={"name": "Группа", "expansion_ids": []}, headers=csrf_headers(client)
).json()["id"]
client.post("/api/auth/dev/users", json={"nickname": "Согрупник"}, headers=csrf_headers(client))
b = client.post(
f"/api/groups/{gid}/members", json={"nickname": "Согрупник"}, headers=csrf_headers(client)
).json()["user_id"]
b = add_group_member(engine, gid, "Согрупник")
factions = client.get(f"/api/groups/{gid}/factions").json()
f1, f2 = factions[0]["id"], factions[1]["id"]
@@ -236,16 +220,14 @@ def test_owner_can_finish_member_started_match(client: TestClient):
assert fin.status_code == 200, fin.text
def test_any_member_can_finish_and_manage(client: TestClient):
def test_any_member_can_finish_and_manage(client: TestClient, engine):
"""Рядовой участник (не создатель, не владелец) может завершать партии и менять дополнения."""
a = login(client, "Овнер")
gid = client.post(
"/api/groups", json={"name": "Компания", "expansion_ids": []}, headers=csrf_headers(client)
).json()["id"]
for nick in ("Бэ", "Цэ"):
client.post("/api/auth/dev/users", json={"nickname": nick}, headers=csrf_headers(client))
b = client.post(f"/api/groups/{gid}/members", json={"nickname": "Бэ"}, headers=csrf_headers(client)).json()["user_id"]
c = client.post(f"/api/groups/{gid}/members", json={"nickname": "Цэ"}, headers=csrf_headers(client)).json()["user_id"]
b = add_group_member(engine, gid, "Бэ")
c = add_group_member(engine, gid, "Цэ")
fids = [f["id"] for f in client.get(f"/api/groups/{gid}/factions").json()]
# Владелец стартует партию A+B+C.
@@ -305,18 +287,14 @@ def test_disabled_account_cannot_login(client: TestClient, make_admin):
assert guest_dev["is_active"] is False
def test_tie_ranking_and_points(client: TestClient):
def test_tie_ranking_and_points(client: TestClient, engine):
"""Ничьи: места 1,2,2 валидны; очки делятся; некорректная расстановка отклоняется."""
me = login(client, "A")
r = client.post("/api/groups", json={"name": "Группа", "expansion_ids": []},
headers=csrf_headers(client))
gid = r.json()["id"]
client.post("/api/auth/dev/users", json={"nickname": "B"}, headers=csrf_headers(client))
client.post("/api/auth/dev/users", json={"nickname": "C"}, headers=csrf_headers(client))
b = client.post(f"/api/groups/{gid}/members", json={"nickname": "B"},
headers=csrf_headers(client)).json()["user_id"]
c = client.post(f"/api/groups/{gid}/members", json={"nickname": "C"},
headers=csrf_headers(client)).json()["user_id"]
b = add_group_member(engine, gid, "B")
c = add_group_member(engine, gid, "C")
factions = client.get(f"/api/groups/{gid}/factions").json()
f1, f2, f3 = (factions[0]["id"], factions[1]["id"], factions[2]["id"])
a = me["id"]