test: add /bridge/rooms endpoint tests — room listing, occupant counts, empty state
This commit is contained in:
@@ -364,3 +364,36 @@ class TestRoomBroadcast:
|
||||
c, _ = client
|
||||
resp = await c.get("/bridge/room_events/nonexistent")
|
||||
assert resp.status == 404
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_rooms_lists_all_rooms_with_occupants(self, client):
|
||||
c, bridge = client
|
||||
await c.post("/bridge/chat", json={
|
||||
"user_id": "alice", "username": "Alice", "message": "hi", "room": "Tower"
|
||||
})
|
||||
await c.post("/bridge/chat", json={
|
||||
"user_id": "bob", "username": "Bob", "message": "hi", "room": "Tower"
|
||||
})
|
||||
await c.post("/bridge/chat", json={
|
||||
"user_id": "carol", "username": "Carol", "message": "hi", "room": "Library"
|
||||
})
|
||||
resp = await c.get("/bridge/rooms")
|
||||
assert resp.status == 200
|
||||
data = await resp.json()
|
||||
assert data["total_rooms"] == 2
|
||||
assert data["total_users"] == 3
|
||||
assert "Tower" in data["rooms"]
|
||||
assert "Library" in data["rooms"]
|
||||
assert data["rooms"]["Tower"]["count"] == 2
|
||||
assert data["rooms"]["Library"]["count"] == 1
|
||||
tower_users = {o["user_id"] for o in data["rooms"]["Tower"]["occupants"]}
|
||||
assert tower_users == {"alice", "bob"}
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_rooms_empty_when_no_sessions(self, client):
|
||||
c, _ = client
|
||||
resp = await c.get("/bridge/rooms")
|
||||
data = await resp.json()
|
||||
assert data["total_rooms"] == 0
|
||||
assert data["total_users"] == 0
|
||||
assert data["rooms"] == {}
|
||||
|
||||
Reference in New Issue
Block a user