use super::*;
use crate::ArticleId;
use chrono::{DateTime, FixedOffset};
use std::borrow::Cow;
#[test]
fn test_malfored_query() {
use serde::Deserialize;
use std::collections::BTreeMap;
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct Entry<'r> {
pub authors: Vec<AuthorName>,
pub comment: Option<&'r str>,
}
let contents = include_str!("../response/tests/query_missing_id.xml").as_bytes();
let response = Response::<Vec<Entry>>::from_xml(contents).unwrap();
assert_eq!(response.entries.len(), 1);
assert!(response.entries[0].comment.is_some());
let response = Response::<BTreeMap<ArticleId, Entry>>::from_xml(contents).unwrap();
assert_eq!(
response
.entries
.get(&ArticleId::parse("2201.13452v1").unwrap())
.unwrap()
.authors[0]
.to_string(),
"Hong-Ming Yin"
);
}
#[test]
fn test_query_de() {
use serde::Deserialize;
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct Entry<'r> {
pub id: ArticleId,
pub updated: DateTime<FixedOffset>,
pub published: DateTime<FixedOffset>,
#[serde(borrow)]
pub title: Cow<'r, str>,
#[serde(borrow)]
pub summary: Cow<'r, str>,
pub authors: Vec<Author<'r>>,
#[serde(borrow)]
pub doi: Option<Cow<'r, str>>,
#[serde(borrow)]
pub comment: Option<Cow<'r, str>>,
#[serde(borrow)]
pub journal_ref: Option<Cow<'r, str>>,
#[serde(borrow)]
pub primary_category: Cow<'r, str>,
#[serde(borrow)]
pub categories: Vec<Cow<'r, str>>,
extra: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct Author<'r> {
pub name: AuthorName,
#[serde(borrow)]
pub affiliation: Option<Cow<'r, str>>,
}
let contents = include_str!("../response/tests/query.xml").as_bytes();
let response = Response::<Vec<Entry>>::from_xml(contents).unwrap();
assert_eq!(
Ok(response.updated),
chrono::DateTime::parse_from_rfc3339("2025-11-11T18:29:40+00:00")
);
assert_eq!(response.pagination.total_results, 7432,);
assert_eq!(response.pagination.start_index, 0);
assert_eq!(response.pagination.items_per_page, 10);
assert_eq!(
Ok(response.entries[0].id),
crate::id::ArticleId::parse("nucl-ex/0408020v1")
);
assert_eq!(response.entries.len(), 10);
assert_eq!(
response.entries[9].authors[0].name,
AuthorName {
firstnames: "U. D.".to_owned(),
keyname: "Jentschura".to_owned(),
suffix: String::new()
}
);
assert_eq!(response.entries[8].primary_category, "physics.plasm-ph");
assert_eq!(
response.entries[8].comment.as_ref().unwrap(),
"11 pages, 19 figures"
);
assert_eq!(response.entries[8].journal_ref, None);
assert_eq!(response.entries[8].authors.len(), 3);
assert_eq!(response.entries[9].authors[0].affiliation, None);
assert_eq!(
response.entries[9].doi.as_ref().unwrap(),
"10.1103/PhysRevA.88.062514"
);
assert_eq!(response.entries[9].categories[2], "nucl-th");
assert_eq!(
response.entries[9].published,
chrono::DateTime::parse_from_rfc3339("2014-01-15T16:58:15Z").unwrap()
);
let contents = include_str!("../response/tests/query_empty.xml").as_bytes();
let response = Response::<Vec<Entry>>::from_xml(contents).unwrap();
assert_eq!(
Ok(response.updated),
chrono::DateTime::parse_from_rfc3339("2025-11-11T18:34:08+00:00")
);
assert!(response.entries.is_empty());
}