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
pub mod scholar;

#[cfg(test)]
mod tests {
    use crate::scholar;
    #[test]
    fn new_scholar_query() {
        let sc = scholar::ScholarArgs{
            query: "machine-learning",
            cite_id: None,
            from_year: None,
            to_year: None,
            sort_by: None,
            cluster_id: None,
            lang: None,
            lang_limit: None,
            limit: Some(3),
            offset: Some(0),
            adult_filtering: None,
            include_similar_results: None,
            include_citations: None,
        };
        assert_eq!(sc.query, "machine-learning");
    }

    #[tokio::test]
    async fn scrape() {
        let sc = scholar::ScholarArgs{
            query: "machine-learning",
            cite_id: None,
            from_year: None,
            to_year: None,
            sort_by: None,
            cluster_id: None,
            lang: None,
            lang_limit: None,
            limit: Some(3),
            offset: Some(0),
            adult_filtering: None,
            include_similar_results: None,
            include_citations: None,
        };

        let client = scholar::init_client();
        match client.scrape_scholar(&sc).await {
            Ok(result) => assert_eq!(result.len(), 3),
            Err(_e) => assert_eq!(true, false),
        };
    }
}