A. The fixture's game id is the synthetic one every fixture uses; the test no longer rewrites it. B. The decoder tries the key names verified on the capture first, the other spellings after. C. The synthetic end-of-game blocks use the real block's shape: PUUID only, no names, the real key spellings. The Riot-ID fallback test adds the names to its own block. D. The captured-block follow test states that the fixture's player is the client's PUUID. E. The recap of a Provisional Match flags the player with the Match's champion and Placement, not every player on that champion; a test covers a champion played by two teams. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
119 lines
4.1 KiB
Rust
119 lines
4.1 KiB
Rust
use super::*;
|
|
|
|
pub const SELF_PUUID: &str = "fixture-puuid-self";
|
|
|
|
const BASE: &str = include_str!("../fixtures/riot/match_1750_EUW1_9000000006.json");
|
|
|
|
/// The six recorded Riot payloads.
|
|
pub fn recorded_matches() -> Vec<String> {
|
|
[
|
|
include_str!("../fixtures/riot/match_1700_EUW1_9000000001.json"),
|
|
include_str!("../fixtures/riot/match_1700_EUW1_9000000002.json"),
|
|
include_str!("../fixtures/riot/match_1740_EUW1_9000000004.json"),
|
|
include_str!("../fixtures/riot/match_1740_EUW1_9000000005.json"),
|
|
include_str!("../fixtures/riot/match_1750_EUW1_9000000003.json"),
|
|
include_str!("../fixtures/riot/match_1750_EUW1_9000000006.json"),
|
|
]
|
|
.map(String::from)
|
|
.to_vec()
|
|
}
|
|
|
|
pub fn recorded_account() -> Account {
|
|
serde_json::from_str(include_str!("../fixtures/riot/account.json")).unwrap()
|
|
}
|
|
|
|
/// A payload cloned from a recorded one, with the self participant patched.
|
|
pub fn payload(
|
|
match_id: &str,
|
|
queue_id: u32,
|
|
champion_id: u32,
|
|
champion_name: &str,
|
|
placement: u8,
|
|
win: bool,
|
|
started_at_ms: i64,
|
|
) -> String {
|
|
let mut v: Value = serde_json::from_str(BASE).unwrap();
|
|
v["metadata"]["matchId"] = match_id.into();
|
|
v["info"]["queueId"] = queue_id.into();
|
|
v["info"]["gameStartTimestamp"] = started_at_ms.into();
|
|
let me = v["info"]["participants"]
|
|
.as_array_mut()
|
|
.unwrap()
|
|
.iter_mut()
|
|
.find(|p| p["puuid"] == SELF_PUUID)
|
|
.unwrap();
|
|
me["championId"] = champion_id.into();
|
|
me["championName"] = champion_name.into();
|
|
me["placement"] = placement.into();
|
|
me["win"] = win.into();
|
|
v.to_string()
|
|
}
|
|
|
|
pub fn with_game_mode(payload: &str, game_mode: &str) -> String {
|
|
let mut v: Value = serde_json::from_str(payload).unwrap();
|
|
v["info"]["gameMode"] = game_mode.into();
|
|
v.to_string()
|
|
}
|
|
|
|
/// The payload with these fields missing from every participant but the Account.
|
|
pub fn without_fields_for_others(payload: &str, fields: &[&str]) -> String {
|
|
let mut v: Value = serde_json::from_str(payload).unwrap();
|
|
for p in v["info"]["participants"].as_array_mut().unwrap() {
|
|
if p["puuid"] != SELF_PUUID {
|
|
for field in fields {
|
|
p.as_object_mut().unwrap().remove(*field);
|
|
}
|
|
}
|
|
}
|
|
v.to_string()
|
|
}
|
|
|
|
pub fn played_by(payload: &str, puuid: &str) -> String {
|
|
payload.replace(SELF_PUUID, puuid)
|
|
}
|
|
|
|
/// The client's PUUID of the recorded Account, which is not the Riot API's.
|
|
pub const CLIENT_PUUID: &str = "client-puuid-self";
|
|
|
|
/// An end-of-game block of an Arena 3x6 game, shaped as the real one
|
|
/// (`fixtures/client/end_of_game_block_arena.json`): 18 players in 6 teams of 3, identified by
|
|
/// PUUID only, the signed-in player (`CLIENT_PUUID`) playing `champion` in the team placed
|
|
/// `standing`.
|
|
pub fn end_of_game_block(game_id: u64, champion: u32, standing: u8) -> String {
|
|
let mut others = (1..=6u8).filter(|&p| p != standing);
|
|
let placements: Vec<u8> = (0..6)
|
|
.map(|team| match team {
|
|
0 => standing,
|
|
_ => others.next().unwrap(),
|
|
})
|
|
.collect();
|
|
let players: Vec<Value> = (0..18u32)
|
|
.map(|i| {
|
|
let team = i / 3;
|
|
let mine = i == 0;
|
|
serde_json::json!({
|
|
"PUUID": if mine { CLIENT_PUUID.to_string() } else { format!("client-puuid-{i}") },
|
|
"championId": if mine { champion } else { 500 + i },
|
|
"subteamId": team + 1,
|
|
"subteamStanding": placements[team as usize],
|
|
"championLevel": 15,
|
|
"playerKills": i,
|
|
"playerDeaths": 2,
|
|
"playerAssists": 3,
|
|
"goldEarned": 10_000,
|
|
"itemIds": [3031, 0, 0, 0, 0, 0, 3340],
|
|
"augmentPlatformIds": [1, 2, 3],
|
|
"damageDealtToChampions": 1000 * (i + 1),
|
|
"damageTaken": 2000,
|
|
})
|
|
})
|
|
.collect();
|
|
serde_json::json!({
|
|
"gameId": game_id,
|
|
"gameMode": "CHERRY",
|
|
"queueId": 1750,
|
|
"statsBlock": {"gameLengthSeconds": 1200, "players": players},
|
|
})
|
|
.to_string()
|
|
}
|