Tests for the directory's Apple sync, metrics and dropped snapshots (#402)

The weekly Apple Podcasts sync runs unattended and ran in no test. Its
Apple address is now an argument (run passes Apple's), and its pause
between calls is none under test, so a test runs it against a stand-in
with one category: the top chart and the category's are taken each
show once in order, looked up, and filed as the apple-podcasts
snapshot with a feed that has a key in it refused as private; a feed an
admin blocked is left out of the next; and a sync whose lookup fails
is an error that leaves the last good snapshot as it was.

/metrics serves every directory_ metric the dashboard and alerts
query, read out of them. Dropping a server's snapshot through the API
is for admins only, and takes the feeds only it listed, keeping one
another server lists too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-07 04:32:28 +00:00
parent c00d5383de
commit 8e8307b569
3 changed files with 117 additions and 8 deletions

View File

@@ -433,6 +433,26 @@ mod tests {
}
}
#[tokio::test]
async fn dropping_a_servers_snapshot_takes_only_the_feeds_nobody_else_lists() {
let (app, dir) = app().await;
let feed = |url: &str| serde_json::json!({ "url": url, "subscribers": 1 });
let mine = serde_json::json!([feed("https://only-rw.test/feed"), feed("https://both.test/feed")]);
assert_eq!(call(&app, "POST", "/v1/snapshot", Some("rw"), Some(mine)).await.0, 200);
let theirs = serde_json::json!([feed("https://both.test/feed")]);
assert_eq!(call(&app, "POST", "/v1/snapshot", Some("rwa"), Some(theirs)).await.0, 200);
assert_eq!(call(&app, "DELETE", "/v1/instances/rw-token", Some("rw"), None).await.0, 403, "admins only");
assert_eq!(call(&app, "DELETE", "/v1/instances/rw-token", Some("rwa"), None).await.0, 204);
let left: Vec<(String, i64)> =
dir.store.instances().await.unwrap().into_iter().map(|i| (i.name, i.feeds)).collect();
assert_eq!(left, [("rwa-token".to_owned(), 1)]);
let gone = dir.store.due_one(&store::feed_id("https://only-rw.test/feed")).await.unwrap();
assert!(gone.is_none(), "nobody lists it now");
let kept = dir.store.due_one(&store::feed_id("https://both.test/feed")).await.unwrap();
assert!(kept.is_some(), "another server still does");
}
#[tokio::test]
async fn each_access_level_does_what_it_may_and_no_more() {
let (app, dir) = app().await;