Riven/riven/tests/tests_na.rs

128 lines
3.7 KiB
Rust
Raw Normal View History

2021-06-30 23:34:34 +00:00
mod testutils;
use riven::consts::*;
use riven::models::summoner_v4::*;
2024-01-21 03:41:46 +00:00
use testutils::*;
2021-06-30 23:34:34 +00:00
fn validate_summoners(s1: Summoner, s2: Summoner) -> Result<(), String> {
rassert_eq!(s1.name, s2.name, "Names didn't match {}.", "");
rassert_eq!(s1.id, s2.id, "SummonerId didn't match {}.", "");
2023-05-10 18:20:15 +00:00
rassert_eq!(
s1.account_id,
s2.account_id,
"AccountId didn't match {}.",
""
);
2021-06-30 23:34:34 +00:00
Ok(())
}
const ROUTE: PlatformRoute = PlatformRoute::NA1;
// Summoner tests.
2024-02-25 04:50:00 +00:00
#[riven_test]
async fn summoner_double() -> Result<(), String> {
let l1p = riot_api()
.summoner_v4()
.get_by_summoner_name(ROUTE, "lug nuts k");
let l2p = riot_api()
.summoner_v4()
.get_by_summoner_name(ROUTE, "lugnuts k");
let l1 = l1p
.await
.map_err(|e| e.to_string())?
.ok_or_else(|| "'lug nuts k' not found!".to_owned())?;
let l2 = l2p
.await
.map_err(|e| e.to_string())?
.ok_or_else(|| "'lugnuts k' not found!".to_owned())?;
validate_summoners(l1, l2)?;
Ok(())
}
2024-02-25 04:50:00 +00:00
#[riven_test]
async fn champion_getrotation() -> Result<(), String> {
let p = riot_api().champion_v3().get_champion_info(ROUTE);
let d = p.await.map_err(|e| e.to_string())?;
let new_len = d.free_champion_ids_for_new_players.len();
let free_len = d.free_champion_ids.len();
let level = d.max_new_player_level;
rassert!(new_len >= 10, "New len: {}", new_len);
rassert!(free_len >= 15, "Free len: {}", free_len);
rassert_eq!(10, level, "New player level: {}", level);
Ok(())
}
2024-02-25 04:50:00 +00:00
#[riven_test]
async fn leagueexp_get() -> Result<(), String> {
let p = riot_api().league_exp_v4().get_league_entries(
ROUTE,
QueueType::RANKED_SOLO_5x5,
Tier::CHALLENGER,
Division::I,
None,
);
let d = p.await.map_err(|e| e.to_string())?;
if d.is_empty() {
eprintln!("Off-season, challenger league is empty.");
}
Ok(())
}
2021-06-30 23:34:34 +00:00
2024-02-25 04:50:00 +00:00
#[riven_test]
async fn champion_mastery_v4() -> Result<(), String> {
let summoner = riot_api()
.summoner_v4()
.get_by_summoner_name(ROUTE, "LugnutsK");
let summoner = summoner
.await
.map_err(|e| e.to_string())?
.ok_or_else(|| "'LugnutsK' not found!".to_owned())?;
let masteries = riot_api()
.champion_mastery_v4()
.get_all_champion_masteries_by_puuid(ROUTE, &summoner.puuid);
let masteries = masteries.await.map_err(|e| e.to_string())?;
rassert!(74 <= masteries.len());
Ok(())
}
// Commented out, requires special API key.
// /// LOR
2024-02-25 04:50:00 +00:00
// #[riven_test]
// async fn async fn lor_ranked_get_leaderboards() -> Result<(), String> {
// let future = riot_api().lor_ranked_v1().get_leaderboards(Region::AMERICAS);
// let _leaderboard = future.await.map_err(|e| e.to_string())?;
// Ok(())
// }
2021-06-30 23:34:34 +00:00
// CLASH
2024-02-25 04:50:00 +00:00
#[riven_test]
async fn clash_get_tournaments() -> Result<(), String> {
let p = riot_api().clash_v1().get_tournaments(ROUTE);
let tours = p.await.map_err(|e| e.to_string())?;
if let Some(tour0) = tours.first() {
let p = riot_api().clash_v1().get_tournament_by_id(ROUTE, tour0.id);
let tour1 = p.await.map_err(|e| e.to_string())?;
assert_eq!(Some(tour0.id), tour1.map(|t| t.id));
2021-06-30 23:34:34 +00:00
}
Ok(())
}
2024-02-25 04:50:00 +00:00
#[riven_test]
async fn clash_get_team_by_id_invalid() -> Result<(), String> {
let p = riot_api()
.clash_v1()
.get_team_by_id(ROUTE, "00000000-0000-0000-0000-000000000000");
let team = p.await.map_err(|e| e.to_string())?;
assert!(team.is_none());
Ok(())
}
2024-02-25 04:50:00 +00:00
#[riven_test]
async fn status() -> Result<(), String> {
let p = riot_api().lol_status_v4().get_platform_data(ROUTE);
let status = p.await.map_err(|e| e.to_string())?;
println!("{:?}", status);
Ok(())
2021-06-30 23:34:34 +00:00
}