Show blocklist import error badge in navigation
When the most recent scheduled import completed with errors, surface the failure in the persistent app shell: - A warning MessageBar appears at top of main content area - An amber badge is rendered on the Blocklists sidebar nav item Backend: add last_run_errors: bool | None to ScheduleInfo model and populate it in get_schedule_info() from the latest import_log row. Frontend: extend ScheduleInfo type, add useBlocklistStatus polling hook, wire both indicators into MainLayout. Tests: 3 new service tests + 1 new router test (433 total, all pass).
This commit is contained in:
@@ -254,7 +254,42 @@ class TestSchedule:
|
||||
assert loaded.interval_hours == 6
|
||||
|
||||
async def test_get_schedule_info_no_log(self, db: aiosqlite.Connection) -> None:
|
||||
"""get_schedule_info returns None for last_run_at when no log exists."""
|
||||
"""get_schedule_info returns None for last_run_at and last_run_errors when no log exists."""
|
||||
info = await blocklist_service.get_schedule_info(db, None)
|
||||
assert info.last_run_at is None
|
||||
assert info.next_run_at is None
|
||||
assert info.last_run_errors is None
|
||||
|
||||
async def test_get_schedule_info_no_errors_when_clean(
|
||||
self, db: aiosqlite.Connection
|
||||
) -> None:
|
||||
"""get_schedule_info returns last_run_errors=False when the last run had no errors."""
|
||||
from app.repositories import import_log_repo
|
||||
|
||||
await import_log_repo.add_log(
|
||||
db,
|
||||
source_id=None,
|
||||
source_url="https://example.test/ips.txt",
|
||||
ips_imported=10,
|
||||
ips_skipped=0,
|
||||
errors=None,
|
||||
)
|
||||
info = await blocklist_service.get_schedule_info(db, None)
|
||||
assert info.last_run_errors is False
|
||||
|
||||
async def test_get_schedule_info_errors_flag_when_failed(
|
||||
self, db: aiosqlite.Connection
|
||||
) -> None:
|
||||
"""get_schedule_info returns last_run_errors=True when the last run had errors."""
|
||||
from app.repositories import import_log_repo
|
||||
|
||||
await import_log_repo.add_log(
|
||||
db,
|
||||
source_id=None,
|
||||
source_url="https://example.test/ips.txt",
|
||||
ips_imported=0,
|
||||
ips_skipped=0,
|
||||
errors="Connection timeout",
|
||||
)
|
||||
info = await blocklist_service.get_schedule_info(db, None)
|
||||
assert info.last_run_errors is True
|
||||
|
||||
Reference in New Issue
Block a user