about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/links.rs71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/links.rs b/tests/links.rs
index 498181a..3c2c01b 100644
--- a/tests/links.rs
+++ b/tests/links.rs
@@ -155,3 +155,74 @@ async fn a_marker_leads_to_its_tally_and_its_phewas() {
         "a marker leads to the PheWAS at it: {links:?}"
     );
 }
+
+/// A scan's reply carries the forward hint that reads the peak for what it
+/// is: how many animals sit in each genotype class there. Without it, "LOD
+/// 2.93" is the same sentence whether it rests on two animals or a hundred.
+#[tokio::test]
+async fn a_scan_points_at_the_class_counts_behind_its_peak() {
+    let Some(token) = common::auth_token().await else {
+        eprintln!("skipping a_scan_points_at_the_class_counts_behind_its_peak: no token");
+        return;
+    };
+    if !common::db_available() {
+        eprintln!("skipping a_scan_points_at_the_class_counts_behind_its_peak: no database");
+        return;
+    }
+    let response = common::get_with_token(
+        "GET /groups/BXD/traits/10001/values",
+        "/groups/BXD/traits/10001/values",
+        &token,
+    )
+    .await;
+    assert_eq!(response.status(), StatusCode::OK);
+    let bytes = response.into_body().collect().await.unwrap().to_bytes();
+    let samples: Value = common::data(&bytes);
+    let body = serde_json::json!({
+        "group": "BXD",
+        "genotype_version": "BXD.4",
+        "trait_name": "BXD::10001",
+        "samples": samples,
+    });
+    let response =
+        common::post_json_with_token("POST /compute/rqtl", "/compute/rqtl", &token, &body).await;
+    assert_eq!(response.status(), StatusCode::OK);
+    let bytes = response.into_body().collect().await.unwrap().to_bytes();
+    let envelope: Value = serde_json::from_slice(&bytes).unwrap();
+    let links: Vec<&str> = envelope["next"]
+        .as_array()
+        .unwrap()
+        .iter()
+        .map(|action| action["href"].as_str().unwrap())
+        .collect();
+    let hint = links
+        .iter()
+        .find(|href| href.contains("/classes?trait="))
+        .unwrap_or_else(|| panic!("a scan offers the class counts at its peak: {links:?}"));
+    assert!(
+        hint.starts_with("/groups/BXD/genotypes/BXD.4/markers/"),
+        "the hint names this scan's own version and marker: {hint}"
+    );
+    assert!(
+        hint.contains("{trait_id}"),
+        "the trait id is the caller's to fill in: {hint}"
+    );
+    // And the marker it names is the peak the reply reported.
+    // /compute/rqtl's rows live under data.markers.
+    let rows = envelope["data"]["markers"].as_array().unwrap();
+    let peak = rows
+        .iter()
+        .max_by(|left, right| {
+            left[3]
+                .as_f64()
+                .unwrap()
+                .partial_cmp(&right[3].as_f64().unwrap())
+                .unwrap()
+        })
+        .unwrap();
+    assert!(
+        hint.contains(peak[0].as_str().unwrap()),
+        "the hint is at the peak marker {}: {hint}",
+        peak[0]
+    );
+}