Regen for match-v5.ParticipantDto optionals, consolidate/add match tests w/ invalid champion IDs

This commit is contained in:
Mingwei Samuel 2021-12-29 09:35:09 -08:00
parent c07efb1087
commit de1e5cdbca
7 changed files with 113 additions and 53 deletions

View file

@ -7,7 +7,7 @@
///////////////////////////////////////////////
// http://www.mingweisamuel.com/riotapi-schema/tool/
// Version 5998519c2eb30a8c3f88edf1dcf88e2c6f091ba1
// Version 517bb1adbfb393d65b8829b208ebe331bb6e73dc
//! Automatically generated endpoint handles.
#![allow(clippy::let_and_return, clippy::too_many_arguments)]

View file

@ -7,7 +7,7 @@
///////////////////////////////////////////////
// http://www.mingweisamuel.com/riotapi-schema/tool/
// Version 5998519c2eb30a8c3f88edf1dcf88e2c6f091ba1
// Version 517bb1adbfb393d65b8829b208ebe331bb6e73dc
//! Metadata about the Riot API and Riven.
//!

View file

@ -7,7 +7,7 @@
///////////////////////////////////////////////
// http://www.mingweisamuel.com/riotapi-schema/tool/
// Version 5998519c2eb30a8c3f88edf1dcf88e2c6f091ba1
// Version 517bb1adbfb393d65b8829b208ebe331bb6e73dc
//! Data transfer structs.
//!
@ -831,7 +831,8 @@ pub mod match_v5 {
#[serde(rename = "consumablesPurchased")]
pub consumables_purchased: i32,
#[serde(rename = "damageDealtToBuildings")]
pub damage_dealt_to_buildings: i32,
#[serde(skip_serializing_if = "Option::is_none")]
pub damage_dealt_to_buildings: Option<i32>,
#[serde(rename = "damageDealtToObjectives")]
pub damage_dealt_to_objectives: i32,
#[serde(rename = "damageDealtToTurrets")]
@ -871,7 +872,8 @@ pub mod match_v5 {
#[serde(skip_serializing_if = "Option::is_none")]
pub inhibitor_takedowns: Option<i32>,
#[serde(rename = "inhibitorsLost")]
pub inhibitors_lost: i32,
#[serde(skip_serializing_if = "Option::is_none")]
pub inhibitors_lost: Option<i32>,
#[serde(rename = "item0")]
pub item0: i32,
#[serde(rename = "item1")]
@ -916,7 +918,8 @@ pub mod match_v5 {
#[serde(skip_serializing_if = "Option::is_none")]
pub nexus_takedowns: Option<i32>,
#[serde(rename = "nexusLost")]
pub nexus_lost: i32,
#[serde(skip_serializing_if = "Option::is_none")]
pub nexus_lost: Option<i32>,
#[serde(rename = "objectivesStolen")]
pub objectives_stolen: i32,
#[serde(rename = "objectivesStolenAssists")]
@ -1014,7 +1017,8 @@ pub mod match_v5 {
#[serde(skip_serializing_if = "Option::is_none")]
pub turret_takedowns: Option<i32>,
#[serde(rename = "turretsLost")]
pub turrets_lost: i32,
#[serde(skip_serializing_if = "Option::is_none")]
pub turrets_lost: Option<i32>,
#[serde(rename = "unrealKills")]
pub unreal_kills: i32,
#[serde(rename = "visionScore")]

View file

@ -12,7 +12,7 @@ use riven::models::tournament_stub_v4::*;
const ROUTE: RegionalRoute = RegionalRoute::AMERICAS;
static MATCHES: [&str; 5] = [
static MATCHES: &[&str] = &[
"NA1_3923487226",
"NA1_4049206905",
"NA1_4052515784",
@ -69,27 +69,10 @@ async_tests!{
},
match_v5_get: async {
for matche in MATCHES {
let p = RIOT_API.match_v5().get_match(ROUTE, matche);
let m = p.await.map_err(|e| format!("Failed to get match {}: {:?}", matche, e))?.ok_or(format!("Match {} not found.", matche))?;
rassert_eq!(matche, m.metadata.match_id, "Bad match id? Sent {}, received {}.", matche, m.metadata.match_id);
rassert!(!m.metadata.participants.is_empty(), "Match should have participants.");
rassert!(!m.info.teams.is_empty(), "Match should have teams.");
}
Ok(())
match_v5_get(ROUTE, MATCHES).await
},
match_v5_get_timeline: async {
for matche in MATCHES {
let p = RIOT_API.match_v5().get_timeline(ROUTE, matche);
let m = p.await.map_err(|e| format!("Failed to get match {}: {:?}", matche, e))?.ok_or(format!("Match {} not found.", matche))?;
rassert_eq!(matche, m.metadata.match_id, "Bad match id? Sent {}, received {}.", matche, m.metadata.match_id);
rassert!(!m.metadata.participants.is_empty(), "Match should have participants.");
if let Some(game_id) = m.info.game_id {
rassert_eq!(matche[(matche.find('_').unwrap() + 1)..], format!("{}", game_id), "Match number ID should match.");
}
rassert!(!m.info.frames.is_empty(), "Match timleine should have frames.");
}
Ok(())
match_v5_get_timeline(ROUTE, MATCHES).await
},
}
}

View file

@ -11,7 +11,7 @@ use riven::consts::*;
const ROUTE: RegionalRoute = RegionalRoute::ASIA;
static MATCHES: [&str; 11] = [
static MATCHES: &[&str] = &[
// Regular game:
"KR_5495121707",
// `teamPosition` empty:
@ -27,32 +27,18 @@ static MATCHES: [&str; 11] = [
"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 {
for matche in MATCHES {
let p = RIOT_API.match_v5().get_match(ROUTE, matche);
let m = p.await.map_err(|e| format!("Failed to get match {}: {:?}", matche, e))?.ok_or(format!("Match {} not found.", matche))?;
rassert_eq!(matche, m.metadata.match_id, "Bad match id? Sent {}, received {}.", matche, m.metadata.match_id);
rassert!(!m.metadata.participants.is_empty(), "Match should have participants.");
rassert!(!m.info.teams.is_empty(), "Match should have teams.");
}
Ok(())
match_v5_get(ROUTE, MATCHES).await
},
match_v5_get_timeline: async {
for matche in MATCHES {
let p = RIOT_API.match_v5().get_timeline(ROUTE, matche);
let m = p.await.map_err(|e| format!("Failed to get match {}: {:?}", matche, e))?.ok_or(format!("Match {} not found.", matche))?;
rassert_eq!(matche, m.metadata.match_id, "Bad match id? Sent {}, received {}.", matche, m.metadata.match_id);
rassert!(!m.metadata.participants.is_empty(), "Match should have participants.");
if let Some(game_id) = m.info.game_id {
rassert_eq!(matche[(matche.find('_').unwrap() + 1)..], format!("{}", game_id), "Match number ID should match.");
}
rassert!(!m.info.frames.is_empty(), "Match timleine should have frames.");
}
Ok(())
match_v5_get_timeline(ROUTE, MATCHES).await
},
}
}

View file

@ -0,0 +1,30 @@
#![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::EUROPE;
static MATCHES: &[&str] = &[
// Illegal big `championId`s. https://github.com/RiotGames/developer-relations/issues/553
"EUW1_5097684633",
"EUW1_5097963383",
"EUW1_5102203800", // https://github.com/MingweiSamuel/Riven/issues/36
];
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

@ -2,11 +2,13 @@
use lazy_static::lazy_static;
use riven::consts::RegionalRoute;
use riven::{RiotApi, RiotApiConfig};
lazy_static! {
pub static ref RIOT_API: RiotApi = {
let api_key = std::env::var("RGAPI_KEY").ok()
let api_key = std::env::var("RGAPI_KEY")
.ok()
.or_else(|| std::fs::read_to_string("apikey.txt").ok())
.expect("Failed to find RGAPI_KEY env var or apikey.txt.");
RiotApi::new(RiotApiConfig::with_key(api_key.trim()).preconfig_burst())
@ -20,3 +22,58 @@ pub mod ids {
pub const ACCOUNT_ID_C9SNEAKY: &str = "ML_CcLT94UUHp1iDvXOXCidfmzzPrk_Jbub1f_INhw";
pub const ACCOUNT_ID_LUGNUTSK: &str = "iheZF2uJ50S84Hfq6Ob8GNlJAUmBmac-EsEEWBJjD01q1jQ";
}
pub async fn match_v5_get(route: RegionalRoute, matches: &[&'static str]) -> Result<(), String> {
for &matche in matches {
let p = RIOT_API.match_v5().get_match(route, matche);
let m = p
.await
.map_err(|e| format!("Failed to get match {}: {:?}", matche, e))?
.ok_or(format!("Match {} not found.", matche))?;
if matche != &*m.metadata.match_id {
return Err(format!(
"Bad match id? Sent {}, received {}.",
matche, m.metadata.match_id
));
}
if m.metadata.participants.is_empty() {
return Err("Match should have participants.".to_owned());
}
if m.info.teams.is_empty() {
return Err("Match should have teams.".to_owned());
}
}
Ok(())
}
pub async fn match_v5_get_timeline(
route: RegionalRoute,
matches: &[&'static str],
) -> Result<(), String> {
for &matche in matches {
let p = RIOT_API.match_v5().get_timeline(route, matche);
let m = p
.await
.map_err(|e| format!("Failed to get match {}: {:?}", matche, e))?
.ok_or(format!("Match {} not found.", matche))?;
if matche != &*m.metadata.match_id {
return Err(format!(
"Bad match id? Sent {}, received {}.",
matche, m.metadata.match_id
));
}
if m.metadata.participants.is_empty() {
return Err("Match should have participants.".to_owned());
}
if let Some(game_id) = m.info.game_id {
if matche[(matche.find('_').unwrap() + 1)..] != game_id.to_string() {
return Err("Match number ID should match.".to_owned());
}
}
if m.info.frames.is_empty() {
return Err("Match timleine should have frames.".to_owned());
}
}
Ok(())
}