pinakes-server: add utoipa annotations to all routes; fix tests

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I28cf5b7b7cff8e90e123d624d97cf9656a6a6964
This commit is contained in:
raf 2026-03-21 02:17:55 +03:00
commit 625077f341
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
60 changed files with 3493 additions and 242 deletions

View file

@ -32,10 +32,7 @@ async fn get_book_metadata_not_found() {
.oneshot(get(&format!("/api/v1/books/{fake_id}/metadata")))
.await
.unwrap();
assert!(
resp.status() == StatusCode::NOT_FOUND
|| resp.status() == StatusCode::INTERNAL_SERVER_ERROR
);
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
}
#[tokio::test]
@ -77,10 +74,8 @@ async fn reading_progress_nonexistent_book() {
))
.await
.unwrap();
// Nonexistent book; expect NOT_FOUND or empty response
assert!(
resp.status() == StatusCode::NOT_FOUND || resp.status() == StatusCode::OK
);
// Nonexistent book always returns 404.
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
}
#[tokio::test]
@ -96,11 +91,8 @@ async fn update_reading_progress_nonexistent_book() {
))
.await
.unwrap();
// Nonexistent book; expect NOT_FOUND or error
assert!(
resp.status() == StatusCode::NOT_FOUND
|| resp.status() == StatusCode::INTERNAL_SERVER_ERROR
);
// Nonexistent book: handler verifies existence first, so always 404.
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
}
#[tokio::test]

View file

@ -154,6 +154,7 @@ pub fn default_config() -> Config {
authentication_disabled: true,
cors_enabled: false,
cors_origins: vec![],
swagger_ui: false,
},
rate_limits: RateLimitConfig::default(),
ui: UiConfig::default(),

View file

@ -51,7 +51,26 @@ async fn notes_graph_empty() {
.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
let body = response_body(resp).await;
assert!(body.is_object() || body.is_array());
// Fresh database: graph must be empty.
if let Some(arr) = body.as_array() {
assert!(arr.is_empty(), "graph should be empty, got {arr:?}");
} else if let Some(obj) = body.as_object() {
// Accept an object if the schema uses {nodes:[], edges:[]} style.
let nodes_empty = obj
.get("nodes")
.and_then(|v| v.as_array())
.map_or(true, |a| a.is_empty());
let edges_empty = obj
.get("edges")
.and_then(|v| v.as_array())
.map_or(true, |a| a.is_empty());
assert!(
nodes_empty && edges_empty,
"graph should be empty, got {obj:?}"
);
} else {
panic!("expected array or object, got {body}");
}
}
#[tokio::test]
@ -62,6 +81,12 @@ async fn unresolved_count_zero() {
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
let body = response_body(resp).await;
// Fresh database has no unresolved links.
let count = body["count"]
.as_u64()
.expect("response should have a numeric 'count' field");
assert_eq!(count, 0, "expected zero unresolved links in fresh database");
}
#[tokio::test]