"""An admin action that counts something keeps the count as data in its audit row's `after`, under the key the audit log names in the reader's language (`scheduler.result.`, frontend auditColumns.tsx) — not only in the English `summary`. A renamed key would fall back to the raw word. DB lane (Postgres). """ from sqlalchemy import select from app.models import AuditLog def _after(db, action: str) -> dict: db.expire_all() return db.execute(select(AuditLog.after).where(AuditLog.action == action)).scalar_one() def test_clearing_the_audit_log_keeps_the_count_as_data(as_user, db, make_user): admin = make_user(email="boss@example.com", role="admin") db.add_all([AuditLog(action="sync_pause"), AuditLog(action="sync_resume")]) db.commit() assert as_user(admin).delete("/api/admin/audit").json()["cleared"] == 2 assert _after(db, "audit_clear") == {"cleared": 2} def test_a_discovery_purge_keeps_its_counts_as_data(as_user, db, make_user): admin = make_user(email="boss@example.com", role="admin") body = as_user(admin).post("/api/admin/purge-discovery").json() body.pop("ok") assert _after(db, "discovery_purge") == body assert {"videos_deleted", "channels_deleted", "search_videos_deleted"} <= set(body)