From d43ba94222583223195438ea99073ed4cd972c0e Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Thu, 14 Mar 2024 23:26:05 -0700 Subject: [PATCH] Move spectator tests into testutils, add `spectator-tft-v5` tests --- riven/tests/tests_euw.rs | 78 ++++------------------------ riven/tests/testutils.rs | 108 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 69 deletions(-) diff --git a/riven/tests/tests_euw.rs b/riven/tests/tests_euw.rs index 63c8b49..9dccf5e 100644 --- a/riven/tests/tests_euw.rs +++ b/riven/tests/tests_euw.rs @@ -50,77 +50,17 @@ async fn championmastery_getall_ma5tery() -> Result<(), String> { Ok(()) } -/// https://github.com/RiotGames/developer-relations/issues/602 #[riven_test] -async fn spectator_v4_combo() -> Result<(), String> { - let featured_p = riot_api().spectator_v4().get_featured_games(ROUTE); - let featured = featured_p.await.map_err(|e| e.to_string())?; - - if featured.game_list.is_empty() { - eprintln!("Featured game list is empty!"); - return Ok(()); - } - - let featured_game = &featured.game_list[0]; - let participant = &featured_game.participants[0]; - let summoner_id = participant.summoner_id.as_ref().ok_or_else(|| { - format!( - "Summoner in spectator featured game missing summoner ID: {}", - &participant.summoner_name - ) - })?; - - let livegame_p = riot_api() - .spectator_v4() - .get_current_game_info_by_summoner(ROUTE, &summoner_id); - let livegame_o = livegame_p.await.map_err(|e| e.to_string())?; - if let Some(livegame) = livegame_o { - let participant_match = livegame - .participants - .iter() - .find(|p| p.summoner_name == participant.summoner_name); - rassert!( - participant_match.is_some(), - "Failed to find summoner in match: {}.", - &participant.summoner_name - ); - } - Ok(()) +async fn spectator_v4_combo_test() -> Result<(), String> { + spectator_v4_combo(ROUTE).await } #[riven_test] -async fn spectator_v5_combo() -> Result<(), String> { - let featured_p = riot_api().spectator_v5().get_featured_games(ROUTE); - let featured = featured_p.await.map_err(|e| e.to_string())?; - - if featured.game_list.is_empty() { - eprintln!("Featured game list is empty!"); - return Ok(()); - } - - let featured_game = &featured.game_list[0]; - let participant = &featured_game.participants[0]; - let puuid = participant.puuid.as_ref().ok_or_else(|| { - format!( - "Summoner in spectator featured game missing summoner ID: {}", - &participant.summoner_name - ) - })?; - - let livegame_p = riot_api() - .spectator_v5() - .get_current_game_info_by_puuid(ROUTE, &puuid); - let livegame_o = livegame_p.await.map_err(|e| e.to_string())?; - if let Some(livegame) = livegame_o { - let participant_match = livegame - .participants - .iter() - .find(|p| p.summoner_name == participant.summoner_name); - rassert!( - participant_match.is_some(), - "Failed to find summoner in match: {}.", - &participant.summoner_name - ); - } - Ok(()) +async fn spectator_v5_combo_test() -> Result<(), String> { + spectator_v5_combo(ROUTE).await +} + +#[riven_test] +async fn spectator_tft_v5_combo_test() -> Result<(), String> { + spectator_tft_v5_combo(ROUTE).await } diff --git a/riven/tests/testutils.rs b/riven/tests/testutils.rs index fd1f5b4..791995a 100644 --- a/riven/tests/testutils.rs +++ b/riven/tests/testutils.rs @@ -290,6 +290,114 @@ pub async fn match_v5_get_timeline( join_all_future_errs(futures).await } +pub async fn spectator_v4_combo(route: PlatformRoute) -> Result<(), String> { + let featured_p = riot_api().spectator_v4().get_featured_games(route); + let featured = featured_p.await.map_err(|e| e.to_string())?; + + if featured.game_list.is_empty() { + eprintln!("Featured game list is empty!"); + return Ok(()); + } + + let featured_game = &featured.game_list[0]; + let participant = &featured_game.participants[0]; + let summoner_id = participant.summoner_id.as_ref().ok_or_else(|| { + format!( + "Summoner in spectator featured game missing summoner ID: {}", + &participant.summoner_name + ) + })?; + + let livegame_p = riot_api() + .spectator_v4() + .get_current_game_info_by_summoner(route, &summoner_id); + let livegame_o = livegame_p.await.map_err(|e| e.to_string())?; + if let Some(livegame) = livegame_o { + let participant_match = livegame + .participants + .iter() + .find(|p| p.summoner_name == participant.summoner_name); + rassert!( + participant_match.is_some(), + "Failed to find summoner in match: {}.", + &participant.summoner_name + ); + } + Ok(()) +} + +pub async fn spectator_v5_combo(route: PlatformRoute) -> Result<(), String> { + let featured_p = riot_api().spectator_v5().get_featured_games(route); + let featured = featured_p.await.map_err(|e| e.to_string())?; + + if featured.game_list.is_empty() { + eprintln!("Featured game list is empty!"); + return Ok(()); + } + + let featured_game = &featured.game_list[0]; + let participant = &featured_game.participants[0]; + let puuid = participant.puuid.as_ref().ok_or_else(|| { + format!( + "Summoner in spectator featured game missing summoner ID: {}", + &participant.summoner_name + ) + })?; + + let livegame_p = riot_api() + .spectator_v5() + .get_current_game_info_by_puuid(route, &puuid); + let livegame_o = livegame_p.await.map_err(|e| e.to_string())?; + if let Some(livegame) = livegame_o { + let participant_match = livegame + .participants + .iter() + .find(|p| p.summoner_name == participant.summoner_name); + rassert!( + participant_match.is_some(), + "Failed to find summoner in match: {}.", + &participant.summoner_name + ); + } + Ok(()) +} + +pub async fn spectator_tft_v5_combo(route: PlatformRoute) -> Result<(), String> { + let featured_p = riot_api().spectator_tft_v5().get_featured_games(route); + let featured = featured_p.await.map_err(|e| e.to_string())?; + + if featured.game_list.is_empty() { + eprintln!("Featured game list is empty!"); + return Ok(()); + } + + let featured_game = &featured.game_list[0]; + let participant = &featured_game.participants[0]; + let puuid = participant.puuid.as_ref().ok_or_else(|| { + format!( + "Summoner in spectator featured game missing summoner ID: {}", + &participant.summoner_name + ) + })?; + + let livegame_p = riot_api() + .spectator_tft_v5() + .get_current_game_info_by_puuid(route, &puuid); + let livegame_o = livegame_p.await.map_err(|e| e.to_string())?; + if let Some(livegame) = livegame_o { + let participant_match = livegame + .participants + .iter() + .find(|p| p.summoner_name == participant.summoner_name); + rassert!( + participant_match.is_some(), + "Failed to find summoner in match: {}.", + &participant.summoner_name + ); + } + Ok(()) +} + /// Joins all futures and keeps ALL error messages, separated by newlines. async fn join_all_future_errs( result_tasks: impl Iterator>>,