Startup merge fails when the database has two albums with the same title as an album in the library #246
@ -301,7 +301,13 @@ impl Display for ArtistId {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{collection::album::AlbumId, core::testmod::FULL_COLLECTION};
|
use crate::{
|
||||||
|
collection::{
|
||||||
|
album::{AlbumId, AlbumMbRef},
|
||||||
|
musicbrainz::MbAlbumRef,
|
||||||
|
},
|
||||||
|
core::testmod::FULL_COLLECTION,
|
||||||
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -612,11 +618,16 @@ mod tests {
|
|||||||
let mut left = Artist::new(ArtistId::new("Artist"));
|
let mut left = Artist::new(ArtistId::new("Artist"));
|
||||||
let mut right = left.clone();
|
let mut right = left.clone();
|
||||||
|
|
||||||
left.albums.push(Album::new(AlbumId::new("Album‐Title ‘Title’")));
|
left.albums
|
||||||
|
.push(Album::new(AlbumId::new("Album‐Title ‘Title’")));
|
||||||
left.albums[0].meta.id.lib_id = AlbumLibId::Value(1);
|
left.albums[0].meta.id.lib_id = AlbumLibId::Value(1);
|
||||||
|
|
||||||
right.albums.push(Album::new(AlbumId::new("alBum—tiTle 'title’")));
|
right
|
||||||
right.albums.push(Album::new(AlbumId::new("Album‐Title “Title”")));
|
.albums
|
||||||
|
.push(Album::new(AlbumId::new("alBum—tiTle 'title’")));
|
||||||
|
right
|
||||||
|
.albums
|
||||||
|
.push(Album::new(AlbumId::new("Album‐Title “Title”")));
|
||||||
|
|
||||||
// The first album will be merged, the second will be added.
|
// The first album will be merged, the second will be added.
|
||||||
let mut expected = left.clone();
|
let mut expected = left.clone();
|
||||||
@ -626,4 +637,59 @@ mod tests {
|
|||||||
let merged = left.merge(right);
|
let merged = left.merge(right);
|
||||||
assert_eq!(expected, merged);
|
assert_eq!(expected, merged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn merge_multiple_singletons() {
|
||||||
|
let mut left = Artist::new(ArtistId::new("Artist"));
|
||||||
|
let mut right = left.clone();
|
||||||
|
|
||||||
|
left.albums.push(Album::new(AlbumId::new("Singleton 1")));
|
||||||
|
left.albums.push(Album::new(AlbumId::new("Singleton 2")));
|
||||||
|
left.albums[0].meta.id.lib_id = AlbumLibId::Singleton;
|
||||||
|
left.albums[1].meta.id.lib_id = AlbumLibId::Singleton;
|
||||||
|
|
||||||
|
right.albums.push(Album::new(AlbumId::new("Singleton 1")));
|
||||||
|
right.albums.push(Album::new(AlbumId::new("Singleton 2")));
|
||||||
|
right.albums.push(Album::new(AlbumId::new("Singleton 3")));
|
||||||
|
right.albums[0].meta.id.lib_id = AlbumLibId::Singleton;
|
||||||
|
right.albums[2].meta.id.lib_id = AlbumLibId::Singleton;
|
||||||
|
|
||||||
|
// Expect first two albums to merge (including lib id) and the third to be added. However,
|
||||||
|
// the third one will lose its lib id due to no match in the primary.
|
||||||
|
let mut expected = left.clone();
|
||||||
|
expected.albums.push(right.albums.last().unwrap().clone());
|
||||||
|
expected.albums.last_mut().unwrap().meta.id.lib_id = AlbumLibId::None;
|
||||||
|
|
||||||
|
let merged = left.merge(right);
|
||||||
|
assert_eq!(expected, merged);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn merge_two_db_albums_to_one_lib_album_with_ids() {
|
||||||
|
let mut left = Artist::new(ArtistId::new("Artist"));
|
||||||
|
let mut right = left.clone();
|
||||||
|
|
||||||
|
let album = Album::new(AlbumId::new("Album"));
|
||||||
|
|
||||||
|
left.albums.push(album.clone());
|
||||||
|
left.albums[0].meta.id.lib_id = AlbumLibId::Value(1);
|
||||||
|
|
||||||
|
// In this test, one DB album has a lib id that matches that of the lib album. This is the
|
||||||
|
// one that we expect to merge while the second album should just be added.
|
||||||
|
right.albums.push(album.clone());
|
||||||
|
right.albums[0].meta.id.lib_id = AlbumLibId::Value(1);
|
||||||
|
right.albums[0].meta.id.mb_ref = AlbumMbRef::Some(
|
||||||
|
MbAlbumRef::from_uuid_str("00000000-0000-0000-0000-000000000000").unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
right.albums.push(album.clone());
|
||||||
|
right.albums[1].meta.id.mb_ref = AlbumMbRef::Some(
|
||||||
|
MbAlbumRef::from_uuid_str("11111111-1111-1111-1111-111111111111").unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let expected = right.clone();
|
||||||
|
|
||||||
|
let merged = left.merge(right);
|
||||||
|
assert_eq!(expected, merged);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user