Fetch loses albums with CannotHaveMbid as mb_ref #259

Merged
wojtek merged 3 commits from 255---fetch-loses-albums-with-cannothavembid-as-mb_ref into main 2025-01-05 14:55:36 +01:00
Showing only changes of commit 6c89131316 - Show all commits

View File

@ -682,15 +682,13 @@ mod tests {
reduced[0].albums.retain(|a| a.meta.id.mb_ref != mb_ref);
// We need a custom music_hoard to override the get_filtered expectations.
let mut music_hoard = MockIMusicHoard::new();
let mut mh = MockIMusicHoard::new();
let mut seq = Sequence::new();
music_hoard
.expect_get_filtered()
mh.expect_get_filtered()
.times(2)
.in_sequence(&mut seq)
.return_const(collection.clone());
music_hoard
.expect_get_filtered()
mh.expect_get_filtered()
.times(1)
.in_sequence(&mut seq)
.return_const(reduced.clone());
@ -701,31 +699,27 @@ mod tests {
let artist = matches.artist.clone();
let mut seq = Sequence::new();
music_hoard
.expect_get_collection()
mh.expect_get_collection()
.times(1)
.in_sequence(&mut seq)
.return_const(collection.clone());
music_hoard
.expect_remove_album()
mh.expect_remove_album()
.times(1)
.with(eq(artist), eq(removed.meta.id.clone()))
.in_sequence(&mut seq)
.return_once(|_, _| Ok(()));
music_hoard
.expect_merge_album_info()
mh.expect_merge_album_info()
.times(1)
.in_sequence(&mut seq)
.return_once(|_, _, _| Ok(()));
music_hoard
.expect_set_album_mb_ref()
mh.expect_set_album_mb_ref()
.times(1)
.in_sequence(&mut seq)
.return_once(|_, _, _| Ok(()));
}
}
let mut matches = AppMachine::match_state(inner(music_hoard), app_matches);
let mut matches = AppMachine::match_state(inner(mh), app_matches);
// Make sure the last album is selected.
let selection = &mut matches.inner.selection;
@ -747,6 +741,58 @@ mod tests {
assert_eq!(album.meta, selected.meta);
}
#[test]
fn set_album_info_with_clashing_cannot_have_mbid() {
let matches_info = album_match();
// The collection below should trigger MH to remove the album with the same MBID but not
// matching album_id.
// (1) Same artist as matches_info.
let mut artist = Artist::new(ArtistId::new("Artist"));
// (2) An album with the same album_id as the selected one.
artist.albums.push(Album::new(AlbumId::new("Album")));
// (3) An album with a different album_id than the selected one.
// (4) This album has an MBID that is identical to that of the selected match.
let removed =
Album::new(AlbumId::new("Album: Not the Same").with_mb_ref(AlbumMbRef::CannotHaveMbid));
artist.albums.push(removed.clone());
// (5) An album after the one that will be removed. Selection must remain on it.
let selected = Album::new(AlbumId::new("Album: Z"));
artist.albums.push(selected.clone());
let (_tx, rx) = mpsc::channel();
let app_matches = MatchState::new(matches_info.clone(), FetchState::search(rx));
let collection = vec![artist];
let mut mh = music_hoard(collection.clone());
match matches_info {
EntityMatches::Artist(_) => panic!(),
EntityMatches::Album(_) => {
let mut seq = Sequence::new();
mh.expect_get_collection()
.times(1)
.in_sequence(&mut seq)
.return_const(collection.clone());
mh.expect_merge_album_info()
.times(1)
.in_sequence(&mut seq)
.return_once(|_, _, _| Ok(()));
mh.expect_set_album_mb_ref()
.times(1)
.in_sequence(&mut seq)
.return_once(|_, _, _| Ok(()));
}
}
let matches = AppMachine::match_state(inner(mh), app_matches);
matches.select().unwrap_fetch();
}
#[test]
fn set_info_error() {
let matches_info = artist_match();