7a0eb3a
//! Always-runnable reflection test: the merged OpenAPI document must expose
//! one operation per posts handler (no infra required).
use serde_json::Value;
#[test]
fn openapi_doc_exposes_post_operations() {
let doc = post::handler::openapi::build_openapi();
let spec: Value = serde_json::from_str(&doc.to_json().unwrap()).unwrap();
let paths = spec["paths"].as_object().expect("paths object");
let mut operations = 0usize;
let mut detail = String::new();
for (key, item) in paths {
if key.contains("/posts") {
detail.push_str(&format!("{key}: {}\n", item.as_object().unwrap().len()));
operations += item.as_object().unwrap().len();
}
}
assert!(
operations >= 15,
"expected >= 15 posts operations, got {operations}:\n{detail}"
);
}
#[test]
fn openapi_doc_has_post_schemas() {
let doc = post::handler::openapi::build_openapi();
let spec: Value = serde_json::from_str(&doc.to_json().unwrap()).unwrap();
let schemas = spec["components"]["schemas"]
.as_object()
.expect("schemas object");
for name in [
"PostView",
"PostPage",
"PostStatusView",
"CreatePostOption",
"UpdatePostOption",
"ListPostQuery",
"PostBoardView",
"PostBoardPage",
"CreatePostBoardOption",
"PostReplyView",
"PostReplyPage",
"CreateReplyOption",
"PostReactionView",
"PostMentionView",
"PostWatchView",
"UpsertPostWatchOption",
"PostLabelView",
"PostLabelPage",
"CreatePostLabelOption",
"UpdatePostLabelOption",
] {
assert!(schemas.contains_key(name), "missing schema {name}");
}
}