diff --git a/src/main.py b/src/main.py index 8dce7d3..684461a 100644 --- a/src/main.py +++ b/src/main.py @@ -84,7 +84,7 @@ async def context() -> JSONResponse: } if isinstance(e, TimeoutError) else None) user_model = User(id=user_data["id"], login=user_data["login"], full_name=user_data.get("full_name", ""), email=user_data.get("email", "")) repo_models = [ - Repo(id=r["id"], name=r["name"], full_name=r["full_name"], description=r.get("description", ""), url=r["html_url"], updated_at=r.get("updated_at", "")) + Repo(id=r["id"], name=r["name"], full_name=r["full_name"], description=r.get("description") or "", url=r["html_url"], updated_at=r.get("updated_at", "")) for r in repo_data[:50] if isinstance(r, dict) ] diff --git a/tests/test_context_timeout.py b/tests/test_context_timeout.py index 4bd150b..5de5dec 100644 --- a/tests/test_context_timeout.py +++ b/tests/test_context_timeout.py @@ -62,4 +62,32 @@ async def test_context_normalizes_nullable_issue_collections(monkeypatch): issue = json.loads(response.body)["issues"][0] assert issue["labels"] == [] - assert issue["assignees"] == [] \ No newline at end of file + assert issue["assignees"] == [] + + +@pytest.mark.anyio +async def test_context_normalizes_nullable_repository_description(monkeypatch): + async def user(): + return {"id": 1, "login": "timmy"} + + async def empty_collection(): + return [] + + async def repo_collection(): + return [{ + "id": 54, + "name": "dashboard", + "full_name": "stackchain/dashboard", + "description": None, + "html_url": "https://forge.example/stackchain/dashboard", + }] + + monkeypatch.setattr(main, "current_user", user) + monkeypatch.setattr(main, "repos", repo_collection) + monkeypatch.setattr(main, "issues", empty_collection) + monkeypatch.setattr(main, "pull_requests", empty_collection) + + response = await main.context() + repository = json.loads(response.body)["repos"][0] + + assert repository["description"] == "" \ No newline at end of file