crates/korp-map-wire/tests/landing.rs
//! **The landing page and the OpenAPI description** on a running server.
mod common;
use common::*;
use korp_map_wire::ServerConfig;
#[tokio::test(flavor = "multi_thread")]
async fn the_landing_page_is_served_at_the_root_and_under_v1() {
let s = TestServer::start(ServerConfig {
about: Some("korp-map-server 9.9.9 (abcdef123456)".into()),
..ServerConfig::default()
})
.await;
let root = get(&s.url("/")).await;
assert_eq!(root.status, 200);
assert_eq!(
root.header("content-type"),
Some("text/html; charset=utf-8")
);
assert_eq!(root.header("access-control-allow-origin"), Some("*"));
let html = String::from_utf8(root.body.to_vec()).unwrap();
assert!(html.starts_with("<!doctype html>"));
assert!(html.contains("korp-map-server 9.9.9 (abcdef123456)"));
assert!(html.contains("korp_map_client.Client("));
assert!(html.contains("/v1/geocode?region="));
for p in ["/v1/", "/v1"] {
let r = get(&s.url(p)).await;
assert_eq!(r.status, 200, "{p}");
assert_eq!(r.body, root.body, "{p}");
}
}
#[tokio::test(flavor = "multi_thread")]
async fn the_openapi_description_is_json_and_names_every_refusal_code() {
let s = TestServer::start(ServerConfig::default()).await;
let r = get(&s.url("/openapi.json")).await;
assert_eq!(r.status, 200);
assert_eq!(r.header("content-type"), Some("application/json"));
let v = r.json();
assert_eq!(v["openapi"], "3.1.0");
let codes: Vec<&str> = v["components"]["schemas"]["Error"]["properties"]["code"]["enum"]
.as_array()
.unwrap()
.iter()
.map(|c| c.as_str().unwrap())
.collect();
let want: Vec<String> = korp_map_wire::Code::ALL.iter().map(|c| c.tag()).collect();
assert_eq!(codes, want);
for p in korp_map_wire::http::ROUTES {
assert!(v["paths"].get(*p).is_some(), "{p}");
}
}