use super::*; #[test] fn other_participants_may_lack_any_field() { let dir = tempfile::tempdir().unwrap(); let thin = common::without_fields_for_others( &payload("EUW1_1", 1750, 7, "Zed", 2, true, 1_000_000_000), &["placement", "win", "championId", "championName", "teamId"], ); let tracker = open( &dir.path().join("arena.db"), FakeHistory::new(recorded_account(), vec![thin]), ); let report = sync(&tracker); assert_eq!(report.added, 1); let stored = tracker.matches(SELF_PUUID).unwrap(); assert_eq!((stored[0].champion_id, stored[0].placement), (7, 2)); } #[test] fn an_account_resolved_to_another_puuid_is_a_second_account() { let dir = tempfile::tempdir().unwrap(); let db = dir.path().join("arena.db"); let at = |hours: i64| (1_000_000 + hours * 3600) * 1000; let build = |puuid: &str, ids: &[u32]| -> Vec { ids.iter() .map(|&i| { let raw = payload( &format!("EUW1_{i}"), 1750, i, "A", 1, true, at(i64::from(i)), ); played_by(&raw, puuid) }) .collect() }; // Under the development key, Joueur#EUW is P1. let account = |puuid: &str| Account { puuid: puuid.into(), ..recorded_account() }; let first = open(&db, FakeHistory::new(account("P1"), build("P1", &[1, 2]))); sync(&first); let before = first.matches("P1").unwrap(); drop(first); // Under the personal key it is P2: nothing proves it is the same Account. let tracker = open( &db, FakeHistory::new(account("P2"), build("P2", &[1, 2, 3])), ); let report = sync(&tracker); assert_eq!(report.account.puuid, "P2"); assert_eq!((report.added, report.stored), (3, 3)); assert_eq!(tracker.matches("P1").unwrap(), before); let mut puuids: Vec = tracker .accounts() .unwrap() .into_iter() .map(|a| a.puuid) .collect(); puuids.sort(); assert_eq!(puuids, ["P1", "P2"]); } #[test] fn two_accounts_keep_separate_matches() { let dir = tempfile::tempdir().unwrap(); let db = dir.path().join("arena.db"); sync(&open( &db, FakeHistory::new(recorded_account(), five_matches(1_000_000)), )); let other = Account { puuid: "fixture-puuid-other".into(), game_name: "Autre".into(), tag_line: "FIX".into(), }; let theirs: Vec = five_matches(5_000_000)[..2] .iter() .map(|raw| played_by(raw, &other.puuid)) .collect(); let tracker = open(&db, FakeHistory::new(other.clone(), theirs)); let report = tracker.sync("Autre#FIX", &mut |_| {}).unwrap(); assert_eq!((report.added, report.stored), (2, 2)); assert_eq!(tracker.match_count(SELF_PUUID).unwrap(), 5); assert_eq!(tracker.match_count(&other.puuid).unwrap(), 2); assert!( tracker .matches(&other.puuid) .unwrap() .iter() .all(|m| m.started_at_ms >= 5_000_000_000) ); assert_eq!(tracker.accounts().unwrap().len(), 2); } #[test] fn matches_without_the_account_are_skipped() { let dir = tempfile::tempdir().unwrap(); let stranger = Account { puuid: "fixture-puuid-stranger".into(), game_name: "Joueur".into(), tag_line: "EUW".into(), }; let tracker = open( &dir.path().join("arena.db"), FakeHistory::new(stranger, recorded_matches()), ); let report = sync(&tracker); assert_eq!((report.added, report.stored), (0, 0)); } #[test] fn riot_ids_are_validated_and_must_exist() { let dir = tempfile::tempdir().unwrap(); let tracker = open( &dir.path().join("arena.db"), FakeHistory::new(recorded_account(), recorded_matches()), ); for bad in ["Joueur", "#EUW", "Joueur#"] { let err = tracker.sync(bad, &mut |_| {}).unwrap_err(); assert!(matches!(err, Error::InvalidRiotId(_)), "{bad}"); } let err = tracker.sync("Inconnu#EUW", &mut |_| {}).unwrap_err(); assert!(matches!(err, Error::Source(SourceError::NotFound))); }