191 lines
5.9 KiB
Rust
191 lines
5.9 KiB
Rust
use super::*;
|
|
|
|
#[test]
|
|
fn failures_during_a_round_are_recorded_and_stored_data_stays_readable() {
|
|
for (error, problem) in failures() {
|
|
let world = World::new(&s2_matches());
|
|
let tracker = world.tracker();
|
|
round(&tracker);
|
|
world.client.set_phase("InProgress", true);
|
|
round(&tracker);
|
|
world.history.fail_with(Some(error));
|
|
world.client.set_phase("EndOfGame", true);
|
|
|
|
assert!(round(&tracker), "{problem:?}");
|
|
|
|
assert_eq!(tracker.status().problem, Some(problem));
|
|
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2);
|
|
assert_eq!(completed(&tracker, SELF_PUUID), 1);
|
|
|
|
world.history.fail_with(None);
|
|
round(&tracker);
|
|
assert_eq!(tracker.status().problem, None);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn failures_during_a_refresh_are_returned_and_recorded() {
|
|
for (error, problem) in failures() {
|
|
let world = World::new(&s2_matches());
|
|
let tracker = world.tracker();
|
|
round(&tracker);
|
|
world.history.fail_with(Some(error));
|
|
|
|
let failed = tracker.refresh(&mut |_| {});
|
|
|
|
assert_eq!(failed.unwrap_err(), problem);
|
|
assert_eq!(tracker.status().problem, Some(problem));
|
|
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2);
|
|
assert_eq!(completed(&tracker, SELF_PUUID), 1);
|
|
|
|
world.history.fail_with(None);
|
|
assert!(tracker.refresh(&mut |_| {}).is_ok());
|
|
assert_eq!(tracker.status().problem, None);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_first_sync_that_failed_is_tried_again_a_minute_later() {
|
|
let world = World::new(&s2_matches());
|
|
world.history.fail_with(Some(SourceError::InvalidKey));
|
|
let tracker = world.tracker();
|
|
|
|
round(&tracker);
|
|
assert_eq!(tracker.status().problem, Some(UpdateProblem::InvalidKey));
|
|
assert_eq!(tracker.status().updating, None);
|
|
|
|
world.history.fail_with(None);
|
|
assert!(round_after(&tracker, 60_000));
|
|
|
|
assert_eq!(tracker.status().problem, None);
|
|
assert_eq!(tracker.status().updating, Some(recorded_account()));
|
|
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2);
|
|
}
|
|
|
|
#[test]
|
|
fn refreshing_with_no_account_known_is_a_problem() {
|
|
let world = World::new(&s2_matches());
|
|
let tracker = world.open();
|
|
|
|
assert_eq!(
|
|
tracker.refresh(&mut |_| {}).unwrap_err(),
|
|
UpdateProblem::NoAccount
|
|
);
|
|
assert_eq!(tracker.status().problem, Some(UpdateProblem::NoAccount));
|
|
}
|
|
|
|
#[test]
|
|
fn refreshing_at_launch_updates_the_last_active_account() {
|
|
let world = World::new(&s2_matches());
|
|
round(&world.tracker());
|
|
world.history.add(new_match("EUW1_next", 1));
|
|
|
|
let tracker = world.open();
|
|
let report = tracker.refresh(&mut |_| {}).unwrap();
|
|
|
|
assert_eq!((report.added, report.stored), (1, 3));
|
|
assert_eq!(tracker.status().updating, Some(recorded_account()));
|
|
}
|
|
|
|
#[test]
|
|
fn official_progress_agrees_when_the_counts_are_equal() {
|
|
let world = World::new(&top1_matches(52));
|
|
let tracker = world.tracker();
|
|
|
|
round(&tracker);
|
|
|
|
// 52 is what the real client reported.
|
|
assert_eq!(
|
|
tracker.status().official_progress,
|
|
ProgressCheck::Agrees(52)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn official_progress_differs_with_both_numbers_and_follows_later_syncs() {
|
|
let world = World::new(&top1_matches(50));
|
|
let tracker = world.tracker();
|
|
|
|
round(&tracker);
|
|
let differs = ProgressCheck::Differs {
|
|
app: 50,
|
|
official: 52,
|
|
};
|
|
assert_eq!(tracker.status().official_progress, differs);
|
|
|
|
world
|
|
.history
|
|
.add(new_match("EUW1_a", 1).replace("\"championId\":222", "\"championId\":2001"));
|
|
world
|
|
.history
|
|
.add(new_match("EUW1_b", 2).replace("\"championId\":222", "\"championId\":2002"));
|
|
tracker.refresh(&mut |_| {}).unwrap();
|
|
assert_eq!(
|
|
tracker.status().official_progress,
|
|
ProgressCheck::Agrees(52)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn official_progress_is_absent_without_a_reading() {
|
|
let world = World::new(&top1_matches(52));
|
|
let tracker = world.tracker();
|
|
round(&tracker);
|
|
assert_ne!(tracker.status().official_progress, ProgressCheck::Absent);
|
|
|
|
world.client.remove_track(S2_TRACK);
|
|
round(&tracker);
|
|
assert_eq!(tracker.status().official_progress, ProgressCheck::Absent);
|
|
|
|
world.client.set_track(S2_TRACK, 52);
|
|
round(&tracker);
|
|
assert_eq!(
|
|
tracker.status().official_progress,
|
|
ProgressCheck::Agrees(52)
|
|
);
|
|
|
|
world.client.sign_out();
|
|
round(&tracker);
|
|
assert_eq!(tracker.status().official_progress, ProgressCheck::Absent);
|
|
}
|
|
|
|
#[test]
|
|
fn official_progress_is_absent_when_the_season_has_no_track_or_there_is_no_season() {
|
|
let world = World::new(&top1_matches(52));
|
|
let tracker = world.tracker();
|
|
|
|
tracker.follow_client(at(date(2026, 1, 15), 0), None, &mut |_| {});
|
|
assert_eq!(tracker.status().official_progress, ProgressCheck::Absent);
|
|
|
|
tracker.follow_client(at(date(2025, 6, 1), 0), None, &mut |_| {});
|
|
assert_eq!(tracker.status().official_progress, ProgressCheck::Absent);
|
|
|
|
tracker.follow_client(now(), None, &mut |_| {});
|
|
assert_eq!(
|
|
tracker.status().official_progress,
|
|
ProgressCheck::Agrees(52)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn banners_point_to_the_parametres_screen_and_never_to_a_missing_field() {
|
|
let text = |p: UpdateProblem| p.message();
|
|
for problem in [UpdateProblem::MissingKey, UpdateProblem::InvalidKey] {
|
|
assert!(text(problem.clone()).contains("Paramètres"), "{problem:?}");
|
|
}
|
|
let no_account = text(UpdateProblem::NoAccount);
|
|
assert!(no_account.contains("League of Legends"), "{no_account}");
|
|
assert!(!no_account.contains("Riot ID"), "{no_account}");
|
|
for problem in [
|
|
UpdateProblem::MissingKey,
|
|
UpdateProblem::InvalidKey,
|
|
UpdateProblem::Network,
|
|
UpdateProblem::RateLimited,
|
|
UpdateProblem::NoAccount,
|
|
UpdateProblem::MatchPending,
|
|
UpdateProblem::Other("x".into()),
|
|
] {
|
|
assert!(!text(problem).contains("réglages"));
|
|
}
|
|
}
|