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
|
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.
/// Br_U_0803_M is a real ProbeSetFreeze row in BXD, used here as a
/// fixture the same way BXD itself is used elsewhere.
#[tokio::test]
async fn dataset_by_name_returns_dataset_row() {
if !common::db_available() {
eprintln!(
"skipping dataset_by_name_returns_dataset_row: no usable database (check SQL_URI credentials)"
);
return;
}
let Some(token) = common::auth_token().await else {
eprintln!("skipping dataset_by_name_returns_dataset_row: no token (see docs/gn-auth.md)");
return;
};
let response =
common::get_with_token("GET /datasets/Br_U_0803_M", "/datasets/Br_U_0803_M", &token).await;
assert_eq!(response.status(), StatusCode::OK);
let body = response.into_body().collect().await.unwrap().to_bytes();
let dataset: Value = common::data(&body);
assert_eq!(dataset["name"], "Br_U_0803_M");
assert_eq!(dataset["full_name"], "Brain U74Av2 08/03 MAS5");
assert_eq!(dataset["data_scale"], "log2");
}
#[tokio::test]
async fn dataset_by_name_unknown_dataset_returns_404() {
if !common::db_available() {
eprintln!(
"skipping dataset_by_name_unknown_dataset_returns_404: no usable database (check SQL_URI credentials)"
);
return;
}
let Some(token) = common::auth_token().await else {
eprintln!(
"skipping dataset_by_name_unknown_dataset_returns_404: no token (see docs/gn-auth.md)"
);
return;
};
let response = common::get_with_token(
"GET /datasets/not-a-real-dataset",
"/datasets/not-a-real-dataset",
&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"], "dataset_not_found");
assert_eq!(error["operation_id"], "dataset_by_name");
}
/// A dataset says what it was measured in (the Tissue its ProbeFreeze
/// points to), here and in the group's dataset list.
#[tokio::test]
async fn datasets_report_their_tissue() {
if !common::db_available() {
eprintln!(
"skipping datasets_report_their_tissue: no usable database (check SQL_URI credentials)"
);
return;
}
let Some(token) = common::auth_token().await else {
eprintln!("skipping datasets_report_their_tissue: no token (see docs/gn-auth.md)");
return;
};
let response =
common::get_with_token("GET /datasets/Br_U_0803_M", "/datasets/Br_U_0803_M", &token).await;
assert_eq!(response.status(), StatusCode::OK);
let body = response.into_body().collect().await.unwrap().to_bytes();
let dataset: Value = common::data(&body);
assert_eq!(dataset["tissue"], "Brain mRNA");
let response =
common::get_with_token("GET /groups/BXD/datasets", "/groups/BXD/datasets", &token).await;
let body = response.into_body().collect().await.unwrap().to_bytes();
let datasets: Vec<Value> = common::data(&body);
let gut = datasets
.iter()
.find(|d| d["name"] == "UTHSC_GutGL_0414")
.unwrap();
assert_eq!(gut["tissue"], "Gastrointestinal mRNA");
}
|