Files
dbx-main/tests/test_project_alerts_api.py
T
king 21fc78adb9 feat(project): blinking popup for new mentions and task assignments
Project pages poll GET /api/notifications/alerts every 20s (and when the
tab becomes visible). New unread mention/assigned notifications show in a
large blinking popup at the bottom center until closed; closing in one tab
closes it in the others. A new browser starts from the latest id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 17:30:15 +09:00

50 lines
2.2 KiB
Python

"""알림 팝업 API — 기준점·태그/배정만·읽지 않은 것·after 이후·오래된 것부터. DB 없이 가짜 저장소로."""
import importlib
import unittest
from unittest.mock import patch
from fastapi import FastAPI
from fastapi.testclient import TestClient
api = importlib.import_module("app.modules.project.router")
ROWS = [ # 최신순(list_notifications 와 같게)
{"id": 9, "type": "completed", "title": "완료", "is_read": False, "task_id": 1, "project_id": 1},
{"id": 8, "type": "mention", "title": "나를 태그함: A", "is_read": False, "task_id": 1, "project_id": 1},
{"id": 7, "type": "assigned", "title": "작업 배정: B", "is_read": True, "task_id": 2, "project_id": 1},
{"id": 6, "type": "assigned", "title": "작업 배정: C", "is_read": False, "task_id": 3, "project_id": 1},
{"id": 2, "type": "assigned", "title": "작업 배정: 옛것", "is_read": False, "task_id": 4, "project_id": 1},
]
class FakeStore:
def list_notifications(self, recipient_email, unread_only=False, limit=100):
rows = [r for r in ROWS if not unread_only or not r["is_read"]]
return rows[:limit]
class AlertsApiTests(unittest.TestCase):
def setUp(self):
app = FastAPI()
app.include_router(api.router)
self.client = TestClient(app)
def get(self, qs=""):
with patch.object(api, "_require_user", return_value={"email": "Me@Test.local"}), \
patch.object(api, "_db_or_503", return_value=FakeStore()), \
patch.object(api, "_visible_notifications", side_effect=lambda st, user, items: items):
return self.client.get("/project/api/notifications/alerts" + qs).json()
def test_without_after_returns_only_baseline(self):
out = self.get()
self.assertEqual((out["me"], out["latest_id"], out["alerts"]), ("me@test.local", 9, []))
def test_after_returns_unread_mentions_and_assignments_oldest_first(self):
out = self.get("?after=5")
self.assertEqual([a["id"] for a in out["alerts"]], [6, 8]) # 완료 알림(9)·읽은 것(7)·옛것(2) 제외
self.assertEqual(out["alerts"][1]["type"], "mention")
if __name__ == "__main__":
unittest.main()