test: update tests and documentation for removal of summoner names

val_queue
Mingwei Samuel 2024-04-10 15:26:17 -07:00
parent ce439b881e
commit d8b04b5c86
7 changed files with 62 additions and 41 deletions

View File

@ -35,18 +35,25 @@ rt.block_on(async {
let api_key = std::env!("RGAPI_KEY"); // "RGAPI-01234567-89ab-cdef-0123-456789abcdef"; let api_key = std::env!("RGAPI_KEY"); // "RGAPI-01234567-89ab-cdef-0123-456789abcdef";
let riot_api = RiotApi::new(api_key); let riot_api = RiotApi::new(api_key);
// Get summoner data. // The region.
let summoner = riot_api.summoner_v4() let platform = PlatformRoute::NA1;
.get_by_summoner_name(PlatformRoute::NA1, "잘 못").await
// Get account data.
let account = riot_api.account_v1()
.get_by_riot_id(platform.to_regional(), "잘 못", "NA1").await
.expect("Get summoner failed.") .expect("Get summoner failed.")
.expect("There is no summoner with that name."); .expect("There is no summoner with that name.");
// Print summoner name. // Print account name#tag.
println!("{} Champion Masteries:", summoner.name); println!(
"{}#{} Champion Masteries:",
account.game_name.unwrap_or_default(),
account.tag_line.unwrap_or_default(),
);
// Get champion mastery data. // Get champion mastery data.
let masteries = riot_api.champion_mastery_v4() let masteries = riot_api.champion_mastery_v4()
.get_all_champion_masteries_by_puuid(PlatformRoute::NA1, &summoner.puuid).await .get_all_champion_masteries_by_puuid(platform, &account.puuid).await
.expect("Get champion masteries failed."); .expect("Get champion masteries failed.");
// Print champion masteries. // Print champion masteries.

View File

@ -47,18 +47,25 @@
//! let api_key = std::env!("RGAPI_KEY"); // "RGAPI-01234567-89ab-cdef-0123-456789abcdef"; //! let api_key = std::env!("RGAPI_KEY"); // "RGAPI-01234567-89ab-cdef-0123-456789abcdef";
//! let riot_api = RiotApi::new(api_key); //! let riot_api = RiotApi::new(api_key);
//! //!
//! // Get summoner data. //! // The region.
//! let summoner = riot_api.summoner_v4() //! let platform = PlatformRoute::NA1;
//! .get_by_summoner_name(PlatformRoute::NA1, "잘 못").await //!
//! // Get account data.
//! let account = riot_api.account_v1()
//! .get_by_riot_id(platform.to_regional(), "잘 못", "NA1").await
//! .expect("Get summoner failed.") //! .expect("Get summoner failed.")
//! .expect("There is no summoner with that name."); //! .expect("There is no summoner with that name.");
//! //!
//! // Print summoner name. //! // Print account name#tag.
//! println!("{} Champion Masteries:", summoner.name); //! println!(
//! "{}#{} Champion Masteries:",
//! account.game_name.unwrap_or_default(),
//! account.tag_line.unwrap_or_default(),
//! );
//! //!
//! // Get champion mastery data. //! // Get champion mastery data.
//! let masteries = riot_api.champion_mastery_v4() //! let masteries = riot_api.champion_mastery_v4()
//! .get_all_champion_masteries_by_puuid(PlatformRoute::NA1, &summoner.puuid).await //! .get_all_champion_masteries_by_puuid(platform, &account.puuid).await
//! .expect("Get champion masteries failed."); //! .expect("Get champion masteries failed.");
//! //!
//! // Print champion masteries. //! // Print champion masteries.

View File

@ -30,7 +30,7 @@ async fn summoner_get_kanjikana() -> Result<(), String> {
.await .await
.map_err(|e| e.to_string())? .map_err(|e| e.to_string())?
.ok_or_else(|| "Failed to get myheadhard".to_owned())?; .ok_or_else(|| "Failed to get myheadhard".to_owned())?;
rassert_eq!("私の頭がかたい", s.name); rassert!(0 < s.puuid.len());
Ok(()) Ok(())
} }

View File

@ -85,10 +85,7 @@ async fn tft_combo() -> Result<(), String> {
.tft_summoner_v1() .tft_summoner_v1()
.get_by_summoner_id(ROUTE, &top_player_entry.summoner_id); .get_by_summoner_id(ROUTE, &top_player_entry.summoner_id);
let top_player = top_player.await.map_err(|e| e.to_string())?; let top_player = top_player.await.map_err(|e| e.to_string())?;
println!( println!("Top player has `puuid` {}.", top_player.puuid);
"Top player is {} with `puuid` {}.",
top_player.name, top_player.puuid
);
let match_ids = riot_api().tft_match_v1().get_match_ids_by_puuid( let match_ids = riot_api().tft_match_v1().get_match_ids_by_puuid(
ROUTE.to_regional(), ROUTE.to_regional(),
&top_player.puuid, &top_player.puuid,

View File

@ -4,14 +4,9 @@ use riven::models::summoner_v4::*;
use testutils::*; use testutils::*;
fn validate_summoners(s1: Summoner, s2: Summoner) -> Result<(), String> { fn validate_summoners(s1: Summoner, s2: Summoner) -> Result<(), String> {
rassert_eq!(s1.name, s2.name, "Names didn't match {}.", ""); rassert_eq!(s1.puuid, s2.puuid, "PUUIDs didn't match.");
rassert_eq!(s1.id, s2.id, "SummonerId didn't match {}.", ""); rassert_eq!(s1.id, s2.id, "Summoner IDs didn't match.");
rassert_eq!( rassert_eq!(s1.account_id, s2.account_id, "Account IDs didn't match.");
s1.account_id,
s2.account_id,
"AccountId didn't match {}.",
""
);
Ok(()) Ok(())
} }

View File

@ -1,7 +1,7 @@
mod testutils; mod testutils;
use futures::future::join_all; use futures::future::join_all;
use riven::consts::*; use riven::consts::*;
use riven::models::summoner_v4::Summoner;
use testutils::*; use testutils::*;
const ROUTE: PlatformRoute = PlatformRoute::TR1; const ROUTE: PlatformRoute = PlatformRoute::TR1;
@ -19,16 +19,29 @@ async fn league_summoner_bulk_test() -> Result<(), String> {
league_list.entries.len() league_list.entries.len()
); );
let summoner_vec = join_all(league_list.entries.iter().take(50).map(|entry| { let summoner_vec = join_all(league_list.entries.iter().take(50).map(|entry| async move {
riot_api() let summoner = riot_api()
.summoner_v4() .summoner_v4()
.get_by_summoner_id(ROUTE, &entry.summoner_id) .get_by_summoner_id(ROUTE, &entry.summoner_id)
.await?;
let account = riot_api()
.account_v1()
.get_by_puuid(ROUTE.to_regional(), &summoner.puuid)
.await;
Ok(account)
})) }))
.await; .await;
for (i, s) in summoner_vec.into_iter().enumerate() { for (i, s) in summoner_vec.into_iter().enumerate() {
let summoner: Summoner = s.map_err(|e| e.to_string())?; let account = s
println!("{}: {}", i + 1, summoner.name); .and_then(std::convert::identity)
.map_err(|e| e.to_string())?;
println!(
"{}: {}#{}",
i + 1,
account.game_name.unwrap_or_default(),
account.tag_line.unwrap_or_default(),
);
} }
Ok(()) Ok(())

View File

@ -292,7 +292,9 @@ pub async fn match_v5_get_timeline(
pub async fn spectator_v5_combo(route: PlatformRoute) -> Result<(), String> { pub async fn spectator_v5_combo(route: PlatformRoute) -> Result<(), String> {
let featured_p = riot_api().spectator_v5().get_featured_games(route); let featured_p = riot_api().spectator_v5().get_featured_games(route);
let featured = featured_p.await.map_err(|e| e.to_string())?; let featured = featured_p
.await
.map_err(|e| format!("Failed to fetch featured games: {}", e))?;
if featured.game_list.is_empty() { if featured.game_list.is_empty() {
eprintln!("Featured game list is empty!"); eprintln!("Featured game list is empty!");
@ -303,8 +305,8 @@ pub async fn spectator_v5_combo(route: PlatformRoute) -> Result<(), String> {
let participant = &featured_game.participants[0]; let participant = &featured_game.participants[0];
let puuid = participant.puuid.as_ref().ok_or_else(|| { let puuid = participant.puuid.as_ref().ok_or_else(|| {
format!( format!(
"Summoner in spectator featured game {} missing summoner ID: {}", "Summoner in spectator featured game {} missing summoner ID. PUUID: {:?}",
featured_game.game_id, &participant.summoner_name, featured_game.game_id, participant.puuid,
) )
})?; })?;
@ -321,11 +323,11 @@ pub async fn spectator_v5_combo(route: PlatformRoute) -> Result<(), String> {
let participant_match = livegame let participant_match = livegame
.participants .participants
.iter() .iter()
.find(|p| p.summoner_name == participant.summoner_name); .find(|p| p.puuid == participant.puuid);
rassert!( rassert!(
participant_match.is_some(), participant_match.is_some(),
"Failed to find summoner in match: {}.", "Failed to find summoner in match with PUUID: {:?}.",
&participant.summoner_name participant.puuid
); );
} }
Ok(()) Ok(())
@ -344,8 +346,8 @@ pub async fn spectator_tft_v5_combo(route: PlatformRoute) -> Result<(), String>
let participant = &featured_game.participants[0]; let participant = &featured_game.participants[0];
let puuid = participant.puuid.as_ref().ok_or_else(|| { let puuid = participant.puuid.as_ref().ok_or_else(|| {
format!( format!(
"Summoner in spectator featured game {} missing summoner ID: {}", "Summoner in spectator featured game {} missing summoner ID. PUUID: {:?}",
featured_game.game_id, &participant.summoner_name, featured_game.game_id, participant.puuid,
) )
})?; })?;
@ -362,11 +364,11 @@ pub async fn spectator_tft_v5_combo(route: PlatformRoute) -> Result<(), String>
let participant_match = livegame let participant_match = livegame
.participants .participants
.iter() .iter()
.find(|p| p.summoner_name == participant.summoner_name); .find(|p| p.puuid == participant.puuid);
rassert!( rassert!(
participant_match.is_some(), participant_match.is_some(),
"Failed to find summoner in match: {}.", "Failed to find summoner in match with PUUID: {:?}.",
&participant.summoner_name participant.puuid
); );
} }
Ok(()) Ok(())