diff --git a/riven/src/endpoints.rs b/riven/src/endpoints.rs index dc8ffc0..b5a4cd6 100644 --- a/riven/src/endpoints.rs +++ b/riven/src/endpoints.rs @@ -7,7 +7,7 @@ /////////////////////////////////////////////// // http://www.mingweisamuel.com/riotapi-schema/tool/ -// Version 5998519c2eb30a8c3f88edf1dcf88e2c6f091ba1 +// Version 517bb1adbfb393d65b8829b208ebe331bb6e73dc //! Automatically generated endpoint handles. #![allow(clippy::let_and_return, clippy::too_many_arguments)] diff --git a/riven/src/meta.rs b/riven/src/meta.rs index 9af003c..f89e02f 100644 --- a/riven/src/meta.rs +++ b/riven/src/meta.rs @@ -7,7 +7,7 @@ /////////////////////////////////////////////// // http://www.mingweisamuel.com/riotapi-schema/tool/ -// Version 5998519c2eb30a8c3f88edf1dcf88e2c6f091ba1 +// Version 517bb1adbfb393d65b8829b208ebe331bb6e73dc //! Metadata about the Riot API and Riven. //! diff --git a/riven/src/models.rs b/riven/src/models.rs index ad0f590..c2248e8 100644 --- a/riven/src/models.rs +++ b/riven/src/models.rs @@ -7,7 +7,7 @@ /////////////////////////////////////////////// // http://www.mingweisamuel.com/riotapi-schema/tool/ -// Version 5998519c2eb30a8c3f88edf1dcf88e2c6f091ba1 +// Version 517bb1adbfb393d65b8829b208ebe331bb6e73dc //! Data transfer structs. //! @@ -831,7 +831,8 @@ pub mod match_v5 { #[serde(rename = "consumablesPurchased")] pub consumables_purchased: i32, #[serde(rename = "damageDealtToBuildings")] - pub damage_dealt_to_buildings: i32, + #[serde(skip_serializing_if = "Option::is_none")] + pub damage_dealt_to_buildings: Option, #[serde(rename = "damageDealtToObjectives")] pub damage_dealt_to_objectives: i32, #[serde(rename = "damageDealtToTurrets")] @@ -871,7 +872,8 @@ pub mod match_v5 { #[serde(skip_serializing_if = "Option::is_none")] pub inhibitor_takedowns: Option, #[serde(rename = "inhibitorsLost")] - pub inhibitors_lost: i32, + #[serde(skip_serializing_if = "Option::is_none")] + pub inhibitors_lost: Option, #[serde(rename = "item0")] pub item0: i32, #[serde(rename = "item1")] @@ -916,7 +918,8 @@ pub mod match_v5 { #[serde(skip_serializing_if = "Option::is_none")] pub nexus_takedowns: Option, #[serde(rename = "nexusLost")] - pub nexus_lost: i32, + #[serde(skip_serializing_if = "Option::is_none")] + pub nexus_lost: Option, #[serde(rename = "objectivesStolen")] pub objectives_stolen: i32, #[serde(rename = "objectivesStolenAssists")] @@ -1014,7 +1017,8 @@ pub mod match_v5 { #[serde(skip_serializing_if = "Option::is_none")] pub turret_takedowns: Option, #[serde(rename = "turretsLost")] - pub turrets_lost: i32, + #[serde(skip_serializing_if = "Option::is_none")] + pub turrets_lost: Option, #[serde(rename = "unrealKills")] pub unreal_kills: i32, #[serde(rename = "visionScore")] diff --git a/riven/tests/tests_americas.rs b/riven/tests/tests_americas.rs index 28c52e3..d9d340f 100644 --- a/riven/tests/tests_americas.rs +++ b/riven/tests/tests_americas.rs @@ -12,7 +12,7 @@ use riven::models::tournament_stub_v4::*; const ROUTE: RegionalRoute = RegionalRoute::AMERICAS; -static MATCHES: [&str; 5] = [ +static MATCHES: &[&str] = &[ "NA1_3923487226", "NA1_4049206905", "NA1_4052515784", @@ -69,27 +69,10 @@ async_tests!{ }, match_v5_get: async { - for matche in MATCHES { - let p = RIOT_API.match_v5().get_match(ROUTE, matche); - let m = p.await.map_err(|e| format!("Failed to get match {}: {:?}", matche, e))?.ok_or(format!("Match {} not found.", matche))?; - rassert_eq!(matche, m.metadata.match_id, "Bad match id? Sent {}, received {}.", matche, m.metadata.match_id); - rassert!(!m.metadata.participants.is_empty(), "Match should have participants."); - rassert!(!m.info.teams.is_empty(), "Match should have teams."); - } - Ok(()) + match_v5_get(ROUTE, MATCHES).await }, match_v5_get_timeline: async { - for matche in MATCHES { - let p = RIOT_API.match_v5().get_timeline(ROUTE, matche); - let m = p.await.map_err(|e| format!("Failed to get match {}: {:?}", matche, e))?.ok_or(format!("Match {} not found.", matche))?; - rassert_eq!(matche, m.metadata.match_id, "Bad match id? Sent {}, received {}.", matche, m.metadata.match_id); - rassert!(!m.metadata.participants.is_empty(), "Match should have participants."); - if let Some(game_id) = m.info.game_id { - rassert_eq!(matche[(matche.find('_').unwrap() + 1)..], format!("{}", game_id), "Match number ID should match."); - } - rassert!(!m.info.frames.is_empty(), "Match timleine should have frames."); - } - Ok(()) + match_v5_get_timeline(ROUTE, MATCHES).await }, } } diff --git a/riven/tests/tests_asia.rs b/riven/tests/tests_asia.rs index b693912..d5c5a60 100644 --- a/riven/tests/tests_asia.rs +++ b/riven/tests/tests_asia.rs @@ -11,7 +11,7 @@ use riven::consts::*; const ROUTE: RegionalRoute = RegionalRoute::ASIA; -static MATCHES: [&str; 11] = [ +static MATCHES: &[&str] = &[ // Regular game: "KR_5495121707", // `teamPosition` empty: @@ -27,32 +27,18 @@ static MATCHES: [&str; 11] = [ "JP1_283568774", // `individualPosition` is set but `teamPosition` is empty due to AFK slightly after beginning: "JP1_285797147", + // Illegal big `championId`s. https://github.com/RiotGames/developer-relations/issues/553 + "JP1_267647303", + "JP1_273343663", ]; -async_tests!{ +async_tests! { my_runner { match_v5_get: async { - for matche in MATCHES { - let p = RIOT_API.match_v5().get_match(ROUTE, matche); - let m = p.await.map_err(|e| format!("Failed to get match {}: {:?}", matche, e))?.ok_or(format!("Match {} not found.", matche))?; - rassert_eq!(matche, m.metadata.match_id, "Bad match id? Sent {}, received {}.", matche, m.metadata.match_id); - rassert!(!m.metadata.participants.is_empty(), "Match should have participants."); - rassert!(!m.info.teams.is_empty(), "Match should have teams."); - } - Ok(()) + match_v5_get(ROUTE, MATCHES).await }, match_v5_get_timeline: async { - for matche in MATCHES { - let p = RIOT_API.match_v5().get_timeline(ROUTE, matche); - let m = p.await.map_err(|e| format!("Failed to get match {}: {:?}", matche, e))?.ok_or(format!("Match {} not found.", matche))?; - rassert_eq!(matche, m.metadata.match_id, "Bad match id? Sent {}, received {}.", matche, m.metadata.match_id); - rassert!(!m.metadata.participants.is_empty(), "Match should have participants."); - if let Some(game_id) = m.info.game_id { - rassert_eq!(matche[(matche.find('_').unwrap() + 1)..], format!("{}", game_id), "Match number ID should match."); - } - rassert!(!m.info.frames.is_empty(), "Match timleine should have frames."); - } - Ok(()) + match_v5_get_timeline(ROUTE, MATCHES).await }, } } diff --git a/riven/tests/tests_europe.rs b/riven/tests/tests_europe.rs new file mode 100644 index 0000000..08d8308 --- /dev/null +++ b/riven/tests/tests_europe.rs @@ -0,0 +1,30 @@ +#![cfg_attr(feature = "nightly", feature(custom_test_frameworks))] +#![cfg_attr(feature = "nightly", test_runner(my_runner))] + +mod async_tests; +mod testutils; +use testutils::*; + +use colored::*; + +use riven::consts::*; + +const ROUTE: RegionalRoute = RegionalRoute::EUROPE; + +static MATCHES: &[&str] = &[ + // Illegal big `championId`s. https://github.com/RiotGames/developer-relations/issues/553 + "EUW1_5097684633", + "EUW1_5097963383", + "EUW1_5102203800", // https://github.com/MingweiSamuel/Riven/issues/36 +]; + +async_tests! { + my_runner { + match_v5_get: async { + match_v5_get(ROUTE, MATCHES).await + }, + match_v5_get_timeline: async { + match_v5_get_timeline(ROUTE, MATCHES).await + }, + } +} diff --git a/riven/tests/testutils.rs b/riven/tests/testutils.rs index 00df739..0112164 100644 --- a/riven/tests/testutils.rs +++ b/riven/tests/testutils.rs @@ -2,11 +2,13 @@ use lazy_static::lazy_static; -use riven::{ RiotApi, RiotApiConfig }; +use riven::consts::RegionalRoute; +use riven::{RiotApi, RiotApiConfig}; lazy_static! { pub static ref RIOT_API: RiotApi = { - let api_key = std::env::var("RGAPI_KEY").ok() + let api_key = std::env::var("RGAPI_KEY") + .ok() .or_else(|| std::fs::read_to_string("apikey.txt").ok()) .expect("Failed to find RGAPI_KEY env var or apikey.txt."); RiotApi::new(RiotApiConfig::with_key(api_key.trim()).preconfig_burst()) @@ -15,8 +17,63 @@ lazy_static! { pub mod ids { pub const SUMMONER_ID_LUGNUTSK: &str = "SBM8Ubipo4ge2yj7bhEzL7yvV0C9Oc1XA2l6v5okGMA_nCw"; - pub const SUMMONER_ID_MA5TERY: &str = "IbC4uyFEEW3ZkZw6FZF4bViw3P1EynclAcI6-p-vCpI99Ec"; + pub const SUMMONER_ID_MA5TERY: &str = "IbC4uyFEEW3ZkZw6FZF4bViw3P1EynclAcI6-p-vCpI99Ec"; pub const SUMMONER_ID_C9SNEAKY: &str = "ghHSdADqgxKwcRl_vWndx6wKiyZx0xKQv-LOhOcU5LU"; - pub const ACCOUNT_ID_C9SNEAKY: &str = "ML_CcLT94UUHp1iDvXOXCidfmzzPrk_Jbub1f_INhw"; - pub const ACCOUNT_ID_LUGNUTSK: &str = "iheZF2uJ50S84Hfq6Ob8GNlJAUmBmac-EsEEWBJjD01q1jQ"; + pub const ACCOUNT_ID_C9SNEAKY: &str = "ML_CcLT94UUHp1iDvXOXCidfmzzPrk_Jbub1f_INhw"; + pub const ACCOUNT_ID_LUGNUTSK: &str = "iheZF2uJ50S84Hfq6Ob8GNlJAUmBmac-EsEEWBJjD01q1jQ"; +} + +pub async fn match_v5_get(route: RegionalRoute, matches: &[&'static str]) -> Result<(), String> { + for &matche in matches { + let p = RIOT_API.match_v5().get_match(route, matche); + let m = p + .await + .map_err(|e| format!("Failed to get match {}: {:?}", matche, e))? + .ok_or(format!("Match {} not found.", matche))?; + + if matche != &*m.metadata.match_id { + return Err(format!( + "Bad match id? Sent {}, received {}.", + matche, m.metadata.match_id + )); + } + if m.metadata.participants.is_empty() { + return Err("Match should have participants.".to_owned()); + } + if m.info.teams.is_empty() { + return Err("Match should have teams.".to_owned()); + } + } + Ok(()) +} + +pub async fn match_v5_get_timeline( + route: RegionalRoute, + matches: &[&'static str], +) -> Result<(), String> { + for &matche in matches { + let p = RIOT_API.match_v5().get_timeline(route, matche); + let m = p + .await + .map_err(|e| format!("Failed to get match {}: {:?}", matche, e))? + .ok_or(format!("Match {} not found.", matche))?; + if matche != &*m.metadata.match_id { + return Err(format!( + "Bad match id? Sent {}, received {}.", + matche, m.metadata.match_id + )); + } + if m.metadata.participants.is_empty() { + return Err("Match should have participants.".to_owned()); + } + if let Some(game_id) = m.info.game_id { + if matche[(matche.find('_').unwrap() + 1)..] != game_id.to_string() { + return Err("Match number ID should match.".to_owned()); + } + } + if m.info.frames.is_empty() { + return Err("Match timleine should have frames.".to_owned()); + } + } + Ok(()) }