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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
//! /traits/... spans both ProbeSet and Publish data (see
//! src/routes/traits.rs and docs/gn-auth.md); these tests exercise
//! both categories through the same URL shape. Needs a live MariaDB
//! connection (SQL_URI) and a live gn-auth (AUTH_SERVER_URL) plus
//! GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md); skips rather than fails
//! when either is missing, same as dataset_probeset_info.rs.
use axum::http::StatusCode;
use http_body_util::BodyExt;
use serde_json::Value;
mod common;
async fn fixtures() -> Option<String> {
if !common::db_available() {
eprintln!("skipping: no usable database (check SQL_URI credentials)");
return None;
}
let Some(token) = common::auth_token().await else {
eprintln!("skipping: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)");
return None;
};
if !common::auth_server_available() {
eprintln!("skipping: no gn-auth reachable");
return None;
}
Some(token)
}
/// Dataset Br_U_0803_M's CreateTime is 2003-08-01, so it's publicly
/// readable regardless of its public/confidentiality flags -- a valid
/// token is still required, but no gn-auth authorization call happens.
#[tokio::test]
async fn trait_info_probeset_category() {
let Some(token) = fixtures().await else {
return;
};
let response = common::get_with_token(
"GET /traits/Br_U_0803_M/100001_at",
"/traits/Br_U_0803_M/100001_at",
&token,
)
.await;
assert_eq!(response.status(), StatusCode::OK);
let body = response.into_body().collect().await.unwrap().to_bytes();
let info: Value = common::data(&body);
assert_eq!(info["category"], "probeset");
assert_eq!(info["name"], "100001_at");
assert_eq!(info["symbol"], "Cd3g");
}
/// BXD's PublishFreeze (BXDPublish) is addressable both by its own
/// name and by the owning group's name, matching GeneNetwork2's
/// wqflask.api.router.trait_sample_data's Publish branch.
#[tokio::test]
async fn trait_info_publish_category_by_group_name() {
let Some(token) = fixtures().await else {
return;
};
let response =
common::get_with_token("GET /traits/BXD/10001", "/traits/BXD/10001", &token).await;
assert_eq!(response.status(), StatusCode::OK);
let body = response.into_body().collect().await.unwrap().to_bytes();
let info: Value = common::data(&body);
assert_eq!(info["category"], "publish");
assert_eq!(info["id"], 10001);
}
#[tokio::test]
async fn trait_info_publish_category_by_publish_freeze_name() {
let Some(token) = fixtures().await else {
return;
};
let response = common::get_with_token(
"GET /traits/BXDPublish/10001",
"/traits/BXDPublish/10001",
&token,
)
.await;
assert_eq!(response.status(), StatusCode::OK);
let body = response.into_body().collect().await.unwrap().to_bytes();
let info: Value = common::data(&body);
assert_eq!(info["category"], "publish");
assert_eq!(info["id"], 10001);
}
#[tokio::test]
async fn trait_values_probeset_category() {
let Some(token) = fixtures().await else {
return;
};
let response = common::get_with_token(
"GET /traits/Br_U_0803_M/100001_at/values",
"/traits/Br_U_0803_M/100001_at/values",
&token,
)
.await;
assert_eq!(response.status(), StatusCode::OK);
let body = response.into_body().collect().await.unwrap().to_bytes();
let values: Vec<Value> = common::data(&body);
assert!(!values.is_empty());
assert!(values.iter().any(|v| v["name"] == "BXD1"));
}
#[tokio::test]
async fn trait_values_publish_category() {
let Some(token) = fixtures().await else {
return;
};
let response = common::get_with_token(
"GET /traits/BXD/10001/values",
"/traits/BXD/10001/values",
&token,
)
.await;
assert_eq!(response.status(), StatusCode::OK);
let body = response.into_body().collect().await.unwrap().to_bytes();
let values: Vec<Value> = common::data(&body);
assert!(!values.is_empty());
assert!(values.iter().any(|v| v["name"] == "BXD1"));
}
#[tokio::test]
async fn traits_list_probeset_category() {
let Some(token) = fixtures().await else {
return;
};
let response =
common::get_with_token("GET /traits/Br_U_0803_M", "/traits/Br_U_0803_M", &token).await;
assert_eq!(response.status(), StatusCode::OK);
let body = response.into_body().collect().await.unwrap().to_bytes();
let traits: Vec<Value> = common::data(&body);
assert!(!traits.is_empty());
assert!(traits.iter().all(|t| t["category"] == "probeset"));
assert!(traits.iter().any(|t| t["name"] == "100001_at"));
}
#[tokio::test]
async fn traits_list_publish_category() {
let Some(token) = fixtures().await else {
return;
};
let response = common::get_with_token("GET /traits/BXD", "/traits/BXD", &token).await;
assert_eq!(response.status(), StatusCode::OK);
let body = response.into_body().collect().await.unwrap().to_bytes();
let traits: Vec<Value> = common::data(&body);
assert!(!traits.is_empty());
assert!(traits.iter().all(|t| t["category"] == "publish"));
assert!(traits.iter().any(|t| t["id"] == 10001));
}
#[tokio::test]
async fn trait_info_without_a_token_returns_401() {
if !common::db_available() {
eprintln!(
"skipping trait_info_without_a_token_returns_401: no usable database (check SQL_URI credentials)"
);
return;
}
let response = common::get("GET /traits/BXD/10001 (no token)", "/traits/BXD/10001").await;
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
}
#[tokio::test]
async fn trait_info_unknown_dataset_returns_404() {
let Some(token) = fixtures().await else {
return;
};
let response = common::get_with_token(
"GET /traits/not-a-real-dataset/123",
"/traits/not-a-real-dataset/123",
&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"], "dataset_not_found");
assert_eq!(error["operation_id"], "trait_info");
}
#[tokio::test]
async fn trait_info_unknown_trait_in_probeset_dataset_returns_404() {
let Some(token) = fixtures().await else {
return;
};
let response = common::get_with_token(
"GET /traits/Br_U_0803_M/not-a-real-probeset",
"/traits/Br_U_0803_M/not-a-real-probeset",
&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"], "trait_not_found");
}
#[tokio::test]
async fn trait_info_unknown_trait_in_publish_dataset_returns_404() {
let Some(token) = fixtures().await else {
return;
};
let response =
common::get_with_token("GET /traits/BXD/99999999", "/traits/BXD/99999999", &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"], "trait_not_found");
}
/// A non-numeric trait segment against a Publish dataset can never
/// match a PublishXRef.Id -- same 404 as a numeric id that just
/// doesn't exist, not a 500 from a failed parse.
#[tokio::test]
async fn trait_info_non_numeric_trait_in_publish_dataset_returns_404() {
let Some(token) = fixtures().await else {
return;
};
let response = common::get_with_token(
"GET /traits/BXD/not-a-number",
"/traits/BXD/not-a-number",
&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"], "trait_not_found");
}
/// UTHSC_BXD_Cochlea_0225 (public=1, confidentiality=1, created
/// 2025-02-13) is neither publicly readable by the flags nor old
/// enough for the embargo-age rule, and has never been linked to a
/// gn-auth resource -- same fixture as dataset_probeset_info.rs,
/// exercised here through the unified endpoint instead.
#[tokio::test]
async fn trait_info_non_public_unlinked_probeset_dataset_returns_403() {
let Some(token) = fixtures().await else {
return;
};
let response = common::get_with_token(
"GET /traits/UTHSC_BXD_Cochlea_0225/ENSMUSG00000028180",
"/traits/UTHSC_BXD_Cochlea_0225/ENSMUSG00000028180",
&token,
)
.await;
assert_eq!(response.status(), StatusCode::FORBIDDEN);
let body = response.into_body().collect().await.unwrap().to_bytes();
let error: Value = serde_json::from_slice(&body).unwrap();
assert_eq!(error["code"], "forbidden");
}
/// Same as above, but with a dataset genuinely less than a year old
/// (UTHSC_BXD_Cochlea_0225 above is real but was already ~20 months
/// old by the time this test was written) -- the age-embargo rule and
/// the "not yet linked to any gn-auth resource" deny path both need to
/// hold for freshly-added data, not just for something that merely
/// hasn't aged into public yet. UTHSC_BXD_2wk_Cochlea_0926
/// (public=1, confidentiality=1, created 2026-09-01) is the most
/// recently added ProbeSetFreeze in the database as of this writing.
#[tokio::test]
async fn trait_info_recent_non_public_probeset_dataset_returns_403() {
let Some(token) = fixtures().await else {
return;
};
let response = common::get_with_token(
"GET /traits/UTHSC_BXD_2wk_Cochlea_0926/ENSMUSG00000028180",
"/traits/UTHSC_BXD_2wk_Cochlea_0926/ENSMUSG00000028180",
&token,
)
.await;
assert_eq!(response.status(), StatusCode::FORBIDDEN);
let body = response.into_body().collect().await.unwrap().to_bytes();
let error: Value = serde_json::from_slice(&body).unwrap();
assert_eq!(error["code"], "forbidden");
}
|