197 lines
6.0 KiB
Rust
197 lines
6.0 KiB
Rust
use super::*;
|
|
|
|
#[test]
|
|
fn a_2nd_place_is_a_win_that_leaves_the_champion_remaining() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = imported_tracker(dir.path(), &[played_match(11, 2, jan(2, 0))]);
|
|
|
|
let stats = stats(&tracker, S1, None);
|
|
|
|
let yi = row(&stats, 11);
|
|
assert_eq!(yi.state, Some(ChampionState::InProgress));
|
|
let challenge = yi.challenge.unwrap();
|
|
assert_eq!(
|
|
(challenge.matches, challenge.wins, challenge.best_placement),
|
|
(1, 1, Some(2))
|
|
);
|
|
assert_eq!(challenge.completed_on, None);
|
|
assert_eq!(
|
|
challenge.marks(),
|
|
Marks {
|
|
played: true,
|
|
won: true,
|
|
completed: false
|
|
}
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_single_top_1_earns_the_three_marks() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = imported_tracker(dir.path(), &[played_match(11, 1, jan(2, 5))]);
|
|
|
|
let stats = stats(&tracker, S1, None);
|
|
|
|
let yi = row(&stats, 11);
|
|
assert_eq!(yi.state, Some(ChampionState::Completed));
|
|
assert_eq!(yi.attempts, Some(1));
|
|
let challenge = yi.challenge.unwrap();
|
|
assert_eq!(challenge.completed_on, Some(date(2026, 1, 2)));
|
|
assert_eq!(
|
|
challenge.marks(),
|
|
Marks {
|
|
played: true,
|
|
won: true,
|
|
completed: true
|
|
}
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_played_champion_without_a_win_has_only_the_first_mark() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = imported_tracker(dir.path(), &run(11, &[5, 4], jan(2, 0)));
|
|
|
|
let stats = stats(&tracker, S1, None);
|
|
|
|
let challenge = challenge(&stats, 11);
|
|
assert_eq!((challenge.matches, challenge.wins), (2, 0));
|
|
assert_eq!(challenge.best_placement, Some(4));
|
|
assert_eq!(
|
|
challenge.marks(),
|
|
Marks {
|
|
played: true,
|
|
won: false,
|
|
completed: false
|
|
}
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_never_played_champion_has_a_zeroed_challenge_and_no_marks() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = imported_tracker(dir.path(), &run(11, &[1], jan(2, 0)));
|
|
|
|
let stats = stats(&tracker, S1, None);
|
|
|
|
let unplayed = challenge(&stats, 8);
|
|
assert_eq!(
|
|
unplayed,
|
|
ChampionChallenge {
|
|
matches: 0,
|
|
wins: 0,
|
|
best_placement: None,
|
|
completed_on: None
|
|
}
|
|
);
|
|
assert_eq!(unplayed.marks(), NO_MARKS);
|
|
}
|
|
|
|
#[test]
|
|
fn the_all_seasons_view_has_no_champion_challenge() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = imported_tracker(dir.path(), &run(11, &[1], jan(2, 0)));
|
|
|
|
let stats = all_seasons(&tracker);
|
|
|
|
assert!(stats.rows.iter().all(|r| r.challenge.is_none()));
|
|
}
|
|
|
|
#[test]
|
|
fn the_format_filter_changes_the_columns_but_not_the_champion_challenge() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let matches = vec![
|
|
played_match(11, 4, jan(2, 1)),
|
|
played_match(11, 1, jan(2, 2)).in_format(1740),
|
|
played_match(11, 2, jan(2, 3)),
|
|
played_match(222, 3, jan(2, 4)).in_format(1740),
|
|
];
|
|
let tracker = imported_tracker(dir.path(), &matches);
|
|
|
|
let everything = stats(&tracker, S1, None);
|
|
let only_3x6 = stats(&tracker, S1, Some(Format::from_queue(1750).unwrap()));
|
|
|
|
let challenges =
|
|
|stats: &Statistics| -> Vec<_> { stats.rows.iter().map(|r| r.challenge).collect() };
|
|
assert_eq!(challenges(&everything), challenges(&only_3x6));
|
|
let yi = challenge(&only_3x6, 11);
|
|
assert_eq!((yi.matches, yi.wins, yi.best_placement), (3, 2, Some(1)));
|
|
assert_eq!(yi.completed_on, Some(date(2026, 1, 2)));
|
|
assert_eq!(challenge(&only_3x6, 222).matches, 1);
|
|
// The Format-scoped columns do change.
|
|
assert_eq!(row(&everything, 11).matches, 3);
|
|
assert_eq!(row(&only_3x6, 11).matches, 2);
|
|
assert_eq!(row(&only_3x6, 11).best_placement, Some(2));
|
|
assert_eq!(row(&only_3x6, 222).matches, 0);
|
|
}
|
|
|
|
#[test]
|
|
fn the_champion_challenge_follows_the_season() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let matches = [
|
|
run(11, &[1, 2], jan(2, 0)),
|
|
run(11, &[6], at(date(2026, 4, 2), 0)),
|
|
]
|
|
.concat();
|
|
let tracker = imported_tracker(dir.path(), &matches);
|
|
|
|
let past = challenge(&stats(&tracker, S1, None), 11);
|
|
let current = challenge(&stats(&tracker, S2, None), 11);
|
|
|
|
assert_eq!((past.matches, past.wins), (2, 2));
|
|
assert_eq!(past.completed_on, Some(date(2026, 1, 2)));
|
|
assert_eq!(
|
|
current,
|
|
ChampionChallenge {
|
|
matches: 1,
|
|
wins: 0,
|
|
best_placement: Some(6),
|
|
completed_on: None
|
|
}
|
|
);
|
|
assert!(!current.marks().won);
|
|
}
|
|
|
|
#[test]
|
|
fn the_champion_challenge_follows_the_account() {
|
|
const OTHER_PUUID: &str = "fixture-puuid-other";
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let other = Account {
|
|
puuid: OTHER_PUUID.into(),
|
|
game_name: "Autre".into(),
|
|
tag_line: "FIX".into(),
|
|
};
|
|
let theirs = played_by(
|
|
&payload("EUW1_theirs", 1750, 11, "MasterYi", 1, true, jan(3, 0)),
|
|
OTHER_PUUID,
|
|
);
|
|
let history = FakeHistory::new(
|
|
recorded_account(),
|
|
payloads(&[played_match(11, 4, jan(2, 0))]),
|
|
)
|
|
.with_account(other, vec![theirs]);
|
|
let tracker = Tracker::open(&dir.path().join("arena.db"), Box::new(history))
|
|
.unwrap()
|
|
.with_seasons(seasons())
|
|
.with_champions(
|
|
Box::new(FakeChampions::new("1.0", &CATALOG)),
|
|
dir.path().join("portraits"),
|
|
);
|
|
tracker.refresh_champions().unwrap();
|
|
tracker.sync(RIOT_ID, &mut |_| {}).unwrap();
|
|
tracker.sync("Autre#FIX", &mut |_| {}).unwrap();
|
|
let scope = Scope {
|
|
season: SeasonScope::Season(S1.into()),
|
|
format: None,
|
|
};
|
|
|
|
let mine = tracker.statistics(SELF_PUUID, &scope).unwrap();
|
|
let theirs = tracker.statistics(OTHER_PUUID, &scope).unwrap();
|
|
|
|
let mine = challenge(&mine, 11);
|
|
assert_eq!((mine.matches, mine.wins, mine.completed_on), (1, 0, None));
|
|
let theirs = challenge(&theirs, 11);
|
|
assert_eq!(theirs.matches, 1);
|
|
assert_eq!(theirs.completed_on, Some(date(2026, 1, 3)));
|
|
}
|