use axum::http::StatusCode; use http_body_util::BodyExt; use serde_json::Value; mod common; /// Unlike hello_world/version, /species needs a live MariaDB connection /// (SQL_URI, see src/db.rs) and a valid token (every endpoint does now /// -- see docs/gn-auth.md). There is no database reachable inside the /// Guix build sandbox, so this test checks connectivity first and skips /// (passes trivially, with a message) rather than failing the build when /// none is available; same for a token (common::auth_token() tries /// POST /get-test-token first, then GN4_TEST_AUTH_TOKEN). #[tokio::test] async fn species_returns_ok_with_species_list() { if !common::db_available() { eprintln!( "skipping species_returns_ok_with_species_list: no usable database (check SQL_URI credentials)" ); return; } let Some(token) = common::auth_token().await else { eprintln!("skipping species_returns_ok_with_species_list: no token (see docs/gn-auth.md)"); return; }; let response = common::get_with_token("GET /species", "/species", &token).await; assert_eq!(response.status(), StatusCode::OK); let body = response.into_body().collect().await.unwrap().to_bytes(); let species: Vec = common::data(&body); assert!(!species.is_empty()); for record in &species { assert!(record["name"].as_str().is_some()); assert!(record["family"].as_str().is_some()); } // mouse and rat are always present in the database. let names: Vec<&str> = species .iter() .map(|record| record["name"].as_str().unwrap()) .collect(); assert!(names.contains(&"mouse")); assert!(names.contains(&"rat")); }