From 7e5bccd0390c2886e04c04c9a80e448b06ae71c6 Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Tue, 9 Nov 2021 19:07:31 -0800 Subject: [PATCH] Update for optional fields in match-v5 timeline DTOs, adding more test matches --- riven/src/endpoints.rs | 2 +- riven/src/meta.rs | 2 +- riven/src/models.rs | 17 +++++++++++------ riven/tests/tests_americas.rs | 16 ++++++++++++---- riven/tests/tests_asia.rs | 26 ++++++++++++++++++++++---- 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/riven/src/endpoints.rs b/riven/src/endpoints.rs index c4bb3f8..d85e724 100644 --- a/riven/src/endpoints.rs +++ b/riven/src/endpoints.rs @@ -7,7 +7,7 @@ /////////////////////////////////////////////// // http://www.mingweisamuel.com/riotapi-schema/tool/ -// Version 309704e3979855858e36430b178e507e48702059 +// Version f7d7b8c90243fcb043ffe81c5b08b0925be83bdf //! 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 f9219c4..62e2e85 100644 --- a/riven/src/meta.rs +++ b/riven/src/meta.rs @@ -7,7 +7,7 @@ /////////////////////////////////////////////// // http://www.mingweisamuel.com/riotapi-schema/tool/ -// Version 309704e3979855858e36430b178e507e48702059 +// Version f7d7b8c90243fcb043ffe81c5b08b0925be83bdf //! Metadata about the Riot API and Riven. //! diff --git a/riven/src/models.rs b/riven/src/models.rs index 914c912..f624407 100644 --- a/riven/src/models.rs +++ b/riven/src/models.rs @@ -7,7 +7,7 @@ /////////////////////////////////////////////// // http://www.mingweisamuel.com/riotapi-schema/tool/ -// Version 309704e3979855858e36430b178e507e48702059 +// Version f7d7b8c90243fcb043ffe81c5b08b0925be83bdf //! Data transfer structs. //! @@ -1236,7 +1236,8 @@ pub mod match_v5 { #[derive(serde::Serialize, serde::Deserialize)] pub struct MatchTimelineInfoFrameParticipantFrameChampionStats { #[serde(rename = "abilityHaste")] - pub ability_haste: i32, + #[serde(skip_serializing_if = "Option::is_none")] + pub ability_haste: Option, #[serde(rename = "abilityPower")] pub ability_power: i32, #[serde(rename = "armor")] @@ -1274,9 +1275,11 @@ pub mod match_v5 { #[serde(rename = "movementSpeed")] pub movement_speed: i32, #[serde(rename = "omnivamp")] - pub omnivamp: i32, + #[serde(skip_serializing_if = "Option::is_none")] + pub omnivamp: Option, #[serde(rename = "physicalVamp")] - pub physical_vamp: i32, + #[serde(skip_serializing_if = "Option::is_none")] + pub physical_vamp: Option, #[serde(rename = "power")] pub power: i32, #[serde(rename = "powerMax")] @@ -1430,9 +1433,11 @@ pub mod match_v5 { #[serde(rename = "frames")] pub frames: std::vec::Vec, #[serde(rename = "gameId")] - pub game_id: i64, + #[serde(skip_serializing_if = "Option::is_none")] + pub game_id: Option, #[serde(rename = "participants")] - pub participants: std::vec::Vec, + #[serde(skip_serializing_if = "Option::is_none")] + pub participants: Option>, } } diff --git a/riven/tests/tests_americas.rs b/riven/tests/tests_americas.rs index 9b3315e..28c52e3 100644 --- a/riven/tests/tests_americas.rs +++ b/riven/tests/tests_americas.rs @@ -12,7 +12,13 @@ use riven::models::tournament_stub_v4::*; const ROUTE: RegionalRoute = RegionalRoute::AMERICAS; -static MATCHES: [&str; 4] = [ "NA1_3923487226", "NA1_4049206905", "NA1_4052515784", "NA1_4062578191" ]; +static MATCHES: [&str; 5] = [ + "NA1_3923487226", + "NA1_4049206905", + "NA1_4052515784", + "NA1_4062578191", + "NA1_4097036960", +]; async_tests!{ my_runner { @@ -65,7 +71,7 @@ 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| e.to_string())?.ok_or(format!("Match {} not found.", 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."); @@ -75,10 +81,12 @@ async_tests!{ 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| e.to_string())?.ok_or(format!("Match timeline {} not found.", 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_eq!(matche[(matche.find('_').unwrap() + 1)..], format!("{}", m.info.game_id), "Match number ID should match."); + 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(()) diff --git a/riven/tests/tests_asia.rs b/riven/tests/tests_asia.rs index 04be90b..b693912 100644 --- a/riven/tests/tests_asia.rs +++ b/riven/tests/tests_asia.rs @@ -11,14 +11,30 @@ use riven::consts::*; const ROUTE: RegionalRoute = RegionalRoute::ASIA; -static MATCHES: [&str; 1] = [ "KR_5495121707" ]; +static MATCHES: [&str; 11] = [ + // Regular game: + "KR_5495121707", + // `teamPosition` empty: + // AFK: + "JP1_312062554", + "JP1_326464722", + "JP1_289504387", + "JP1_285434511", + "JP1_307559381", + "JP1_292569767", + "JP1_310138781", + "JP1_300507433", + "JP1_283568774", + // `individualPosition` is set but `teamPosition` is empty due to AFK slightly after beginning: + "JP1_285797147", +]; 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| e.to_string())?.ok_or(format!("Match {} not found.", 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."); @@ -28,10 +44,12 @@ async_tests!{ 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| e.to_string())?.ok_or(format!("Match timeline {} not found.", 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_eq!(matche[(matche.find('_').unwrap() + 1)..], format!("{}", m.info.game_id), "Match number ID should match."); + 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(())