test: rearrange, add Valorant tests

This commit is contained in:
Mingwei Samuel 2024-04-20 20:46:24 -07:00
parent a3e1bb92cb
commit f6cb3397ff
3 changed files with 81 additions and 54 deletions

View file

@ -1,62 +1,12 @@
/// Non-match Valorant tests for LATAM.
mod testutils;
use riven::consts::*;
use testutils::{riot_api, riven_test, val_match_v1_latest};
use testutils::{riven_test, val_content_ranked};
const ROUTE: ValPlatformRoute = ValPlatformRoute::LATAM;
#[riven_test]
async fn val_content_ranked_test() -> Result<(), String> {
let p = riot_api()
.val_content_v1()
.get_content(ROUTE, Some("zh-CN"));
let contents = p
.await
.map_err(|e| format!("Failed to get content: {}", e))?;
// Find the LAST active act, via `.rev().find(...)`.
// Added filter when parent id is 0000... as there are multiple that are active, the last active seems to be episode 5
// Not sure if this a bandaid fix
let act = contents
.acts
.iter()
.rev()
.find(|act| {
act.is_active
&& act.parent_id != Some("00000000-0000-0000-0000-000000000000".to_string())
})
.ok_or(format!("No active acts of {} found.", contents.acts.len()))?;
println!("ACT {:?}", act);
let p = riot_api()
.val_ranked_v1()
.get_leaderboard(ROUTE, &act.id, None, None);
let leaderboard = p.await.map_err(|e| e.to_string())?.ok_or(format!(
"Failed to get act leaderboard {} {}.",
act.id, act.name
))?;
rassert_eq!(act.id, leaderboard.act_id);
for (i, p) in leaderboard.players.iter().take(10).enumerate() {
rassert_eq!(i + 1, p.leaderboard_rank as usize);
println!(
"{:>2}: {:>4} {:<22} ({} wins)",
p.leaderboard_rank,
p.ranked_rating,
format!(
"{}#{}",
p.game_name.as_deref().unwrap_or("<NONE>"),
p.tag_line.as_deref().unwrap_or("<NONE>")
),
p.number_of_wins
);
}
Ok(())
}
#[riven_test]
async fn val_match_v1_latest_test() -> Result<(), String> {
val_match_v1_latest(ROUTE).await
val_content_ranked(ROUTE).await
}

View file

@ -0,0 +1,25 @@
mod testutils;
use riven::consts::*;
use testutils::{riven_test, val_content_ranked, val_match_v1_get, val_match_v1_latest};
const ROUTE: ValPlatformRoute = ValPlatformRoute::NA;
static MATCHES: &[&str] = &[
"b979be9e-aeb1-419e-981d-d7d2472649a2",
"c086129c-e538-43cf-ae93-7148d0d01182",
];
#[riven_test]
async fn val_match_v1_get_test() -> Result<(), String> {
val_match_v1_get(ROUTE, MATCHES).await
}
#[riven_test]
async fn val_content_ranked_test() -> Result<(), String> {
val_content_ranked(ROUTE).await
}
#[riven_test]
async fn val_match_v1_latest_test() -> Result<(), String> {
val_match_v1_latest(ROUTE).await
}

View file

@ -380,6 +380,58 @@ pub async fn spectator_tft_v5_combo(route: PlatformRoute) -> Result<(), String>
Ok(())
}
/// Test getting a ranked leaderboard.
pub async fn val_content_ranked(route: ValPlatformRoute) -> Result<(), String> {
let p = riot_api()
.val_content_v1()
.get_content(route, Some("zh-CN")); // Idk
let contents = p
.await
.map_err(|e| format!("Failed to get content: {}", e))?;
// Find the LAST active act, via `.rev().find(...)`.
// Added filter when parent id is 0000... as there are multiple that are active, the last active seems to be episode 5
// Not sure if this a bandaid fix
let act = contents
.acts
.iter()
.rev()
.find(|act| {
act.is_active
&& act.parent_id != Some("00000000-0000-0000-0000-000000000000".to_string())
})
.ok_or(format!("No active acts of {} found.", contents.acts.len()))?;
println!("ACT {:?}", act);
let p = riot_api()
.val_ranked_v1()
.get_leaderboard(route, &act.id, None, None);
let leaderboard = p.await.map_err(|e| e.to_string())?.ok_or(format!(
"Failed to get act leaderboard {} {}.",
act.id, act.name
))?;
rassert_eq!(act.id, leaderboard.act_id);
for (i, p) in leaderboard.players.iter().take(10).enumerate() {
rassert_eq!(i + 1, p.leaderboard_rank as usize);
println!(
"{:>2}: {:>4} {:<22} ({} wins)",
p.leaderboard_rank,
p.ranked_rating,
format!(
"{}#{}",
p.game_name.as_deref().unwrap_or("<NONE>"),
p.tag_line.as_deref().unwrap_or("<NONE>")
),
p.number_of_wins
);
}
Ok(())
}
/// Get recent Challenger matches and check that they parse as valid.
pub async fn val_match_v1_latest(route: ValPlatformRoute) -> Result<(), String> {
// Val rate limits are super low.