# co-gahusb/tests/test_teamlog.py
from app import store


async def test_log_event_and_read(r):
    await store.log_event(r, "message", "Producer→BE: hi")
    await store.log_event(r, "lock", "BE acquired nas-deploy")
    res = await store.read_team_log(r)
    msgs = [e["text"] for e in res["events"]]
    assert msgs == ["Producer→BE: hi", "BE acquired nas-deploy"]


async def test_team_log_after_id(r):
    e1 = (await store.log_event(r, "message", "a"))["event_id"]
    await store.log_event(r, "message", "b")
    res = await store.read_team_log(r, after_id=e1)
    assert [e["text"] for e in res["events"]] == ["b"]


async def test_team_log_capped(r):
    for i in range(10):
        await store.log_event(r, "message", f"m{i}")
    res = await store.read_team_log(r, limit=3)
    assert len(res["events"]) == 3
    assert res["events"][-1]["text"] == "m9"
