1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
//! The QTL-mapping suggestions in `actions` (src/suggest.rs).
//!
//! Fetching one trait's values is usually the step before mapping that
//! trait, so the per-strain values endpoints suggest `/compute/rqtl` and
//! `/compute/gemma` — as `POST`s with a ready-to-edit body, which is why
//! they are in `actions` and not in `next` (`next` is the list of GETs
//! that return 200, and `tests/envelope.rs` follows every one of them).
//!
//! One test function per binary, mutating nothing and needing only a
//! token and a database; skips without them.
use axum::body::Body;
use axum::http::StatusCode;
use http_body_util::BodyExt;
use serde_json::Value;
mod common;
async fn get_json(uri: &str, token: &str) -> (StatusCode, Value) {
let response = common::get_with_token(&format!("GET {uri}"), uri, token).await;
let status = response.status();
let bytes = response.into_body().collect().await.unwrap().to_bytes();
(status, serde_json::from_slice(&bytes).unwrap())
}
#[tokio::test]
async fn values_responses_suggest_rqtl_and_gemma_but_plain_lists_do_not() {
if !common::db_available() {
eprintln!(
"skipping values_responses_suggest_rqtl_and_gemma_but_plain_lists_do_not: no usable \
database (check SQL_URI credentials)"
);
return;
}
let Some(token) = common::auth_token().await else {
eprintln!(
"skipping values_responses_suggest_rqtl_and_gemma_but_plain_lists_do_not: set \
GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)"
);
return;
};
// 1. A published trait's values: both mapping endpoints, with the
// values already in the body, in the response's own sample order.
let (status, body) = get_json("/groups/BXD/traits/10001/values", &token).await;
assert_eq!(status, StatusCode::OK, "{body}");
let values = body["data"].as_array().expect("data is a list of values");
let actions = body["actions"]
.as_array()
.expect("the values endpoints carry actions");
assert_eq!(actions.len(), 2, "{body}");
assert_eq!(actions[0]["method"], "POST");
assert_eq!(actions[0]["href"], "/compute/rqtl");
assert_eq!(actions[1]["method"], "POST");
assert_eq!(actions[1]["href"], "/compute/gemma");
// The values travel with the suggestion *and* the group, so the body
// is runnable as it stands: the server resolves the genotype files
// from `group`, and the values are matched onto the panel by name.
for action in actions {
let body = &action["body"];
let samples = body["samples"].as_array().expect("named samples");
assert_eq!(samples.len(), values.len());
assert_eq!(samples[0]["name"], values[0]["name"]);
assert_eq!(samples[0]["value"], values[0]["value"]);
assert_eq!(
body["group"], "BXD",
"the group is named, so no path is needed: {action}"
);
let text = body.to_string();
assert!(
!text.contains("genotype_file") && !text.contains('<'),
"no placeholders in a group-scoped suggestion: {text}"
);
}
// 2. The other two values routes get the same treatment: one for a
// ProbeSet value (`db::ProbeSetValue`), one for the dataset/trait
// addressing of the same published value.
for uri in [
"/datasets/Br_U_0803_M/probesets/100001_at/values",
"/traits/BXDPublish/10001/values",
] {
let (status, body) = get_json(uri, &token).await;
assert_eq!(status, StatusCode::OK, "{uri}: {body}");
assert_eq!(
body["actions"].as_array().map(|a| a.len()),
Some(2),
"{uri}: {body}"
);
// These routes do not know which group the dataset belongs to, so
// their suggestions keep the file-path placeholder and say so.
let action = &body["actions"][0];
assert!(
action["body"]["genotype_file"]
.as_str()
.unwrap()
.starts_with('<'),
"{uri}: {action}"
);
assert!(
action["description"]
.as_str()
.unwrap()
.contains("group"),
"the description says to add the group: {action}"
);
}
// 3. Endpoints that are not about one trait's values keep the
// four-member envelope: no empty `actions` on every response.
for uri in ["/species", "/groups/BXD", "/groups/BXD/traits/10001"] {
let (status, body) = get_json(uri, &token).await;
assert_eq!(status, StatusCode::OK, "{uri}: {body}");
assert!(body.get("actions").is_none(), "{uri}: {body}");
}
// 4. `next` stays what it was: GETs that return 200, nothing else.
let (_, body) = get_json("/groups/BXD/traits/10001/values", &token).await;
for next in body["next"].as_array().unwrap() {
assert!(next.get("method").is_none(), "{next}");
let response = common::get_with_token("next link", next["href"].as_str().unwrap(), &token)
.await;
assert_eq!(response.status(), StatusCode::OK, "{next}");
}
}
|