Group core integration tests by behavior (#102)
This commit is contained in:
1 parent
4548b6ac64
commit
c716c2c759
32 files changed
+4508
-4414
No files matched your search
@@ -0,0 +1,344 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_first_round_syncs_the_signed_in_account_and_makes_it_active() {
|
||||
let world = World::new(&s2_matches());
|
||||
let tracker = world.tracker();
|
||||
assert_eq!(tracker.status().updating, None);
|
||||
assert!(!tracker.status().client_running);
|
||||
|
||||
assert!(round(&tracker));
|
||||
|
||||
let status = tracker.status();
|
||||
assert!(status.client_running);
|
||||
assert_eq!(status.updating, Some(recorded_account()));
|
||||
assert_eq!(status.problem, None);
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2);
|
||||
|
||||
// Nothing changed: no visible change and no call to Riot, even if the client spells the
|
||||
// Riot ID differently.
|
||||
world.client.sign_in("joueur", "euw");
|
||||
let calls = world.source_calls();
|
||||
assert!(!round(&tracker));
|
||||
assert_eq!(world.source_calls(), calls);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn signing_in_to_another_account_switches_the_active_account() {
|
||||
let world = World::with_history(two_accounts());
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
assert_eq!(tracker.status().updating, Some(recorded_account()));
|
||||
|
||||
world.client.sign_in("Autre", "FIX");
|
||||
assert!(round(&tracker));
|
||||
|
||||
assert_eq!(tracker.status().updating, Some(other_account()));
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2);
|
||||
assert_eq!(tracker.match_count(OTHER_PUUID).unwrap(), 1);
|
||||
assert_eq!(completed(&tracker, SELF_PUUID), 1);
|
||||
assert_eq!(completed(&tracker, OTHER_PUUID), 0);
|
||||
|
||||
world.client.sign_in("Joueur", "EUW");
|
||||
round(&tracker);
|
||||
assert_eq!(tracker.status().updating, Some(recorded_account()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_the_client_the_first_round_catches_up_on_the_last_active_account() {
|
||||
let world = World::new(&s2_matches());
|
||||
round(&world.tracker());
|
||||
world.client.sign_out();
|
||||
world.history.add(new_match("EUW1_while_closed", 3));
|
||||
|
||||
let tracker = world.tracker();
|
||||
assert_eq!(
|
||||
tracker.last_active_account().unwrap(),
|
||||
Some(recorded_account())
|
||||
);
|
||||
assert!(round(&tracker));
|
||||
|
||||
let status = tracker.status();
|
||||
assert!(!status.client_running);
|
||||
assert_eq!(status.updating, Some(recorded_account()));
|
||||
assert_eq!(status.problem, None);
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_the_client_nor_any_known_account_there_is_nothing_to_update() {
|
||||
let world = World::new(&s2_matches());
|
||||
world.client.sign_out();
|
||||
let tracker = world.tracker();
|
||||
|
||||
assert!(round(&tracker));
|
||||
|
||||
let status = tracker.status();
|
||||
assert_eq!(
|
||||
(status.updating, status.problem),
|
||||
(None, Some(UpdateProblem::NoAccount))
|
||||
);
|
||||
assert_eq!(world.source_calls(), 0);
|
||||
// An empty Riot ID from the settings is no Riot ID.
|
||||
tracker.follow_client(now(), Some(" "), &mut |_| {});
|
||||
assert_eq!(tracker.status().problem, Some(UpdateProblem::NoAccount));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_configured_riot_id_is_the_fallback_when_nothing_else_is_known() {
|
||||
let world = World::new(&s2_matches());
|
||||
world.client.sign_out();
|
||||
let tracker = world.tracker();
|
||||
|
||||
assert!(tracker.follow_client(now(), Some("Joueur#EUW"), &mut |_| {}));
|
||||
|
||||
let status = tracker.status();
|
||||
assert_eq!(
|
||||
(status.updating, status.problem),
|
||||
(Some(recorded_account()), None)
|
||||
);
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2);
|
||||
assert_eq!(
|
||||
world.open().last_active_account().unwrap(),
|
||||
Some(recorded_account())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rounds_work_without_any_client() {
|
||||
let world = World::new(&s2_matches());
|
||||
let tracker = world.open();
|
||||
|
||||
tracker.follow_client(now(), Some("Joueur#EUW"), &mut |_| {});
|
||||
|
||||
assert!(!tracker.status().client_running);
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn when_the_client_stops_the_active_account_and_its_data_stay() {
|
||||
let world = World::new(&s2_matches());
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
world.client.sign_out();
|
||||
let calls = world.source_calls();
|
||||
|
||||
assert!(round(&tracker));
|
||||
|
||||
let status = tracker.status();
|
||||
assert!(!status.client_running);
|
||||
assert_eq!(status.updating, Some(recorded_account()));
|
||||
assert_eq!(status.official_progress, ProgressCheck::Absent);
|
||||
assert_eq!(world.source_calls(), calls);
|
||||
assert_eq!(completed(&tracker, SELF_PUUID), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unknown_riot_id_in_the_client_is_a_problem_not_a_crash() {
|
||||
let world = World::new(&s2_matches());
|
||||
world.client.sign_in("Inconnu", "XX");
|
||||
let tracker = world.tracker();
|
||||
|
||||
round(&tracker);
|
||||
|
||||
assert!(matches!(
|
||||
tracker.status().problem,
|
||||
Some(UpdateProblem::Other(_))
|
||||
));
|
||||
assert_eq!(tracker.status().updating, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failed_first_sight_of_another_account_does_not_keep_the_previous_one() {
|
||||
let world = World::with_history(
|
||||
FakeHistory::new(recorded_account(), payloads(&s2_matches()))
|
||||
.with_account(other_account(), vec![]),
|
||||
);
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
assert_eq!(tracker.status().updating, Some(recorded_account()));
|
||||
|
||||
// Never seen before, and Riot is down.
|
||||
world
|
||||
.history
|
||||
.fail_with(Some(SourceError::Network("coupé".into())));
|
||||
world.client.sign_in("Autre", "FIX");
|
||||
round(&tracker);
|
||||
assert_eq!(tracker.status().updating, None);
|
||||
assert_eq!(tracker.status().problem, Some(UpdateProblem::Network));
|
||||
play_arena_game(&world, &tracker);
|
||||
round(&tracker);
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2);
|
||||
|
||||
// Once seen, the stored Account stays shown while Riot is down.
|
||||
world.history.fail_with(None);
|
||||
world.client.set_phase("None", false);
|
||||
world.client.sign_in("Autre", "FIX");
|
||||
round(&tracker);
|
||||
assert_eq!(tracker.status().updating, Some(other_account()));
|
||||
world.client.sign_in("Joueur", "EUW");
|
||||
round(&tracker);
|
||||
world
|
||||
.history
|
||||
.fail_with(Some(SourceError::Network("coupé".into())));
|
||||
world.client.sign_in("Autre", "FIX");
|
||||
round(&tracker);
|
||||
assert_eq!(tracker.status().updating, Some(other_account()));
|
||||
assert_eq!(tracker.status().problem, Some(UpdateProblem::Network));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn signing_back_in_after_a_failed_switch_shows_that_account_again() {
|
||||
let world = World::with_history(two_accounts());
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
world
|
||||
.history
|
||||
.fail_with(Some(SourceError::Network("coupé".into())));
|
||||
world.client.sign_in("Autre", "FIX");
|
||||
round(&tracker);
|
||||
assert_eq!(tracker.status().updating, None);
|
||||
|
||||
world.client.sign_in("Joueur", "EUW");
|
||||
round(&tracker);
|
||||
|
||||
assert_eq!(tracker.status().updating, Some(recorded_account()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failing_adoption_is_tried_again_once_a_minute_not_on_every_client_event() {
|
||||
let world = World::new(&s2_matches());
|
||||
world.history.fail_with(Some(SourceError::InvalidKey));
|
||||
let tracker = world.tracker();
|
||||
|
||||
round(&tracker);
|
||||
for _ in 0..9 {
|
||||
round_after(&tracker, 0);
|
||||
}
|
||||
assert_eq!(world.source_calls(), 1);
|
||||
// The refresh button is not held back.
|
||||
let refreshed = tracker.refresh(&mut |_| {});
|
||||
assert_eq!(refreshed.unwrap_err(), UpdateProblem::InvalidKey);
|
||||
assert_eq!(world.source_calls(), 2);
|
||||
round_after(&tracker, 59_999);
|
||||
assert_eq!(world.source_calls(), 2);
|
||||
round_after(&tracker, 1);
|
||||
|
||||
assert_eq!(world.source_calls(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refresh_after_a_failed_first_sight_adopts_the_signed_in_account() {
|
||||
let world = World::with_history(two_accounts());
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
world.history.fail_with(Some(SourceError::InvalidKey));
|
||||
world.client.sign_in("Autre", "FIX");
|
||||
round(&tracker);
|
||||
assert_eq!(tracker.status().updating, None);
|
||||
|
||||
world.history.fail_with(None);
|
||||
let report = tracker.refresh(&mut |_| {}).unwrap();
|
||||
|
||||
assert_eq!(report.account, other_account());
|
||||
assert_eq!(tracker.status().updating, Some(other_account()));
|
||||
assert_eq!(
|
||||
tracker.last_active_account().unwrap(),
|
||||
Some(other_account())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refresh_after_a_failed_first_round_adopts_the_account_signed_in_to_the_client() {
|
||||
let world = World::new(&s2_matches());
|
||||
world.history.fail_with(Some(SourceError::InvalidKey));
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
|
||||
world.history.fail_with(None);
|
||||
let report = tracker.refresh(&mut |_| {}).unwrap();
|
||||
|
||||
assert_eq!((report.added, report.stored), (2, 2));
|
||||
assert_eq!(tracker.status().updating, Some(recorded_account()));
|
||||
assert_eq!(tracker.status().problem, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refresh_during_the_first_import_of_a_new_account_keeps_that_account_active() {
|
||||
let (entered_tx, entered) = mpsc::channel();
|
||||
let (release, release_rx) = mpsc::channel();
|
||||
let world = World::with_history(two_accounts().gated(entered_tx, release_rx));
|
||||
let tracker = world.tracker();
|
||||
// The two Matches of the recorded Account go through.
|
||||
release.send(()).unwrap();
|
||||
release.send(()).unwrap();
|
||||
round(&tracker);
|
||||
assert_eq!(entered.try_iter().count(), 2);
|
||||
world.client.sign_in("Autre", "FIX");
|
||||
|
||||
thread::scope(|scope| {
|
||||
let follower = scope.spawn(|| round(&tracker));
|
||||
// The import of the other Account now waits on Riot.
|
||||
entered.recv().unwrap();
|
||||
let refresh = scope.spawn(|| tracker.refresh(&mut |_| {}));
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
release.send(()).unwrap();
|
||||
follower.join().unwrap();
|
||||
refresh.join().unwrap().unwrap();
|
||||
});
|
||||
|
||||
assert_eq!(tracker.status().updating, Some(other_account()));
|
||||
assert_eq!(
|
||||
tracker.last_active_account().unwrap(),
|
||||
Some(other_account())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_fallback_whose_first_sync_failed_is_tried_again_by_later_rounds() {
|
||||
let world = World::new(&s2_matches());
|
||||
world.client.sign_out();
|
||||
world.history.fail_with(Some(SourceError::InvalidKey));
|
||||
let tracker = world.tracker();
|
||||
|
||||
tracker.follow_client(now(), Some("Joueur#EUW"), &mut |_| {});
|
||||
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().updating, Some(recorded_account()));
|
||||
assert_eq!(tracker.status().problem, None);
|
||||
assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refresh_after_a_failed_first_round_uses_the_fallback() {
|
||||
let world = World::new(&s2_matches());
|
||||
world.client.sign_out();
|
||||
world.history.fail_with(Some(SourceError::InvalidKey));
|
||||
let tracker = world.tracker();
|
||||
tracker.follow_client(now(), Some("Joueur#EUW"), &mut |_| {});
|
||||
|
||||
world.history.fail_with(None);
|
||||
let report = tracker.refresh(&mut |_| {}).unwrap();
|
||||
|
||||
assert_eq!((report.added, report.stored), (2, 2));
|
||||
assert_eq!(tracker.status().updating, Some(recorded_account()));
|
||||
assert_eq!(tracker.status().problem, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_fallback_given_after_a_round_without_any_account_is_used() {
|
||||
let world = World::new(&s2_matches());
|
||||
world.client.sign_out();
|
||||
let tracker = world.tracker();
|
||||
round(&tracker);
|
||||
assert_eq!(tracker.status().problem, Some(UpdateProblem::NoAccount));
|
||||
|
||||
tracker.follow_client(now(), Some("Joueur#EUW"), &mut |_| {});
|
||||
|
||||
assert_eq!(tracker.status().updating, Some(recorded_account()));
|
||||
assert_eq!(tracker.status().problem, None);
|
||||
}
|
||||
Reference in new issue
Block a user