- The recap draws six augment slots per player, like the seven item slots: the augments taken, then empty slots, so the lines read in columns; the name moves to the bubble. - The catalog takes CommunityDragon's large augment icon (coloured by rarity) instead of the small white glyph, shrunk to 64 px at download. - catalog.json gets a format number: a cache from before is read again from the sources at the same patch and its augment icons downloaded again. - A first download tells the page every 100 icons, so icons show as they come instead of after the whole pass. - The icon download tests move to tests/game_data/icons.rs (Rule #2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0192He3BEKJ9v922udzup4Qn
396 lines
15 KiB
Rust
396 lines
15 KiB
Rust
mod common;
|
|
|
|
use arena_tracker_core::{Error, GameData, SourceError};
|
|
use common::{
|
|
FakeCatalog, RECORDED_ITEMS, RECORDED_VERSION, VERSIONS_URL, arena_url, augments_url, icon_png,
|
|
item_icon_url, items_url,
|
|
};
|
|
use serde_json::Value;
|
|
|
|
const RABADON_ICON: &str = "https://ddragon.leagueoflegends.com/cdn/16.23.1/img/item/3089.png";
|
|
const ADAPT_ICON: &str = "https://raw.communitydragon.org/16.23/plugins/rcp-be-lol-game-data/global/default/assets/ux/cherry/augments/icons/adapt_large.png";
|
|
/// Six items and nine augments, each with an icon.
|
|
const ICONS: usize = 15;
|
|
|
|
#[path = "game_data/icons.rs"]
|
|
mod icons;
|
|
|
|
/// Refreshes and counts the changes the caller was told of.
|
|
fn refresh(data: &GameData, source: &FakeCatalog) -> Result<usize, Error> {
|
|
let mut changes = 0;
|
|
data.refresh(source, &mut || changes += 1)?;
|
|
Ok(changes)
|
|
}
|
|
|
|
fn filled() -> (tempfile::TempDir, GameData, FakeCatalog) {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let data = GameData::new(dir.path().join("game-data"));
|
|
let source = FakeCatalog::recorded();
|
|
refresh(&data, &source).unwrap();
|
|
source.forget_asked();
|
|
(dir, data, source)
|
|
}
|
|
|
|
#[test]
|
|
fn the_catalog_is_filled_in_french_with_its_icons() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let data = GameData::new(dir.path().join("game-data"));
|
|
let source = FakeCatalog::recorded();
|
|
assert!(data.load().is_empty());
|
|
|
|
// Told once the names are stored, and once the icons are.
|
|
assert_eq!(refresh(&data, &source).unwrap(), 2);
|
|
|
|
let catalog = data.load();
|
|
assert_eq!(catalog.version.as_deref(), Some(RECORDED_VERSION));
|
|
assert_eq!(catalog.item_display(3089).name, "Coiffe de Rabadon");
|
|
assert_eq!(catalog.item_display(443055).name, "Fulmination");
|
|
assert_eq!(catalog.augment_display(1205).name, "Adaptation");
|
|
assert_eq!(catalog.augment_display(93).name, "Échauffement");
|
|
let augment = catalog.augment(1205).unwrap();
|
|
assert_eq!(augment.name_id, "ARAM_ADAPt");
|
|
assert_eq!(augment.rarity.as_deref(), Some("kSilver"));
|
|
assert_eq!(catalog.augment(1327).unwrap().name_id, "Adamant");
|
|
|
|
let item_icon = catalog.item_display(3089).icon.unwrap();
|
|
assert_eq!(std::fs::read(item_icon).unwrap(), icon_png(RABADON_ICON));
|
|
let augment_icon = catalog.augment_display(1205).icon.unwrap();
|
|
assert_eq!(std::fs::read(augment_icon).unwrap(), icon_png(ADAPT_ICON));
|
|
assert_eq!(source.icons_asked().len(), ICONS);
|
|
assert_eq!(
|
|
source.asked()[..4],
|
|
[
|
|
VERSIONS_URL.to_owned(),
|
|
augments_url("16.23"),
|
|
arena_url("16.23"),
|
|
items_url("16.23.1"),
|
|
]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn the_catalog_keeps_the_raw_descriptions_for_the_bubbles() {
|
|
let (dir, _, _) = filled();
|
|
let file = std::fs::read(dir.path().join("game-data/catalog.json")).unwrap();
|
|
let stored: Value = serde_json::from_slice(&file).unwrap();
|
|
let item = |id| {
|
|
(stored["items"].as_array().unwrap().iter())
|
|
.find(|i| i["id"] == id)
|
|
.unwrap()
|
|
};
|
|
let augment = |id| {
|
|
(stored["augments"].as_array().unwrap().iter())
|
|
.find(|a| a["id"] == id)
|
|
.unwrap()
|
|
};
|
|
assert!(
|
|
item(3089)["description"]
|
|
.as_str()
|
|
.unwrap()
|
|
.starts_with("<mainText>")
|
|
);
|
|
assert!(
|
|
item(222524)["description"]
|
|
.as_str()
|
|
.unwrap()
|
|
.contains("0 sec")
|
|
);
|
|
assert!(
|
|
augment(93)["summary"]
|
|
.as_str()
|
|
.unwrap()
|
|
.contains("@MaxStacks@%")
|
|
);
|
|
assert_eq!(augment(93)["values"]["MaxStacks"][3], 60.0);
|
|
assert!(
|
|
augment(214)["summary"]
|
|
.as_str()
|
|
.unwrap()
|
|
.contains("@SpinDamageAmp*100@")
|
|
);
|
|
assert_eq!(augment(323)["values"]["APRatio"], serde_json::json!([0.0]));
|
|
assert_eq!(augment(1205)["summary"], "");
|
|
assert_eq!(augment(1205)["values"], serde_json::json!({}));
|
|
}
|
|
|
|
#[test]
|
|
fn load_prepares_the_texts_of_the_bubbles() {
|
|
let (_dir, data, _) = filled();
|
|
let catalog = data.load();
|
|
assert_eq!(
|
|
catalog.item_display(3089).description.as_deref(),
|
|
Some("+130\u{a0}puissance\n\nOpus magique\nVous augmentez votre puissance totale de 30%.")
|
|
);
|
|
assert!(
|
|
(catalog.item_display(222524).description.unwrap()).contains("pendant ? sec"),
|
|
"a value the game computes is never 0"
|
|
);
|
|
let echauffement = catalog.augment_display(93).description.unwrap();
|
|
assert!(
|
|
echauffement.ends_with("(jusqu'à 20% max)."),
|
|
"{echauffement}"
|
|
);
|
|
// No entry in CommunityDragon's arena file, and an id nobody knows.
|
|
assert_eq!(catalog.augment_display(1205).description, None);
|
|
assert_eq!(catalog.augment_display(9_999_999).description, None);
|
|
assert_eq!(catalog.item_display(9_999_999).description, None);
|
|
}
|
|
|
|
#[test]
|
|
fn the_same_version_asks_only_for_the_versions() {
|
|
let (_dir, data, source) = filled();
|
|
|
|
assert_eq!(refresh(&data, &source).unwrap(), 0);
|
|
assert_eq!(source.asked(), [VERSIONS_URL]);
|
|
}
|
|
|
|
#[test]
|
|
fn a_cache_missing_a_usable_list_is_repaired_even_at_the_same_version() {
|
|
let (dir, data, source) = filled();
|
|
let path = dir.path().join("game-data/catalog.json");
|
|
let original: Value = serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();
|
|
for (list, field) in [
|
|
("items", "name"),
|
|
("augments", "name"),
|
|
("augments", "summary"),
|
|
] {
|
|
let mut damaged = original.clone();
|
|
for entry in damaged[list].as_array_mut().unwrap() {
|
|
entry[field] = "".into();
|
|
}
|
|
std::fs::write(&path, serde_json::to_vec(&damaged).unwrap()).unwrap();
|
|
|
|
assert_eq!(refresh(&data, &source).unwrap(), 1, "{list}.{field}");
|
|
let repaired: Value = serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();
|
|
assert_eq!(repaired, original);
|
|
assert!(source.icons_asked().is_empty());
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_new_version_renews_the_names_and_fetches_only_the_new_or_renamed_icons() {
|
|
let (_dir, data, source) = filled();
|
|
|
|
// The next patch renames an item, gives another one a new picture and adds one.
|
|
let mut list: Value = serde_json::from_str(RECORDED_ITEMS).unwrap();
|
|
list["data"]["3089"]["name"] = "Coiffe de Rabadon (corrigée)".into();
|
|
list["data"]["1001"]["image"]["full"] = "1001_v2.png".into();
|
|
list["data"]["1337"] = serde_json::json!({
|
|
"name": "Nouvel objet", "description": "<mainText>Neuf</mainText>", "image": {"full": "1337.png"}
|
|
});
|
|
source.publish_data_dragon("16.24.1", &list.to_string());
|
|
source.publish_community_dragon("16.24");
|
|
|
|
assert_eq!(refresh(&data, &source).unwrap(), 2);
|
|
let catalog = data.load();
|
|
assert_eq!(catalog.version.as_deref(), Some("16.24.1"));
|
|
assert_eq!(
|
|
catalog.item_display(3089).name,
|
|
"Coiffe de Rabadon (corrigée)"
|
|
);
|
|
assert_eq!(catalog.item_display(1337).name, "Nouvel objet");
|
|
assert_eq!(
|
|
source.icons_asked(),
|
|
[
|
|
item_icon_url("16.24.1", "1001_v2.png"),
|
|
item_icon_url("16.24.1", "1337.png"),
|
|
]
|
|
);
|
|
let moved = std::fs::read(catalog.item_display(1001).icon.unwrap()).unwrap();
|
|
assert_eq!(moved, icon_png(&item_icon_url("16.24.1", "1001_v2.png")));
|
|
// The unchanged icons are kept, from the previous version.
|
|
let kept = std::fs::read(catalog.item_display(3089).icon.unwrap()).unwrap();
|
|
assert_eq!(kept, icon_png(RABADON_ICON));
|
|
assert!(catalog.augment_display(1205).icon.is_some());
|
|
}
|
|
|
|
#[test]
|
|
fn communitydragon_behind_a_patch_keeps_the_old_catalog_and_the_next_check_retries() {
|
|
let (_dir, data, source) = filled();
|
|
source.publish_data_dragon("16.24.1", RECORDED_ITEMS);
|
|
|
|
// CommunityDragon answers 404 for patch 16.24: nothing is written, not even the items.
|
|
assert!(matches!(refresh(&data, &source), Err(Error::Source(_))));
|
|
let catalog = data.load();
|
|
assert_eq!(catalog.version.as_deref(), Some(RECORDED_VERSION));
|
|
assert_eq!(catalog.augment_display(1205).name, "Adaptation");
|
|
assert!(
|
|
catalog
|
|
.item_display(3089)
|
|
.icon
|
|
.is_some_and(|path| path.is_file())
|
|
);
|
|
assert!(
|
|
catalog
|
|
.augment_display(1205)
|
|
.icon
|
|
.is_some_and(|path| path.is_file())
|
|
);
|
|
assert!(source.icons_asked().is_empty());
|
|
assert!(
|
|
!source.asked().contains(&items_url("16.24.1")),
|
|
"the big items list is not downloaded for nothing"
|
|
);
|
|
|
|
// CommunityDragon catches up: the next check goes through.
|
|
source.publish_community_dragon("16.24");
|
|
assert_eq!(
|
|
refresh(&data, &source).unwrap(),
|
|
1,
|
|
"the names; every icon is kept"
|
|
);
|
|
assert_eq!(data.load().version.as_deref(), Some("16.24.1"));
|
|
}
|
|
|
|
#[test]
|
|
fn a_source_that_fails_or_answers_nonsense_leaves_the_old_catalog_whole() {
|
|
let (_dir, data, source) = filled();
|
|
source.publish_data_dragon("16.24.1", RECORDED_ITEMS);
|
|
source.publish_community_dragon("16.24");
|
|
let step = |source: &FakeCatalog| {
|
|
assert!(matches!(refresh(&data, source), Err(Error::Source(_))));
|
|
let catalog = data.load();
|
|
assert_eq!(catalog.version.as_deref(), Some(RECORDED_VERSION));
|
|
assert_eq!(catalog.item_display(3089).name, "Coiffe de Rabadon");
|
|
assert_eq!(catalog.augment_display(93).name, "Échauffement");
|
|
assert!(catalog.augment_display(93).description.is_some());
|
|
};
|
|
|
|
source.fail(&arena_url("16.24"), SourceError::Network("coupé".into()));
|
|
step(&source);
|
|
source.fail(&arena_url("16.24"), SourceError::Other("HTTP 500".into()));
|
|
step(&source);
|
|
source.serve(&arena_url("16.24"), "pas du JSON");
|
|
step(&source);
|
|
source.serve(&arena_url("16.24"), r#"{"augments":[{}]}"#);
|
|
step(&source);
|
|
source.serve(
|
|
&arena_url("16.24"),
|
|
r#"{"augments":[{"id":93,"desc":" "}]}"#,
|
|
);
|
|
step(&source);
|
|
source.serve(
|
|
&arena_url("16.24"),
|
|
r#"{"augments":[{"id":424242,"desc":"Autre"}]}"#,
|
|
);
|
|
step(&source);
|
|
source.publish_community_dragon("16.24");
|
|
source.serve(&augments_url("16.24"), "[]");
|
|
step(&source);
|
|
source.publish_community_dragon("16.24");
|
|
source.serve(&items_url("16.24.1"), r#"{"data": {}}"#);
|
|
step(&source);
|
|
source.fail(VERSIONS_URL, SourceError::Network("coupé".into()));
|
|
step(&source);
|
|
}
|
|
|
|
#[test]
|
|
fn a_patch_with_nameless_items_or_augments_is_retried_without_replacing_the_catalog() {
|
|
let (dir, data, source) = filled();
|
|
let path = dir.path().join("game-data/catalog.json");
|
|
let old = std::fs::read(&path).unwrap();
|
|
source.publish_community_dragon("16.24");
|
|
source.publish_data_dragon("16.24.1", r#"{"data":{"1":{}}}"#);
|
|
|
|
assert!(matches!(refresh(&data, &source), Err(Error::Source(_))));
|
|
assert_eq!(std::fs::read(&path).unwrap(), old);
|
|
|
|
// One name among unnamed entries is not enough either.
|
|
source.publish_data_dragon(
|
|
"16.24.1",
|
|
r#"{"data":{"1":{"name":"Bottes"},"2":{},"3":{"name":" "}}}"#,
|
|
);
|
|
assert!(matches!(refresh(&data, &source), Err(Error::Source(_))));
|
|
assert_eq!(std::fs::read(&path).unwrap(), old);
|
|
|
|
source.publish_data_dragon("16.24.1", RECORDED_ITEMS);
|
|
source.serve(&augments_url("16.24"), r#"[{"id":93,"nameTRA":" "}]"#);
|
|
assert!(matches!(refresh(&data, &source), Err(Error::Source(_))));
|
|
assert_eq!(std::fs::read(&path).unwrap(), old);
|
|
source.serve(
|
|
&augments_url("16.24"),
|
|
r#"[{"id":93,"nameTRA":"Échauffement"},{"id":94,"nameTRA":""}]"#,
|
|
);
|
|
assert!(matches!(refresh(&data, &source), Err(Error::Source(_))));
|
|
assert_eq!(std::fs::read(&path).unwrap(), old);
|
|
assert!(source.icons_asked().is_empty());
|
|
|
|
source.publish_community_dragon("16.24");
|
|
assert_eq!(refresh(&data, &source).unwrap(), 1);
|
|
assert_eq!(data.load().version.as_deref(), Some("16.24.1"));
|
|
}
|
|
|
|
#[test]
|
|
fn an_unknown_id_gets_the_neutral_icon_and_name() {
|
|
let (_dir, data, _) = filled();
|
|
let catalog = data.load();
|
|
|
|
assert_eq!(catalog.item_display(9_999_999).name, "Objet 9999999");
|
|
assert_eq!(catalog.item_display(9_999_999).icon, None);
|
|
assert_eq!(catalog.augment_display(424_242).name, "Amélioration 424242");
|
|
assert_eq!(catalog.augment_display(424_242).icon, None);
|
|
assert_eq!(catalog.augment(424_242), None);
|
|
}
|
|
|
|
#[test]
|
|
fn offline_with_no_catalog_keeps_the_neutral_names() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let data = GameData::new(dir.path().to_owned());
|
|
let source = FakeCatalog::recorded();
|
|
source.lose_network_after(0);
|
|
|
|
assert!(matches!(refresh(&data, &source), Err(Error::Source(_))));
|
|
let catalog = data.load();
|
|
assert!(catalog.is_empty());
|
|
assert_eq!(catalog.item_display(3089).name, "Objet 3089");
|
|
assert_eq!(catalog.augment_display(1205).icon, None);
|
|
}
|
|
|
|
#[test]
|
|
fn a_cache_that_cannot_be_read_is_rebuilt() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
std::fs::write(dir.path().join("catalog.json"), "{ not json").unwrap();
|
|
let data = GameData::new(dir.path().to_owned());
|
|
assert!(data.load().is_empty());
|
|
|
|
refresh(&data, &FakeCatalog::recorded()).unwrap();
|
|
assert_eq!(data.load().item_display(1001).name, "Bottes");
|
|
}
|
|
|
|
#[test]
|
|
fn a_cache_made_from_the_client_still_loads_and_is_replaced() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let old = r#"{"version": "16.22.719.8541", "locale": "en_US", "icons_complete": true,
|
|
"items": [{"id": 3089, "name": "Rabadon's Deathcap",
|
|
"icon": "/lol-game-data/assets/ASSETS/Items/Icons2D/3089_Mage_T3_Deathcap.png"}],
|
|
"augments": [{"id": 1205, "name_id": "ARAM_ADAPt", "name": "Adapt", "rarity": "kSilver",
|
|
"icon": "/lol-game-data/assets/ASSETS/UX/Cherry/Augments/Icons/ADAPt_small.png"}]}"#;
|
|
std::fs::write(dir.path().join("catalog.json"), old).unwrap();
|
|
std::fs::create_dir(dir.path().join("items")).unwrap();
|
|
std::fs::write(dir.path().join("items/3089.png"), "\u{89}PNG old").unwrap();
|
|
let data = GameData::new(dir.path().to_owned());
|
|
assert_eq!(data.load().item_display(3089).name, "Rabadon's Deathcap");
|
|
|
|
refresh(&data, &FakeCatalog::recorded()).unwrap();
|
|
|
|
let catalog = data.load();
|
|
assert_eq!(catalog.version.as_deref(), Some(RECORDED_VERSION));
|
|
assert_eq!(catalog.item_display(3089).name, "Coiffe de Rabadon");
|
|
let icon = std::fs::read(catalog.item_display(3089).icon.unwrap()).unwrap();
|
|
assert_eq!(
|
|
icon,
|
|
icon_png(RABADON_ICON),
|
|
"the client's picture was dropped"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn the_augment_name_id_matches_the_death_recap_events_in_both_sources() {
|
|
let (_dir, data, _) = filled();
|
|
let catalog = data.load();
|
|
|
|
// The ids and names the Death Recap matches on, as CommunityDragon spells them.
|
|
assert_eq!(catalog.augment(93).unwrap().name_id, "WarmupRoutine");
|
|
assert_eq!(catalog.augment(2087).unwrap().name_id, "ARAM_Archmage");
|
|
}
|