[library] Listening: the audiobook position as an event (latest write wins), replayed by the export
This commit is contained in:
@@ -94,3 +94,23 @@ fn familiar_and_editions_on_a_book_and_through_an_export() {
|
||||
evs2.push(ev("7", "x", &mut c, 7, Op::Edition { book: "b".into(), sha256: sha, language: None }));
|
||||
assert!(Library::from_events(&evs2).books["b"].editions.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_audiobook_position_is_the_latest_write_and_survives_an_export() {
|
||||
let (mut pc, mut dc) = (Clock::default(), Clock::default());
|
||||
let sha = "cd".repeat(32);
|
||||
let pos = |ms: u64| Op::AudioPosition { book: "b".into(), sha256: sha.clone(), ms };
|
||||
let evs = vec![
|
||||
ev("0", "desk", &mut dc, 1, Op::BookAdd { book: "b".into(), info: info(1), restore: false }),
|
||||
ev("1", "desk", &mut dc, 1_000, pos(61_000)),
|
||||
ev("2", "phone", &mut pc, 2_000, pos(95_250)),
|
||||
ev("3", "phone", &mut pc, 3_000, Op::AudioPosition { book: "b".into(), sha256: "nope".into(), ms: 5 }),
|
||||
];
|
||||
let mut rev = evs.clone();
|
||||
rev.reverse();
|
||||
let lib = Library::from_events(&evs);
|
||||
assert_eq!(lib, Library::from_events(&rev));
|
||||
assert_eq!(lib.books["b"].audio_position, Some((sha.clone(), 95_250)), "to the millisecond, the latest write");
|
||||
let back = Library::from_events(&events_from(&lib, "restore", 10));
|
||||
assert_eq!(back.books.values().next().and_then(|b| b.audio_position.clone()), Some((sha, 95_250)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user