# tests integration WebSocket from fastapi.testclient import TestClient from main import app client = TestClient(app) def test_set_username(): with client.websocket_connect("/ws") as ws: ws.send_json({"type": "set_username", "username": "Alice"}) msg = ws.receive_json() assert msg["type"] == "username_set" def test_create_lobby_sans_pseudo(): with client.websocket_connect("/ws") as ws: ws.send_json({"type": "create_lobby"}) msg = ws.receive_json() assert msg["code"] == "no_username" def test_create_lobby_ok(): with client.websocket_connect("/ws") as ws: ws.send_json({"type": "set_username", "username": "Alice"}) ws.receive_json() ws.send_json({"type": "create_lobby"}) msg = ws.receive_json() assert msg["type"] == "lobby_created"