Skip to content

Commit 4faf18b

Browse files
committed
fix: view page error.
1 parent af6d73a commit 4faf18b

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

backend/tests/test_activity.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,32 @@ async def test_activity_stats(auth_client):
2222
data = response.json()
2323
# stats might be empty but should be a dict
2424
assert isinstance(data, dict)
25+
26+
27+
@pytest.mark.asyncio
28+
async def test_deleted_pages_excluded_from_stats(admin_client):
29+
# Create two pages and bump view counts.
30+
await admin_client.post("/api/pages", json={
31+
"title": "Keep Me", "content_md": "x", "slug": "stats-keep",
32+
})
33+
await admin_client.post("/api/pages", json={
34+
"title": "Delete Me", "content_md": "x", "slug": "stats-delete",
35+
})
36+
# View the to-be-deleted one a few times so it would top the list.
37+
for ua in ("a", "b", "c"):
38+
await admin_client.get(
39+
"/api/pages/stats-delete", headers={"User-Agent": ua}
40+
)
41+
await admin_client.get("/api/pages/stats-keep")
42+
43+
# Soft-delete it.
44+
r = await admin_client.delete("/api/pages/stats-delete")
45+
assert r.status_code == 200
46+
47+
stats = (await admin_client.get("/api/activity/stats")).json()
48+
slugs_top = {p["slug"] for p in stats["top_viewed"]}
49+
slugs_recent = {p["slug"] for p in stats["recently_updated"]}
50+
slugs_orphan = {p["slug"] for p in stats["orphan_pages"]}
51+
assert "stats-delete" not in slugs_top
52+
assert "stats-delete" not in slugs_recent
53+
assert "stats-delete" not in slugs_orphan

frontend/src/pages/Activity.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function Activity() {
1515

1616
useEffect(() => {
1717
fetchActivity()
18-
fetchStats()
18+
fetchStats(true)
1919
}, [])
2020

2121
const actionLabel = (action) => {

0 commit comments

Comments
 (0)