Files
personal-ai-assistant/backend/tests/test_notifications.py
dolgolyov.alexei ada7e82961 Phase 5: Notifications — WebSocket, APScheduler, AI tool, health review
Backend:
- Notification model + Alembic migration
- Notification service: CRUD, mark read, unread count, pending scheduled
- WebSocket manager singleton for real-time push
- WebSocket endpoint /ws/notifications with JWT auth via query param
- APScheduler integration: periodic notification sender (every 60s),
  daily proactive health review job (8 AM)
- AI tool: schedule_notification (immediate or scheduled)
- Health review worker: analyzes user memory via Claude, creates
  ai_generated notifications with WebSocket push

Frontend:
- Notification API client + Zustand store
- WebSocket hook with auto-reconnect (exponential backoff)
- Notification bell in header with unread count badge + dropdown
- Notifications page with type badges, mark read, mark all read
- WebSocket initialized in AppLayout for app-wide real-time updates
- Enabled notifications nav in sidebar
- English + Russian translations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 13:57:25 +03:00

47 lines
1.5 KiB
Python

import pytest
from httpx import AsyncClient
@pytest.fixture
async def auth_headers(client: AsyncClient):
resp = await client.post("/api/v1/auth/register", json={
"email": "notifuser@example.com",
"username": "notifuser",
"password": "testpass123",
})
assert resp.status_code == 201
return {"Authorization": f"Bearer {resp.json()['access_token']}"}
async def test_list_notifications_empty(client: AsyncClient, auth_headers: dict):
resp = await client.get("/api/v1/notifications/", headers=auth_headers)
assert resp.status_code == 200
data = resp.json()
assert data["notifications"] == []
assert data["unread_count"] == 0
async def test_unread_count(client: AsyncClient, auth_headers: dict):
resp = await client.get("/api/v1/notifications/unread-count", headers=auth_headers)
assert resp.status_code == 200
assert resp.json()["count"] == 0
async def test_mark_all_read(client: AsyncClient, auth_headers: dict):
resp = await client.post("/api/v1/notifications/mark-all-read", headers=auth_headers)
assert resp.status_code == 200
assert resp.json()["marked"] == 0
async def test_mark_nonexistent_read(client: AsyncClient, auth_headers: dict):
resp = await client.patch(
"/api/v1/notifications/00000000-0000-0000-0000-000000000000/read",
headers=auth_headers,
)
assert resp.status_code == 404
async def test_unauthenticated(client: AsyncClient):
resp = await client.get("/api/v1/notifications/")
assert resp.status_code == 401