stackchain-dashboard/tests/test_following_api.py
timmy 041f2dbe9b
Some checks failed
CI / lint (pull_request) Failing after 4m8s
CI / build-release (pull_request) Has been skipped
CI / browser-journey (pull_request) Has been skipped
CI / release-candidate (pull_request) Has been skipped
feat: add mobile Following queue for watched issues (Closes #1293)
2026-08-23 04:04:09 +00:00

56 lines
2.0 KiB
Python

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",
}]}