Complete coverage
All checks were successful
Cargo CI / Build and Test (pull_request) Successful in 2m1s
Cargo CI / Lint (pull_request) Successful in 1m6s

This commit is contained in:
Wojciech Kozlowski 2025-01-02 19:41:06 +01:00
parent e320beda6d
commit 00648063e2

View File

@ -746,6 +746,71 @@ mod tests {
assert_eq!(music_hoard.collection, collection); assert_eq!(music_hoard.collection, collection);
} }
#[test]
fn set_clear_album_db_id() {
let mut database = MockIDatabase::new();
let artist_id = ArtistId::new("an artist");
let mut album_id = AlbumId::new("an album");
let album_id_2 = AlbumId::new("another album");
let mut database_result = vec![Artist::new(artist_id.clone())];
database_result[0].albums.push(Album::new(album_id.clone()));
database
.expect_load()
.times(1)
.return_once(|| Ok(database_result));
database.expect_save().times(2).returning(|_| Ok(()));
let mut music_hoard = MusicHoard::database(database).unwrap();
assert_eq!(
music_hoard.collection[0].albums[0].meta.id.db_id,
AlbumDbId::None
);
// Seting db_id on an album not belonging to the artist is an error.
assert!(music_hoard
.set_album_db_id(&artist_id, &album_id_2, AlbumDbId::CannotHaveMbid)
.is_err());
assert_eq!(
music_hoard.collection[0].albums[0].meta.id.db_id,
AlbumDbId::None
);
// Set db_id.
assert!(music_hoard
.set_album_db_id(&artist_id, &album_id, AlbumDbId::CannotHaveMbid)
.is_ok());
assert_eq!(
music_hoard.collection[0].albums[0].meta.id.db_id,
AlbumDbId::CannotHaveMbid
);
// Clearing db_id on an album that does not exist is an error.
assert!(music_hoard
.clear_album_db_id(&artist_id, &album_id_2)
.is_err());
// Clearing db_id from album without the db_id set is an error. Effectively the album does
// not exist.
assert!(music_hoard
.clear_album_db_id(&artist_id, &album_id)
.is_err());
assert_eq!(
music_hoard.collection[0].albums[0].meta.id.db_id,
AlbumDbId::CannotHaveMbid
);
// To clear the db_id we need the album_id to have the db_id to identify the correct album.
album_id.set_db_id(AlbumDbId::CannotHaveMbid);
assert!(music_hoard.clear_album_db_id(&artist_id, &album_id).is_ok());
assert_eq!(
music_hoard.collection[0].albums[0].meta.id.db_id,
AlbumDbId::None
);
}
#[test] #[test]
fn set_clear_album_seq() { fn set_clear_album_seq() {
let mut database = MockIDatabase::new(); let mut database = MockIDatabase::new();