use axum::http::StatusCode; use http_body_util::BodyExt; use serde_json::Value; mod common; /// Needs a live MariaDB connection (SQL_URI, see src/db.rs) and a valid /// token (every endpoint needs one now -- see docs/gn-auth.md); skips /// rather than fails when either is missing, same as group_by_name.rs. /// Not gated on fine-grained gn-auth authorization -- same as its /// /groups/{group}/datasets sibling, this only returns dataset metadata /// (names, public/confidentiality flags), not trait data -- but a /// token is still required, like every endpoint now. #[tokio::test] async fn species_datasets_mouse_returns_datasets() { if !common::db_available() { eprintln!( "skipping species_datasets_mouse_returns_datasets: no usable database (check SQL_URI credentials)" ); return; } let Some(token) = common::auth_token().await else { eprintln!( "skipping species_datasets_mouse_returns_datasets: no token (see docs/gn-auth.md)" ); return; }; let response = common::get_with_token( "GET /species/mouse/datasets", "/species/mouse/datasets", &token, ) .await; assert_eq!(response.status(), StatusCode::OK); let body = response.into_body().collect().await.unwrap().to_bytes(); let datasets: Vec = common::data(&body); assert!(!datasets.is_empty()); let names: Vec<&str> = datasets .iter() .map(|record| record["name"].as_str().unwrap()) .collect(); assert!(names.contains(&"Br_U_0803_M")); } #[tokio::test] async fn species_datasets_unknown_species_returns_404() { if !common::db_available() { eprintln!( "skipping species_datasets_unknown_species_returns_404: no usable database (check SQL_URI credentials)" ); return; } let Some(token) = common::auth_token().await else { eprintln!( "skipping species_datasets_unknown_species_returns_404: no token (see docs/gn-auth.md)" ); return; }; let response = common::get_with_token( "GET /species/not-a-real-species/datasets", "/species/not-a-real-species/datasets", &token, ) .await; assert_eq!(response.status(), StatusCode::NOT_FOUND); let body = response.into_body().collect().await.unwrap().to_bytes(); let error: Value = serde_json::from_slice(&body).unwrap(); assert_eq!(error["status"], 404); assert_eq!(error["code"], "species_not_found"); assert_eq!(error["operation_id"], "species_datasets"); assert_eq!(error["next"], "/species"); }