mlb_api/endpoints/teams/team/alumni/
mod.rs

1use crate::endpoints::StatsAPIUrl;
2use crate::endpoints::teams::team::TeamId;
3use crate::gen_params;
4use std::fmt::{Display, Formatter};
5use crate::endpoints::people::PeopleResponse;
6
7pub struct AlumniEndpointUrl {
8	team_id: TeamId,
9	season: Option<u16>,
10}
11
12impl Display for AlumniEndpointUrl {
13	fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
14		write!(f, "http://statsapi.mlb.com/api/v1/teams/{}/alumni{}", self.team_id, gen_params! { "season"?: self.season })
15	}
16}
17
18impl StatsAPIUrl for AlumniEndpointUrl {
19	type Response = PeopleResponse;
20}
21
22#[cfg(test)]
23mod tests {
24	use crate::endpoints::StatsAPIUrl;
25	use crate::endpoints::teams::TeamsEndpointUrl;
26	use crate::endpoints::teams::team::alumni::AlumniEndpointUrl;
27	use chrono::{Datelike, Local};
28
29	#[tokio::test]
30	#[cfg_attr(not(feature = "_heavy_tests"), ignore)]
31	async fn test_heavy() {
32		let season = Local::now().year() as _;
33		let teams = TeamsEndpointUrl { sport_id: None, season: Some(season) }.get().await.unwrap();
34		for team in teams.teams {
35			let json = reqwest::get(AlumniEndpointUrl { team_id: team.id, season: Some(season) }.to_string()).await.unwrap().bytes().await.unwrap();
36			let mut de = serde_json::Deserializer::from_slice(&json);
37			let result: Result<<AlumniEndpointUrl as StatsAPIUrl>::Response, serde_path_to_error::Error<_>> = serde_path_to_error::deserialize(&mut de);
38			match result {
39				Ok(_) => {}
40				Err(e) if format!("{:?}", e.inner()).contains("missing field `copyright`") => {}
41				Err(e) => panic!("Err: {:?}", e),
42			}
43		}
44	}
45}