diff --git a/riven/tests/tests_asia.rs b/riven/tests/tests_asia.rs deleted file mode 100644 index d5c5a60..0000000 --- a/riven/tests/tests_asia.rs +++ /dev/null @@ -1,44 +0,0 @@ -#![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::ASIA; - -static MATCHES: &[&str] = &[ - // 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", - // Illegal big `championId`s. https://github.com/RiotGames/developer-relations/issues/553 - "JP1_267647303", - "JP1_273343663", -]; - -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/tests_jp.rs b/riven/tests/tests_asia_jp.rs similarity index 76% rename from riven/tests/tests_jp.rs rename to riven/tests/tests_asia_jp.rs index 7281ee0..423b3a0 100644 --- a/riven/tests/tests_jp.rs +++ b/riven/tests/tests_asia_jp.rs @@ -11,7 +11,28 @@ use riven::consts::*; const ROUTE: PlatformRoute = PlatformRoute::JP1; -async_tests!{ +static MATCHES: &[&str] = &[ + // 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", + // Illegal big `championId`s. https://github.com/RiotGames/developer-relations/issues/553 + "JP1_267647303", + "JP1_273343663", +]; + +async_tests! { my_runner { // Summoner tests. summoner_get_kanjikana: async { @@ -68,5 +89,16 @@ async_tests!{ rassert!(!lr.is_empty()); Ok(()) }, + + // ASIA regional tests + league_v4_match_v5_latest_combo: async { + league_v4_match_v5_latest_combo(ROUTE).await + }, + match_v5_get: async { + match_v5_get(ROUTE.to_regional(), MATCHES).await + }, + match_v5_get_timeline: async { + match_v5_get_timeline(ROUTE.to_regional(), MATCHES).await + }, } } diff --git a/riven/tests/testutils.rs b/riven/tests/testutils.rs index 3757dbc..fa4ab16 100644 --- a/riven/tests/testutils.rs +++ b/riven/tests/testutils.rs @@ -2,7 +2,7 @@ use lazy_static::lazy_static; -use riven::consts::RegionalRoute; +use riven::consts::{PlatformRoute, QueueType, RegionalRoute}; use riven::{RiotApi, RiotApiConfig}; lazy_static! { @@ -15,8 +15,63 @@ lazy_static! { }; } -pub async fn tft_match_v1_get(route: RegionalRoute, matches: &[impl AsRef]) -> Result<(), String> { - let futures = matches.iter().map(|matche| async move { +pub async fn league_v4_match_v5_latest_combo(route: PlatformRoute) -> Result<(), String> { + const NUM_MATCHES: usize = 10; + + let challenger_future = RIOT_API + .league_v4() + .get_challenger_league(route, QueueType::RANKED_SOLO_5x5); + let challenger_league = challenger_future.await.map_err(|e| e.to_string())?; + + if &QueueType::RANKED_SOLO_5x5 != &challenger_league.queue { + return Err(format!("Unexpected `queue`: {}", challenger_league.queue)); + } + if challenger_league.entries.is_empty() { + return Err("Challenger league is unexpectedly empty!".to_owned()); + } + + let match_ids_futures = challenger_league + .entries + .iter() + .take(5) + .map(|entry| async move { + let summoner_future = RIOT_API + .summoner_v4() + .get_by_summoner_id(route, &entry.summoner_id); + let summoner_info = summoner_future.await.map_err(|e| e.to_string())?; + + let match_ids_future = RIOT_API.match_v5().get_match_ids_by_puuid( + route.to_regional(), + &*summoner_info.puuid, + Some(5), + None, + None, + None, + None, + None, + ); + let match_ids = match_ids_future.await.map_err(|e| e.to_string())?; + Ok(match_ids) as Result<_, String> + }); + + let match_ids = futures::future::try_join_all(match_ids_futures).await?; + + let mut match_ids: Vec = match_ids.into_iter().flatten().collect(); + match_ids.sort_unstable_by(|a, b| a.cmp(b).reverse()); // Sort descending, so latest are first. + + let _ = tokio::try_join!( + match_v5_get(route.to_regional(), match_ids.iter().take(NUM_MATCHES)), + match_v5_get_timeline(route.to_regional(), match_ids.iter().take(NUM_MATCHES)), + )?; + + Ok(()) +} + +pub async fn tft_match_v1_get( + route: RegionalRoute, + matches: impl IntoIterator>, +) -> Result<(), String> { + let futures = matches.into_iter().map(|matche| async move { let matche = matche.as_ref(); let p = RIOT_API.tft_match_v1().get_match(route, matche); let m = p @@ -45,8 +100,11 @@ pub async fn tft_match_v1_get(route: RegionalRoute, matches: &[impl AsRef]) Ok(()) } -pub async fn match_v5_get(route: RegionalRoute, matches: &[impl AsRef]) -> Result<(), String> { - let futures = matches.iter().map(|matche| async move { +pub async fn match_v5_get( + route: RegionalRoute, + matches: impl IntoIterator>, +) -> Result<(), String> { + let futures = matches.into_iter().map(|matche| async move { let matche = matche.as_ref(); let p = RIOT_API.match_v5().get_match(route, matche); let m = p @@ -67,7 +125,9 @@ pub async fn match_v5_get(route: RegionalRoute, matches: &[impl AsRef]) -> return Err("Match participants do not line up with participant UUIDs.".to_owned()); } for participant in &m.info.participants { - participant.champion().map_err(|e| format!("Failed to determine champion: {}", e))?; + participant + .champion() + .map_err(|e| format!("Failed to determine champion: {}", e))?; } if m.info.teams.is_empty() { return Err("Match should have teams.".to_owned()); @@ -80,9 +140,9 @@ pub async fn match_v5_get(route: RegionalRoute, matches: &[impl AsRef]) -> pub async fn match_v5_get_timeline( route: RegionalRoute, - matches: &[impl AsRef], + matches: impl IntoIterator>, ) -> Result<(), String> { - let futures = matches.iter().map(|matche| async move { + let futures = matches.into_iter().map(|matche| async move { let matche = matche.as_ref(); let p = RIOT_API.match_v5().get_timeline(route, matche); let m = p