about summary refs log tree commit diff
path: root/tests/publications.rs
blob: f17f369e064785a114d94ba0ee9a8b4900cb779d (plain)
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
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; skips rather than fails when either is missing, same as
/// group_traits.rs. PubMed 24102824 is the Ye et al. serotonin
/// homeostasis paper behind BXDPublish trait 17985.
#[tokio::test]
async fn publication_traits_lists_the_traits_a_paper_reports() {
    if !common::db_available() {
        eprintln!(
            "skipping publication_traits_lists_the_traits_a_paper_reports: no usable database (check SQL_URI credentials)"
        );
        return;
    }
    let Some(token) = common::auth_token().await else {
        eprintln!(
            "skipping publication_traits_lists_the_traits_a_paper_reports: no token (see docs/gn-auth.md)"
        );
        return;
    };

    let response = common::get_with_token(
        "GET /publications/24102824/traits",
        "/publications/24102824/traits",
        &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.iter().all(|t| t["pubmed_id"] == 24102824));
    let midbrain = traits
        .iter()
        .find(|t| t["id"] == 17985)
        .expect("trait 17985 is reported by this paper");
    assert_eq!(midbrain["dataset"], "BXDPublish");
    assert_eq!(midbrain["abbreviation"], "5HT_MB_M");
}

#[tokio::test]
async fn publication_traits_unknown_pubmed_id_returns_404() {
    if !common::db_available() {
        eprintln!(
            "skipping publication_traits_unknown_pubmed_id_returns_404: no usable database (check SQL_URI credentials)"
        );
        return;
    }
    let Some(token) = common::auth_token().await else {
        eprintln!(
            "skipping publication_traits_unknown_pubmed_id_returns_404: no token (see docs/gn-auth.md)"
        );
        return;
    };

    let response = common::get_with_token(
        "GET /publications/999999999/traits",
        "/publications/999999999/traits",
        &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"], "publication_not_found");
    assert_eq!(error["operation_id"], "publication_traits");
}