use axum::http::StatusCode; use http_body_util::BodyExt; use serde_json::Value; mod common; /// Needs a live MariaDB connection (SQL_URI) and a valid token; skips /// rather than fails when either is missing, same as groups.rs. GN602 is /// the BXD published phenotypes dataset; GN1 is Br_U_0803_M. #[tokio::test] async fn accession_resolves_to_its_dataset() { if !common::db_available() { eprintln!( "skipping accession_resolves_to_its_dataset: no usable database (check SQL_URI credentials)" ); return; } let Some(token) = common::auth_token().await else { eprintln!("skipping accession_resolves_to_its_dataset: no token (see docs/gn-auth.md)"); return; }; for uri in ["/accessions/GN602", "/accessions/gn602", "/accessions/602"] { let response = common::get_with_token(&format!("GET {uri}"), uri, &token).await; assert_eq!(response.status(), StatusCode::OK, "{uri}"); let body = response.into_body().collect().await.unwrap().to_bytes(); let found: Value = common::data(&body); assert_eq!(found["accession"], 602, "{uri}"); assert_eq!(found["name"], "BXDPublish"); assert_eq!(found["title"], "BXD Published Phenotypes"); assert_eq!(found["category"], "publish"); assert_eq!(found["group"], "BXD"); } // An expression dataset. let response = common::get_with_token("GET /accessions/GN1", "/accessions/GN1", &token).await; assert_eq!(response.status(), StatusCode::OK); let body = response.into_body().collect().await.unwrap().to_bytes(); let found: Value = common::data(&body); assert_eq!(found["name"], "Br_U_0803_M"); assert_eq!(found["category"], "probeset"); assert_eq!(found["group"], "BXD"); } #[tokio::test] async fn accession_rejects_text_and_unknown_numbers() { if !common::db_available() { eprintln!( "skipping accession_rejects_text_and_unknown_numbers: no usable database (check SQL_URI credentials)" ); return; } let Some(token) = common::auth_token().await else { eprintln!( "skipping accession_rejects_text_and_unknown_numbers: no token (see docs/gn-auth.md)" ); return; }; let response = common::get_with_token( "GET /accessions/BXDPublish", "/accessions/BXDPublish", &token, ) .await; assert_eq!(response.status(), StatusCode::BAD_REQUEST); let body = response.into_body().collect().await.unwrap().to_bytes(); let error: Value = serde_json::from_slice(&body).unwrap(); assert_eq!(error["code"], "invalid_parameter"); assert_eq!(error["operation_id"], "accession"); let response = common::get_with_token( "GET /accessions/GN99999999", "/accessions/GN99999999", &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["code"], "accession_not_found"); }