82 lines
2.6 KiB
Rust
82 lines
2.6 KiB
Rust
use super::*;
|
|
|
|
#[test]
|
|
fn a_database_written_before_the_sync_mark_keeps_working() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let db = dir.path().join("arena.db");
|
|
rusqlite::Connection::open(&db)
|
|
.unwrap()
|
|
.execute_batch(LEGACY_SCHEMA)
|
|
.unwrap();
|
|
let other = Account {
|
|
puuid: "fixture-puuid-other".into(),
|
|
game_name: "Autre".into(),
|
|
tag_line: "FIX".into(),
|
|
};
|
|
let theirs = vec![played_by(
|
|
&payload("EUW1_9", 1750, 9, "I", 1, true, 1_000_005_000),
|
|
&other.puuid,
|
|
)];
|
|
let tracker = open(
|
|
&db,
|
|
FakeHistory::new(
|
|
recorded_account(),
|
|
vec![
|
|
payload("EUW1_1", 1750, 1, "A", 4, false, 1_000_000_000),
|
|
payload("EUW1_2", 1750, 2, "B", 1, true, 1_000_003_000),
|
|
],
|
|
)
|
|
.with_account(other.clone(), theirs),
|
|
);
|
|
|
|
// No mark yet: everything is listed, what is stored is not fetched again.
|
|
let report = sync(&tracker);
|
|
assert_eq!((report.added, report.stored), (1, 2));
|
|
// A new Account can be added to the old table.
|
|
let report = tracker.sync("Autre#FIX", &mut |_| {}).unwrap();
|
|
assert_eq!((report.added, report.stored), (1, 1));
|
|
assert_eq!(tracker.accounts().unwrap().len(), 2);
|
|
}
|
|
|
|
#[test]
|
|
fn queues_map_to_formats_and_non_matches_are_skipped() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let at = |i: i64| (1_000_000 + i) * 1000;
|
|
let fake = FakeHistory::new(
|
|
recorded_account(),
|
|
vec![
|
|
payload("EUW1_1", 1750, 1, "A", 1, true, at(1)),
|
|
payload("EUW1_2", 1740, 2, "B", 2, true, at(2)),
|
|
payload("EUW1_3", 1700, 3, "C", 3, true, at(3)),
|
|
payload("EUW1_4", 1710, 4, "D", 4, true, at(4)),
|
|
],
|
|
)
|
|
.listed_under(1700, payload("EUW1_5", 1704, 5, "E", 1, true, at(5)))
|
|
.listed_under(1700, payload("EUW1_6", 9999, 6, "F", 5, false, at(6)))
|
|
.listed_under(
|
|
1700,
|
|
with_game_mode(&payload("EUW1_7", 1700, 7, "G", 1, true, at(7)), "ARAM"),
|
|
);
|
|
let tracker = open(&dir.path().join("arena.db"), fake);
|
|
|
|
let report = sync(&tracker);
|
|
|
|
assert_eq!((report.added, report.stored), (5, 5));
|
|
let formats: Vec<_> = tracker
|
|
.matches(SELF_PUUID)
|
|
.unwrap()
|
|
.into_iter()
|
|
.map(|m| (m.match_id, m.format))
|
|
.collect();
|
|
assert_eq!(
|
|
formats,
|
|
[
|
|
("EUW1_1".into(), Format::Arena3x6),
|
|
("EUW1_2".into(), Format::BraveryArena),
|
|
("EUW1_3".into(), Format::Arena16),
|
|
("EUW1_4".into(), Format::Arena16),
|
|
("EUW1_6".into(), Format::Other(9999)),
|
|
]
|
|
);
|
|
}
|