Add test to fetch latest matches from JP

This commit is contained in:
Mingwei Samuel 2023-03-20 21:35:53 -07:00
parent d05b068bb8
commit 32fe532f07
3 changed files with 101 additions and 53 deletions

View file

@ -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
},
}
}

View file

@ -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
},
}
}

View file

@ -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<str>]) -> 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<String> = 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<Item = impl AsRef<str>>,
) -> 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<str>])
Ok(())
}
pub async fn match_v5_get(route: RegionalRoute, matches: &[impl AsRef<str>]) -> Result<(), String> {
let futures = matches.iter().map(|matche| async move {
pub async fn match_v5_get(
route: RegionalRoute,
matches: impl IntoIterator<Item = impl AsRef<str>>,
) -> 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<str>]) ->
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<str>]) ->
pub async fn match_v5_get_timeline(
route: RegionalRoute,
matches: &[impl AsRef<str>],
matches: impl IntoIterator<Item = impl AsRef<str>>,
) -> 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