import httpx import pytest from src import main from src.following_store import FollowingStore @pytest.mark.anyio async def test_confirmed_watch_updates_account_following_collection(monkeypatch, tmp_path): store = FollowingStore(tmp_path / "following.sqlite3", encryption_key=b"a" * 32) detail = { "repository": "stackchain/api", "kind": "issue", "number": 42, "title": "Make mobile review useful", "state": "open", "updated_at": "2026-08-23T03:00:00Z", "url": "https://forge.example/stackchain/api/issues/42", "claimable": True, } async def preview(repository, kind, number): assert (repository, kind, number) == ("stackchain/api", "issue", 42) return detail async def set_subscription(repository, number, watching): return {"watching": watching} async def user(): return {"login": "Timmy"} monkeypatch.setattr(main, "_following_store", lambda: store, raising=False) monkeypatch.setattr(main.gitea_proxy, "work_preview", preview) monkeypatch.setattr(main.gitea_proxy, "set_issue_subscription", set_subscription) monkeypatch.setattr(main, "current_user", user) transport = httpx.ASGITransport(app=main.app) async with httpx.AsyncClient(transport=transport, base_url="http://test") as client: watched = await client.put( "/api/v1/repos/stackchain/api/issues/42/preview/subscription?kind=issue" ) following = await client.get("/api/v1/following") assert watched.status_code == 200 assert watched.json() == {"watching": True, "following_revision": 1, "following_count": 1} assert following.status_code == 200 assert following.headers["cache-control"] == "no-store" assert following.json() == {"revision": 1, "items": [{ "repository": "stackchain/api", "number": 42, "title": "Make mobile review useful", "state": "open", "updated_at": "2026-08-23T03:00:00Z", "url": "https://forge.example/stackchain/api/issues/42", }]}