Files
awoooi/apps/api/tests/test_weekly_report_preview_api.py
Your Name 77fe2a85fd
Some checks failed
Code Review / ai-code-review (push) Successful in 17s
CD Pipeline / tests (push) Successful in 1m43s
CD Pipeline / build-and-deploy (push) Failing after 8m19s
CD Pipeline / post-deploy-checks (push) Has been skipped
fix(api): 在日報月報 preview 顯示資料源沉澱
2026-06-18 20:01:44 +08:00

73 lines
2.6 KiB
Python

from fastapi.testclient import TestClient
from src.main import app
def test_daily_report_preview_exposes_source_health_no_send_preview():
client = TestClient(app)
response = client.get("/api/v1/stats/daily/preview")
assert response.status_code == 200
data = response.json()
assert "report_date" in data
assert "alert_total" in data
assert "km_new_entries" in data
assert "playbook_count" in data
assert "source_ok_count" in data
assert "source_total_count" in data
assert "source_confidence_percent" in data
assert "source_gap_ids" in data
assert "formatted_preview" in data
preview = data["formatted_preview"]
assert "AWOOOI 日度巡檢報告" in preview
assert "報表資料源 / 沉澱" in preview
assert f"來源: <code>{data['source_ok_count']}/{data['source_total_count']}</code>" in preview
assert "不自動改排程" in preview
def test_weekly_report_preview_exposes_source_health_no_send_preview():
client = TestClient(app)
response = client.get("/api/v1/stats/weekly/preview")
assert response.status_code == 200
data = response.json()
assert "week_range" in data
assert "alert_total" in data
assert "source_ok_count" in data
assert "source_total_count" in data
assert "source_confidence_percent" in data
assert "source_gap_ids" in data
assert "formatted_preview" in data
assert data["source_total_count"] >= 0
assert data["source_ok_count"] >= 0
preview = data["formatted_preview"]
assert "報表資料信任度" in preview
if data["source_total_count"] > 0:
assert "報表資料源 / 沉澱" in preview
assert f"來源: <code>{data['source_ok_count']}/{data['source_total_count']}</code>" in preview
assert "不自動改排程" in preview
def test_monthly_report_preview_exposes_source_health_no_send_preview():
client = TestClient(app)
response = client.get("/api/v1/stats/monthly/preview")
assert response.status_code == 200
data = response.json()
assert "report_month" in data
assert "source_ok_count" in data
assert "source_total_count" in data
assert "source_confidence_percent" in data
assert "source_gap_ids" in data
assert "no_send_preview_count" in data
assert "formatted_preview" in data
preview = data["formatted_preview"]
assert "月報 no-send preview" in preview
assert "報表資料源 / 沉澱" in preview
assert f"來源: <code>{data['source_ok_count']}/{data['source_total_count']}</code>" in preview
assert "實發: 0" in preview
assert "不代表已授權發送或自動修復" in preview