From 1616cf1a366cf7c49f492f566b1a1a19a32f024f Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Mon, 22 Jan 2024 22:07:49 +0100 Subject: [PATCH] Move more tests around --- src/core/collection/artist.rs | 450 ++++++++++++++++++++++++++++++ src/core/musichoard/musichoard.rs | 360 ++---------------------- 2 files changed, 466 insertions(+), 344 deletions(-) diff --git a/src/core/collection/artist.rs b/src/core/collection/artist.rs index c7f4a7c..dd48426 100644 --- a/src/core/collection/artist.rs +++ b/src/core/collection/artist.rs @@ -468,9 +468,14 @@ mod tests { static MUSICBRAINZ: &str = "https://musicbrainz.org/artist/d368baa8-21ca-4759-9731-0b2753071ad8"; + static MUSICBRAINZ_2: &str = + "https://musicbrainz.org/artist/823869a5-5ded-4f6b-9fb7-2a9344d83c6b"; static MUSICBUTLER: &str = "https://www.musicbutler.io/artist-page/483340948"; + static MUSICBUTLER_2: &str = "https://www.musicbutler.io/artist-page/658903042/"; static BANDCAMP: &str = "https://thelasthangmen.bandcamp.com/"; + static BANDCAMP_2: &str = "https://viciouscrusade.bandcamp.com/"; static QOBUZ: &str = "https://www.qobuz.com/nl-nl/interpreter/the-last-hangmen/1244413"; + static QOBUZ_2: &str = "https://www.qobuz.com/nl-nl/interpreter/vicious-crusade/7522386"; #[test] fn musicbrainz() { @@ -522,6 +527,451 @@ mod tests { assert!(Qobuz::new(QOBUZ).is_ok()); } + #[test] + fn artist_sort_set_clear() { + let artist_id = ArtistId::new("an artist"); + let sort_id_1 = ArtistId::new("sort id 1"); + let sort_id_2 = ArtistId::new("sort id 2"); + + let mut artist = Artist::new(artist_id.clone()); + + assert_eq!(artist.id, artist_id); + assert_eq!(artist.sort, None); + assert_eq!(artist.get_sort_key(), &artist_id); + assert!(artist < Artist::new(sort_id_1.clone())); + assert!(artist < Artist::new(sort_id_2.clone())); + + artist.set_sort_key(sort_id_1.clone()); + + assert_eq!(artist.id, artist_id); + assert_eq!(artist.sort.as_ref(), Some(&sort_id_1)); + assert_eq!(artist.get_sort_key(), &sort_id_1); + assert!(artist > Artist::new(artist_id.clone())); + assert!(artist < Artist::new(sort_id_2.clone())); + + artist.set_sort_key(sort_id_2.clone()); + + assert_eq!(artist.id, artist_id); + assert_eq!(artist.sort.as_ref(), Some(&sort_id_2)); + assert_eq!(artist.get_sort_key(), &sort_id_2); + assert!(artist > Artist::new(artist_id.clone())); + assert!(artist > Artist::new(sort_id_1.clone())); + + artist.clear_sort_key(); + + assert_eq!(artist.id, artist_id); + assert_eq!(artist.sort, None); + assert_eq!(artist.get_sort_key(), &artist_id); + assert!(artist < Artist::new(sort_id_1.clone())); + assert!(artist < Artist::new(sort_id_2.clone())); + } + + #[test] + fn add_remove_musicbrainz_url() { + let mut artist = Artist::new(ArtistId::new("an artist")); + + let mut expected: Option = None; + assert_eq!(artist.properties.musicbrainz, expected); + + // Adding incorect URL is an error. + assert!(artist.add_musicbrainz_url(MUSICBUTLER).is_err()); + assert!(artist.add_musicbrainz_url(BANDCAMP).is_err()); + assert!(artist.add_musicbrainz_url(QOBUZ).is_err()); + assert_eq!(artist.properties.musicbrainz, expected); + + // Adding URL to artist. + assert!(artist.add_musicbrainz_url(MUSICBRAINZ).is_ok()); + _ = expected.insert(MusicBrainz::new(MUSICBRAINZ).unwrap()); + assert_eq!(artist.properties.musicbrainz, expected); + + // Adding the same URL again is ok, but does not do anything. + assert!(artist.add_musicbrainz_url(MUSICBRAINZ).is_ok()); + assert_eq!(artist.properties.musicbrainz, expected); + + // Adding further URLs is an error. + assert!(artist.add_musicbrainz_url(MUSICBRAINZ_2).is_err()); + assert_eq!(artist.properties.musicbrainz, expected); + + // Removing a URL not in the collection is okay, but does not do anything. + assert!(artist.remove_musicbrainz_url(MUSICBRAINZ_2).is_ok()); + assert_eq!(artist.properties.musicbrainz, expected); + + // Removing a URL in the collection removes it. + assert!(artist.remove_musicbrainz_url(MUSICBRAINZ).is_ok()); + _ = expected.take(); + assert_eq!(artist.properties.musicbrainz, expected); + + assert!(artist.remove_musicbrainz_url(MUSICBRAINZ).is_ok()); + assert_eq!(artist.properties.musicbrainz, expected); + } + + #[test] + fn set_clear_musicbrainz_url() { + let mut artist = Artist::new(ArtistId::new("an artist")); + + let mut expected: Option = None; + assert_eq!(artist.properties.musicbrainz, expected); + + // Setting an incorrect URL is an error. + assert!(artist.set_musicbrainz_url(MUSICBUTLER).is_err()); + assert!(artist.set_musicbrainz_url(BANDCAMP).is_err()); + assert!(artist.set_musicbrainz_url(QOBUZ).is_err()); + assert_eq!(artist.properties.musicbrainz, expected); + + // Setting a URL on an artist. + assert!(artist.set_musicbrainz_url(MUSICBRAINZ).is_ok()); + _ = expected.insert(MusicBrainz::new(MUSICBRAINZ).unwrap()); + assert_eq!(artist.properties.musicbrainz, expected); + + assert!(artist.set_musicbrainz_url(MUSICBRAINZ).is_ok()); + assert_eq!(artist.properties.musicbrainz, expected); + + assert!(artist.set_musicbrainz_url(MUSICBRAINZ_2).is_ok()); + _ = expected.insert(MusicBrainz::new(MUSICBRAINZ_2).unwrap()); + assert_eq!(artist.properties.musicbrainz, expected); + + // Clearing URLs. + artist.clear_musicbrainz_url(); + _ = expected.take(); + assert_eq!(artist.properties.musicbrainz, expected); + } + + #[test] + fn add_remove_musicbutler_urls() { + let mut artist = Artist::new(ArtistId::new("an artist")); + + let mut expected: Vec = vec![]; + assert_eq!(artist.properties.musicbutler, expected); + + // If any URL is incorrect adding URLs is an error. + assert!(artist + .add_musicbutler_urls(vec![MUSICBRAINZ, MUSICBRAINZ_2]) + .is_err()); + assert!(artist + .add_musicbutler_urls(vec![BANDCAMP, BANDCAMP_2]) + .is_err()); + assert!(artist.add_musicbutler_urls(vec![QOBUZ, QOBUZ_2]).is_err()); + assert!(artist + .add_musicbutler_urls(vec![MUSICBRAINZ, MUSICBUTLER, BANDCAMP, QOBUZ]) + .is_err()); + assert_eq!(artist.properties.musicbutler, expected); + + // Adding a single URL. + assert!(artist.add_musicbutler_urls(vec![MUSICBUTLER]).is_ok()); + expected.push(MusicButler::new(MUSICBUTLER).unwrap()); + assert_eq!(artist.properties.musicbutler, expected); + + // Adding a URL that already exists is ok, but does not do anything. + assert!(artist.add_musicbutler_urls(vec![MUSICBUTLER]).is_ok()); + assert_eq!(artist.properties.musicbutler, expected); + + // Adding another single URL. + assert!(artist.add_musicbutler_urls(vec![MUSICBUTLER_2]).is_ok()); + expected.push(MusicButler::new(MUSICBUTLER_2).unwrap()); + assert_eq!(artist.properties.musicbutler, expected); + + assert!(artist.add_musicbutler_urls(vec![MUSICBUTLER_2]).is_ok()); + assert_eq!(artist.properties.musicbutler, expected); + + // Removing a URL. + assert!(artist.remove_musicbutler_urls(vec![MUSICBUTLER]).is_ok()); + expected.retain(|url| url.as_str() != MUSICBUTLER); + assert_eq!(artist.properties.musicbutler, expected); + + // Removing URls that do not exist is okay, they will be ignored. + assert!(artist.remove_musicbutler_urls(vec![MUSICBUTLER]).is_ok()); + assert_eq!(artist.properties.musicbutler, expected); + + // Removing a URL. + assert!(artist.remove_musicbutler_urls(vec![MUSICBUTLER_2]).is_ok()); + expected.retain(|url| url.as_str() != MUSICBUTLER_2); + assert_eq!(artist.properties.musicbutler, expected); + + assert!(artist.remove_musicbutler_urls(vec![MUSICBUTLER_2]).is_ok()); + assert_eq!(artist.properties.musicbutler, expected); + + // Adding URLs if some exist is okay, they will be ignored. + assert!(artist.add_musicbutler_urls(vec![MUSICBUTLER]).is_ok()); + expected.push(MusicButler::new(MUSICBUTLER).unwrap()); + assert_eq!(artist.properties.musicbutler, expected); + + assert!(artist + .add_musicbutler_urls(vec![MUSICBUTLER, MUSICBUTLER_2]) + .is_ok()); + expected.push(MusicButler::new(MUSICBUTLER_2).unwrap()); + assert_eq!(artist.properties.musicbutler, expected); + + // Removing URLs if some do not exist is okay, they will be ignored. + assert!(artist.remove_musicbutler_urls(vec![MUSICBUTLER]).is_ok()); + expected.retain(|url| url.as_str() != MUSICBUTLER); + assert_eq!(artist.properties.musicbutler, expected); + + assert!(artist + .remove_musicbutler_urls(vec![MUSICBUTLER, MUSICBUTLER_2]) + .is_ok()); + expected.retain(|url| url.as_str() != MUSICBUTLER_2); + assert_eq!(artist.properties.musicbutler, expected); + + // Adding mutliple URLs without clashes. + assert!(artist + .add_musicbutler_urls(vec![MUSICBUTLER, MUSICBUTLER_2]) + .is_ok()); + expected.push(MusicButler::new(MUSICBUTLER).unwrap()); + expected.push(MusicButler::new(MUSICBUTLER_2).unwrap()); + assert_eq!(artist.properties.musicbutler, expected); + + // Removing multiple URLs without clashes. + assert!(artist + .remove_musicbutler_urls(vec![MUSICBUTLER, MUSICBUTLER_2]) + .is_ok()); + expected.clear(); + assert_eq!(artist.properties.musicbutler, expected); + } + + #[test] + fn set_clear_musicbutler_urls() { + let mut artist = Artist::new(ArtistId::new("an artist")); + + let mut expected: Vec = vec![]; + assert_eq!(artist.properties.musicbutler, expected); + + // If any URL is incorrect setting URLs is an error. + assert!(artist + .set_musicbutler_urls(vec![MUSICBRAINZ, MUSICBRAINZ_2]) + .is_err()); + assert!(artist + .set_musicbutler_urls(vec![BANDCAMP, BANDCAMP_2]) + .is_err()); + assert!(artist.set_musicbutler_urls(vec![QOBUZ, QOBUZ_2]).is_err()); + assert!(artist + .set_musicbutler_urls(vec![MUSICBRAINZ, MUSICBUTLER, BANDCAMP, QOBUZ]) + .is_err()); + assert_eq!(artist.properties.musicbutler, expected); + + // Set URLs. + assert!(artist.set_musicbutler_urls(vec![MUSICBUTLER]).is_ok()); + expected.push(MusicButler::new(MUSICBUTLER).unwrap()); + assert_eq!(artist.properties.musicbutler, expected); + + assert!(artist.set_musicbutler_urls(vec![MUSICBUTLER_2]).is_ok()); + expected.clear(); + expected.push(MusicButler::new(MUSICBUTLER_2).unwrap()); + assert_eq!(artist.properties.musicbutler, expected); + + assert!(artist + .set_musicbutler_urls(vec![MUSICBUTLER, MUSICBUTLER_2]) + .is_ok()); + expected.clear(); + expected.push(MusicButler::new(MUSICBUTLER).unwrap()); + expected.push(MusicButler::new(MUSICBUTLER_2).unwrap()); + assert_eq!(artist.properties.musicbutler, expected); + + // Clear URLs. + artist.clear_musicbutler_urls(); + expected.clear(); + assert_eq!(artist.properties.musicbutler, expected); + } + + #[test] + fn add_remove_bandcamp_urls() { + let mut artist = Artist::new(ArtistId::new("an artist")); + + let mut expected: Vec = vec![]; + assert_eq!(artist.properties.bandcamp, expected); + + // If any URL is incorrect adding URLs is an error. + assert!(artist + .add_bandcamp_urls(vec![MUSICBRAINZ, MUSICBRAINZ_2]) + .is_err()); + assert!(artist + .add_bandcamp_urls(vec![MUSICBUTLER, MUSICBUTLER_2]) + .is_err()); + assert!(artist.add_bandcamp_urls(vec![QOBUZ, QOBUZ_2]).is_err()); + assert!(artist + .add_bandcamp_urls(vec![MUSICBRAINZ, MUSICBUTLER, BANDCAMP, QOBUZ]) + .is_err()); + assert_eq!(artist.properties.bandcamp, expected); + + // Adding a single URL. + assert!(artist.add_bandcamp_urls(vec![BANDCAMP]).is_ok()); + expected.push(Bandcamp::new(BANDCAMP).unwrap()); + assert_eq!(artist.properties.bandcamp, expected); + + // Adding a URL that already exists is ok, but does not do anything. + assert!(artist.add_bandcamp_urls(vec![BANDCAMP]).is_ok()); + assert_eq!(artist.properties.bandcamp, expected); + + // Adding another single URL. + assert!(artist.add_bandcamp_urls(vec![BANDCAMP_2]).is_ok()); + expected.push(Bandcamp::new(BANDCAMP_2).unwrap()); + assert_eq!(artist.properties.bandcamp, expected); + + assert!(artist.add_bandcamp_urls(vec![BANDCAMP_2]).is_ok()); + assert_eq!(artist.properties.bandcamp, expected); + + // Removing a URL. + assert!(artist.remove_bandcamp_urls(vec![BANDCAMP]).is_ok()); + expected.retain(|url| url.as_str() != BANDCAMP); + assert_eq!(artist.properties.bandcamp, expected); + + // Removing URls that do not exist is okay, they will be ignored. + assert!(artist.remove_bandcamp_urls(vec![BANDCAMP]).is_ok()); + assert_eq!(artist.properties.bandcamp, expected); + + // Removing a URL. + assert!(artist.remove_bandcamp_urls(vec![BANDCAMP_2]).is_ok()); + expected.retain(|url| url.as_str() != BANDCAMP_2); + assert_eq!(artist.properties.bandcamp, expected); + + assert!(artist.remove_bandcamp_urls(vec![BANDCAMP_2]).is_ok()); + assert_eq!(artist.properties.bandcamp, expected); + + // Adding URLs if some exist is okay, they will be ignored. + assert!(artist.add_bandcamp_urls(vec![BANDCAMP]).is_ok()); + expected.push(Bandcamp::new(BANDCAMP).unwrap()); + assert_eq!(artist.properties.bandcamp, expected); + + assert!(artist.add_bandcamp_urls(vec![BANDCAMP, BANDCAMP_2]).is_ok()); + expected.push(Bandcamp::new(BANDCAMP_2).unwrap()); + assert_eq!(artist.properties.bandcamp, expected); + + // Removing URLs if some do not exist is okay, they will be ignored. + assert!(artist.remove_bandcamp_urls(vec![BANDCAMP]).is_ok()); + expected.retain(|url| url.as_str() != BANDCAMP); + assert_eq!(artist.properties.bandcamp, expected); + + assert!(artist + .remove_bandcamp_urls(vec![BANDCAMP, BANDCAMP_2]) + .is_ok()); + expected.retain(|url| url.as_str() != BANDCAMP_2); + assert_eq!(artist.properties.bandcamp, expected); + + // Adding mutliple URLs without clashes. + assert!(artist.add_bandcamp_urls(vec![BANDCAMP, BANDCAMP_2]).is_ok()); + expected.push(Bandcamp::new(BANDCAMP).unwrap()); + expected.push(Bandcamp::new(BANDCAMP_2).unwrap()); + assert_eq!(artist.properties.bandcamp, expected); + + // Removing multiple URLs without clashes. + assert!(artist + .remove_bandcamp_urls(vec![BANDCAMP, BANDCAMP_2]) + .is_ok()); + expected.clear(); + assert_eq!(artist.properties.bandcamp, expected); + } + + #[test] + fn set_clear_bandcamp_urls() { + let mut artist = Artist::new(ArtistId::new("an artist")); + + let mut expected: Vec = vec![]; + assert_eq!(artist.properties.bandcamp, expected); + + // If any URL is incorrect setting URLs is an error. + assert!(artist + .set_bandcamp_urls(vec![MUSICBRAINZ, MUSICBRAINZ_2]) + .is_err()); + assert!(artist + .set_bandcamp_urls(vec![MUSICBUTLER, MUSICBUTLER_2]) + .is_err()); + assert!(artist.set_bandcamp_urls(vec![QOBUZ, QOBUZ_2]).is_err()); + assert!(artist + .set_bandcamp_urls(vec![MUSICBRAINZ, MUSICBUTLER, BANDCAMP, QOBUZ]) + .is_err()); + assert_eq!(artist.properties.bandcamp, expected); + + // Set URLs. + assert!(artist.set_bandcamp_urls(vec![BANDCAMP]).is_ok()); + expected.push(Bandcamp::new(BANDCAMP).unwrap()); + assert_eq!(artist.properties.bandcamp, expected); + + assert!(artist.set_bandcamp_urls(vec![BANDCAMP_2]).is_ok()); + expected.clear(); + expected.push(Bandcamp::new(BANDCAMP_2).unwrap()); + assert_eq!(artist.properties.bandcamp, expected); + + assert!(artist.set_bandcamp_urls(vec![BANDCAMP, BANDCAMP_2]).is_ok()); + expected.clear(); + expected.push(Bandcamp::new(BANDCAMP).unwrap()); + expected.push(Bandcamp::new(BANDCAMP_2).unwrap()); + assert_eq!(artist.properties.bandcamp, expected); + + // Clear URLs. + artist.clear_bandcamp_urls(); + expected.clear(); + assert_eq!(artist.properties.bandcamp, expected); + } + + #[test] + fn add_remove_qobuz_url() { + let mut artist = Artist::new(ArtistId::new("an artist")); + + let mut expected: Option = None; + assert_eq!(artist.properties.qobuz, expected); + + // Adding incorect URL is an error. + assert!(artist.add_qobuz_url(MUSICBRAINZ).is_err()); + assert!(artist.add_qobuz_url(MUSICBUTLER).is_err()); + assert!(artist.add_qobuz_url(BANDCAMP).is_err()); + assert_eq!(artist.properties.qobuz, expected); + + // Adding URL to artist. + assert!(artist.add_qobuz_url(QOBUZ).is_ok()); + _ = expected.insert(Qobuz::new(QOBUZ).unwrap()); + assert_eq!(artist.properties.qobuz, expected); + + // Adding the same URL again is ok, but does not do anything. + assert!(artist.add_qobuz_url(QOBUZ).is_ok()); + assert_eq!(artist.properties.qobuz, expected); + + // Adding further URLs is an error. + assert!(artist.add_qobuz_url(QOBUZ_2).is_err()); + assert_eq!(artist.properties.qobuz, expected); + + // Removing a URL not in the collection is okay, but does not do anything. + assert!(artist.remove_qobuz_url(QOBUZ_2).is_ok()); + assert_eq!(artist.properties.qobuz, expected); + + // Removing a URL in the collection removes it. + assert!(artist.remove_qobuz_url(QOBUZ).is_ok()); + _ = expected.take(); + assert_eq!(artist.properties.qobuz, expected); + + assert!(artist.remove_qobuz_url(QOBUZ).is_ok()); + assert_eq!(artist.properties.qobuz, expected); + } + + #[test] + fn set_clear_qobuz_url() { + let mut artist = Artist::new(ArtistId::new("an artist")); + + let mut expected: Option = None; + assert_eq!(artist.properties.qobuz, expected); + + // Setting an incorrect URL is an error. + assert!(artist.set_qobuz_url(MUSICBUTLER).is_err()); + assert!(artist.set_qobuz_url(BANDCAMP).is_err()); + assert!(artist.set_qobuz_url(MUSICBRAINZ).is_err()); + assert_eq!(artist.properties.qobuz, expected); + + // Setting a URL on an artist. + assert!(artist.set_qobuz_url(QOBUZ).is_ok()); + _ = expected.insert(Qobuz::new(QOBUZ).unwrap()); + assert_eq!(artist.properties.qobuz, expected); + + assert!(artist.set_qobuz_url(QOBUZ).is_ok()); + assert_eq!(artist.properties.qobuz, expected); + + assert!(artist.set_qobuz_url(QOBUZ_2).is_ok()); + _ = expected.insert(Qobuz::new(QOBUZ_2).unwrap()); + assert_eq!(artist.properties.qobuz, expected); + + // Clearing URLs. + artist.clear_qobuz_url(); + _ = expected.take(); + assert_eq!(artist.properties.qobuz, expected); + } + #[test] fn merge_artist_no_overlap() { let left = FULL_COLLECTION[0].to_owned(); diff --git a/src/core/musichoard/musichoard.rs b/src/core/musichoard/musichoard.rs index 70278d5..6ea79fd 100644 --- a/src/core/musichoard/musichoard.rs +++ b/src/core/musichoard/musichoard.rs @@ -342,17 +342,13 @@ mod tests { use crate::database::{self, MockIDatabase}; use crate::library::{self, testmod::LIBRARY_ITEMS, MockILibrary}; - // FIXME: all tests with URLs should go to collection::artist static MUSICBRAINZ: &str = "https://musicbrainz.org/artist/d368baa8-21ca-4759-9731-0b2753071ad8"; - static MUSICBRAINZ_2: &str = - "https://musicbrainz.org/artist/823869a5-5ded-4f6b-9fb7-2a9344d83c6b"; static MUSICBUTLER: &str = "https://www.musicbutler.io/artist-page/483340948"; static MUSICBUTLER_2: &str = "https://www.musicbutler.io/artist-page/658903042/"; static BANDCAMP: &str = "https://thelasthangmen.bandcamp.com/"; static BANDCAMP_2: &str = "https://viciouscrusade.bandcamp.com/"; static QOBUZ: &str = "https://www.qobuz.com/nl-nl/interpreter/the-last-hangmen/1244413"; - static QOBUZ_2: &str = "https://www.qobuz.com/nl-nl/interpreter/vicious-crusade/7522386"; #[test] fn artist_new_delete() { @@ -428,12 +424,14 @@ mod tests { fn collection_error() { let artist_id = ArtistId::new("an artist"); let mut music_hoard = MusicHoard::default(); + music_hoard.add_artist(artist_id.clone()); let actual_err = music_hoard .add_musicbrainz_url(&artist_id, QOBUZ) .unwrap_err(); - let expected_err = - Error::CollectionError(String::from("artist 'an artist' is not in the collection")); + let expected_err = Error::CollectionError(format!( + "an error occurred when processing a URL: invalid MusicBrainz URL: {QOBUZ}" + )); assert_eq!(actual_err, expected_err); assert_eq!(actual_err.to_string(), expected_err.to_string()); } @@ -449,16 +447,6 @@ mod tests { let mut expected: Option = None; assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); - // Adding incorect URL is an error. - assert!(music_hoard - .add_musicbrainz_url(&artist_id, MUSICBUTLER) - .is_err()); - assert!(music_hoard - .add_musicbrainz_url(&artist_id, BANDCAMP) - .is_err()); - assert!(music_hoard.add_musicbrainz_url(&artist_id, QOBUZ).is_err()); - assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); - // Adding URL to an artist not in the collection is an error. assert!(music_hoard .add_musicbrainz_url(&artist_id_2, MUSICBRAINZ) @@ -472,41 +460,18 @@ mod tests { _ = expected.insert(MusicBrainz::new(MUSICBRAINZ).unwrap()); assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); - // Adding the same URL again is ok, but does not do anything. - assert!(music_hoard - .add_musicbrainz_url(&artist_id, MUSICBRAINZ) - .is_ok()); - assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); - - // Adding further URLs is an error. - assert!(music_hoard - .add_musicbrainz_url(&artist_id, MUSICBRAINZ_2) - .is_err()); - assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); - // Removing a URL from an artist not in the collection is an error. assert!(music_hoard .remove_musicbrainz_url(&artist_id_2, MUSICBRAINZ) .is_err()); assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); - // Removing a URL not in the collection is okay, but does not do anything. - assert!(music_hoard - .remove_musicbrainz_url(&artist_id, MUSICBRAINZ_2) - .is_ok()); - assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); - // Removing a URL in the collection removes it. assert!(music_hoard .remove_musicbrainz_url(&artist_id, MUSICBRAINZ) .is_ok()); _ = expected.take(); assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); - - assert!(music_hoard - .remove_musicbrainz_url(&artist_id, MUSICBRAINZ) - .is_ok()); - assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); } #[test] @@ -520,16 +485,6 @@ mod tests { let mut expected: Option = None; assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); - // Setting an incorrect URL is an error. - assert!(music_hoard - .set_musicbrainz_url(&artist_id, MUSICBUTLER) - .is_err()); - assert!(music_hoard - .set_musicbrainz_url(&artist_id, BANDCAMP) - .is_err()); - assert!(music_hoard.set_musicbrainz_url(&artist_id, QOBUZ).is_err()); - assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); - // Setting a URL on an artist not in the collection is an error. assert!(music_hoard .set_musicbrainz_url(&artist_id_2, MUSICBRAINZ) @@ -543,17 +498,6 @@ mod tests { _ = expected.insert(MusicBrainz::new(MUSICBRAINZ).unwrap()); assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); - assert!(music_hoard - .set_musicbrainz_url(&artist_id, MUSICBRAINZ) - .is_ok()); - assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); - - assert!(music_hoard - .set_musicbrainz_url(&artist_id, MUSICBRAINZ_2) - .is_ok()); - _ = expected.insert(MusicBrainz::new(MUSICBRAINZ_2).unwrap()); - assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); - // Clearing URLs on an artist that does not exist is an error. assert!(music_hoard.clear_musicbrainz_url(&artist_id_2).is_err()); assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected); @@ -575,109 +519,12 @@ mod tests { let mut expected: Vec = vec![]; assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - // If any URL is incorrect adding URLs is an error. - assert!(music_hoard - .add_musicbutler_urls(&artist_id, vec![MUSICBRAINZ, MUSICBRAINZ_2]) - .is_err()); - assert!(music_hoard - .add_musicbutler_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2]) - .is_err()); - assert!(music_hoard - .add_musicbutler_urls(&artist_id, vec![QOBUZ, QOBUZ_2]) - .is_err()); - assert!(music_hoard - .add_musicbutler_urls(&artist_id, vec![MUSICBRAINZ, MUSICBUTLER, BANDCAMP, QOBUZ]) - .is_err()); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - // Adding URLs to an artist not in the collection is an error. assert!(music_hoard .add_musicbutler_urls(&artist_id_2, vec![MUSICBUTLER]) .is_err()); assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - // Adding a single URL. - assert!(music_hoard - .add_musicbutler_urls(&artist_id, vec![MUSICBUTLER]) - .is_ok()); - expected.push(MusicButler::new(MUSICBUTLER).unwrap()); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - - // Adding a URL that already exists is ok, but does not do anything. - assert!(music_hoard - .add_musicbutler_urls(&artist_id, vec![MUSICBUTLER]) - .is_ok()); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - - // Adding another single URL. - assert!(music_hoard - .add_musicbutler_urls(&artist_id, vec![MUSICBUTLER_2]) - .is_ok()); - expected.push(MusicButler::new(MUSICBUTLER_2).unwrap()); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - - assert!(music_hoard - .add_musicbutler_urls(&artist_id, vec![MUSICBUTLER_2]) - .is_ok()); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - - // Removing URLs from an artist not in the collection is an error. - assert!(music_hoard - .remove_musicbutler_urls(&artist_id_2, vec![MUSICBUTLER]) - .is_err()); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - - // Removing a URL. - assert!(music_hoard - .remove_musicbutler_urls(&artist_id, vec![MUSICBUTLER]) - .is_ok()); - expected.retain(|url| url.as_str() != MUSICBUTLER); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - - // Removing URls that do not exist is okay, they will be ignored. - assert!(music_hoard - .remove_musicbutler_urls(&artist_id, vec![MUSICBUTLER]) - .is_ok()); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - - // Removing a URL. - assert!(music_hoard - .remove_musicbutler_urls(&artist_id, vec![MUSICBUTLER_2]) - .is_ok()); - expected.retain(|url| url.as_str() != MUSICBUTLER_2); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - - assert!(music_hoard - .remove_musicbutler_urls(&artist_id, vec![MUSICBUTLER_2]) - .is_ok()); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - - // Adding URLs if some exist is okay, they will be ignored. - assert!(music_hoard - .add_musicbutler_urls(&artist_id, vec![MUSICBUTLER]) - .is_ok()); - expected.push(MusicButler::new(MUSICBUTLER).unwrap()); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - - assert!(music_hoard - .add_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2]) - .is_ok()); - expected.push(MusicButler::new(MUSICBUTLER_2).unwrap()); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - - // Removing URLs if some do not exist is okay, they will be ignored. - assert!(music_hoard - .remove_musicbutler_urls(&artist_id, vec![MUSICBUTLER]) - .is_ok()); - expected.retain(|url| url.as_str() != MUSICBUTLER); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - - assert!(music_hoard - .remove_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2]) - .is_ok()); - expected.retain(|url| url.as_str() != MUSICBUTLER_2); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - // Adding mutliple URLs without clashes. assert!(music_hoard .add_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2]) @@ -686,6 +533,12 @@ mod tests { expected.push(MusicButler::new(MUSICBUTLER_2).unwrap()); assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); + // Removing URLs from an artist not in the collection is an error. + assert!(music_hoard + .remove_musicbutler_urls(&artist_id_2, vec![MUSICBUTLER]) + .is_err()); + assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); + // Removing multiple URLs without clashes. assert!(music_hoard .remove_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2]) @@ -705,21 +558,6 @@ mod tests { let mut expected: Vec = vec![]; assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - // If any URL is incorrect setting URLs is an error. - assert!(music_hoard - .set_musicbutler_urls(&artist_id, vec![MUSICBRAINZ, MUSICBRAINZ_2]) - .is_err()); - assert!(music_hoard - .set_musicbutler_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2]) - .is_err()); - assert!(music_hoard - .set_musicbutler_urls(&artist_id, vec![QOBUZ, QOBUZ_2]) - .is_err()); - assert!(music_hoard - .set_musicbutler_urls(&artist_id, vec![MUSICBRAINZ, MUSICBUTLER, BANDCAMP, QOBUZ]) - .is_err()); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - // Seting URL on an artist not in the collection is an error. assert!(music_hoard .set_musicbutler_urls(&artist_id_2, vec![MUSICBUTLER]) @@ -727,19 +565,6 @@ mod tests { assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); // Set URLs. - assert!(music_hoard - .set_musicbutler_urls(&artist_id, vec![MUSICBUTLER]) - .is_ok()); - expected.push(MusicButler::new(MUSICBUTLER).unwrap()); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - - assert!(music_hoard - .set_musicbutler_urls(&artist_id, vec![MUSICBUTLER_2]) - .is_ok()); - expected.clear(); - expected.push(MusicButler::new(MUSICBUTLER_2).unwrap()); - assert_eq!(music_hoard.collection[0].properties.musicbutler, expected); - assert!(music_hoard .set_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2]) .is_ok()); @@ -768,109 +593,12 @@ mod tests { let mut expected: Vec = vec![]; assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - // If any URL is incorrect adding URLs is an error. - assert!(music_hoard - .add_bandcamp_urls(&artist_id, vec![MUSICBRAINZ, MUSICBRAINZ_2]) - .is_err()); - assert!(music_hoard - .add_bandcamp_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2]) - .is_err()); - assert!(music_hoard - .add_bandcamp_urls(&artist_id, vec![QOBUZ, QOBUZ_2]) - .is_err()); - assert!(music_hoard - .add_bandcamp_urls(&artist_id, vec![MUSICBRAINZ, MUSICBUTLER, BANDCAMP, QOBUZ]) - .is_err()); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - // Adding URLs to an artist not in the collection is an error. assert!(music_hoard .add_bandcamp_urls(&artist_id_2, vec![BANDCAMP]) .is_err()); assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - // Adding a single URL. - assert!(music_hoard - .add_bandcamp_urls(&artist_id, vec![BANDCAMP]) - .is_ok()); - expected.push(Bandcamp::new(BANDCAMP).unwrap()); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - - // Adding a URL that already exists is ok, but does not do anything. - assert!(music_hoard - .add_bandcamp_urls(&artist_id, vec![BANDCAMP]) - .is_ok()); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - - // Adding another single URL. - assert!(music_hoard - .add_bandcamp_urls(&artist_id, vec![BANDCAMP_2]) - .is_ok()); - expected.push(Bandcamp::new(BANDCAMP_2).unwrap()); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - - assert!(music_hoard - .add_bandcamp_urls(&artist_id, vec![BANDCAMP_2]) - .is_ok()); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - - // Removing URLs from an artist not in the collection is an error. - assert!(music_hoard - .remove_bandcamp_urls(&artist_id_2, vec![BANDCAMP]) - .is_err()); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - - // Removing a URL. - assert!(music_hoard - .remove_bandcamp_urls(&artist_id, vec![BANDCAMP]) - .is_ok()); - expected.retain(|url| url.as_str() != BANDCAMP); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - - // Removing URls that do not exist is okay, they will be ignored. - assert!(music_hoard - .remove_bandcamp_urls(&artist_id, vec![BANDCAMP]) - .is_ok()); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - - // Removing a URL. - assert!(music_hoard - .remove_bandcamp_urls(&artist_id, vec![BANDCAMP_2]) - .is_ok()); - expected.retain(|url| url.as_str() != BANDCAMP_2); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - - assert!(music_hoard - .remove_bandcamp_urls(&artist_id, vec![BANDCAMP_2]) - .is_ok()); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - - // Adding URLs if some exist is okay, they will be ignored. - assert!(music_hoard - .add_bandcamp_urls(&artist_id, vec![BANDCAMP]) - .is_ok()); - expected.push(Bandcamp::new(BANDCAMP).unwrap()); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - - assert!(music_hoard - .add_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2]) - .is_ok()); - expected.push(Bandcamp::new(BANDCAMP_2).unwrap()); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - - // Removing URLs if some do not exist is okay, they will be ignored. - assert!(music_hoard - .remove_bandcamp_urls(&artist_id, vec![BANDCAMP]) - .is_ok()); - expected.retain(|url| url.as_str() != BANDCAMP); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - - assert!(music_hoard - .remove_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2]) - .is_ok()); - expected.retain(|url| url.as_str() != BANDCAMP_2); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - // Adding mutliple URLs without clashes. assert!(music_hoard .add_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2]) @@ -879,6 +607,12 @@ mod tests { expected.push(Bandcamp::new(BANDCAMP_2).unwrap()); assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); + // Removing URLs from an artist not in the collection is an error. + assert!(music_hoard + .remove_bandcamp_urls(&artist_id_2, vec![BANDCAMP]) + .is_err()); + assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); + // Removing multiple URLs without clashes. assert!(music_hoard .remove_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2]) @@ -898,21 +632,6 @@ mod tests { let mut expected: Vec = vec![]; assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - // If any URL is incorrect setting URLs is an error. - assert!(music_hoard - .set_bandcamp_urls(&artist_id, vec![MUSICBRAINZ, MUSICBRAINZ_2]) - .is_err()); - assert!(music_hoard - .set_bandcamp_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2]) - .is_err()); - assert!(music_hoard - .set_bandcamp_urls(&artist_id, vec![QOBUZ, QOBUZ_2]) - .is_err()); - assert!(music_hoard - .set_bandcamp_urls(&artist_id, vec![MUSICBRAINZ, MUSICBUTLER, BANDCAMP, QOBUZ]) - .is_err()); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - // Seting URL on an artist not in the collection is an error. assert!(music_hoard .set_bandcamp_urls(&artist_id_2, vec![BANDCAMP]) @@ -920,19 +639,6 @@ mod tests { assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); // Set URLs. - assert!(music_hoard - .set_bandcamp_urls(&artist_id, vec![BANDCAMP]) - .is_ok()); - expected.push(Bandcamp::new(BANDCAMP).unwrap()); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - - assert!(music_hoard - .set_bandcamp_urls(&artist_id, vec![BANDCAMP_2]) - .is_ok()); - expected.clear(); - expected.push(Bandcamp::new(BANDCAMP_2).unwrap()); - assert_eq!(music_hoard.collection[0].properties.bandcamp, expected); - assert!(music_hoard .set_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2]) .is_ok()); @@ -961,12 +667,6 @@ mod tests { let mut expected: Option = None; assert_eq!(music_hoard.collection[0].properties.qobuz, expected); - // Adding incorect URL is an error. - assert!(music_hoard.add_qobuz_url(&artist_id, MUSICBRAINZ).is_err()); - assert!(music_hoard.add_qobuz_url(&artist_id, MUSICBUTLER).is_err()); - assert!(music_hoard.add_qobuz_url(&artist_id, BANDCAMP).is_err()); - assert_eq!(music_hoard.collection[0].properties.qobuz, expected); - // Adding URL to an artist not in the collection is an error. assert!(music_hoard.add_qobuz_url(&artist_id_2, QOBUZ).is_err()); assert_eq!(music_hoard.collection[0].properties.qobuz, expected); @@ -976,29 +676,14 @@ mod tests { _ = expected.insert(Qobuz::new(QOBUZ).unwrap()); assert_eq!(music_hoard.collection[0].properties.qobuz, expected); - // Adding the same URL again is ok, but does not do anything. - assert!(music_hoard.add_qobuz_url(&artist_id, QOBUZ).is_ok()); - assert_eq!(music_hoard.collection[0].properties.qobuz, expected); - - // Adding further URLs is an error. - assert!(music_hoard.add_qobuz_url(&artist_id, QOBUZ_2).is_err()); - assert_eq!(music_hoard.collection[0].properties.qobuz, expected); - // Removing a URL from an artist not in the collection is an error. assert!(music_hoard.remove_qobuz_url(&artist_id_2, QOBUZ).is_err()); assert_eq!(music_hoard.collection[0].properties.qobuz, expected); - // Removing a URL not in the collection is okay, but does not do anything. - assert!(music_hoard.remove_qobuz_url(&artist_id, QOBUZ_2).is_ok()); - assert_eq!(music_hoard.collection[0].properties.qobuz, expected); - // Removing a URL in the collection removes it. assert!(music_hoard.remove_qobuz_url(&artist_id, QOBUZ).is_ok()); _ = expected.take(); assert_eq!(music_hoard.collection[0].properties.qobuz, expected); - - assert!(music_hoard.remove_qobuz_url(&artist_id, QOBUZ).is_ok()); - assert_eq!(music_hoard.collection[0].properties.qobuz, expected); } #[test] @@ -1012,12 +697,6 @@ mod tests { let mut expected: Option = None; assert_eq!(music_hoard.collection[0].properties.qobuz, expected); - // Setting an incorrect URL is an error. - assert!(music_hoard.set_qobuz_url(&artist_id, MUSICBUTLER).is_err()); - assert!(music_hoard.set_qobuz_url(&artist_id, BANDCAMP).is_err()); - assert!(music_hoard.set_qobuz_url(&artist_id, MUSICBRAINZ).is_err()); - assert_eq!(music_hoard.collection[0].properties.qobuz, expected); - // Setting a URL on an artist not in the collection is an error. assert!(music_hoard.set_qobuz_url(&artist_id_2, QOBUZ).is_err()); assert_eq!(music_hoard.collection[0].properties.qobuz, expected); @@ -1027,13 +706,6 @@ mod tests { _ = expected.insert(Qobuz::new(QOBUZ).unwrap()); assert_eq!(music_hoard.collection[0].properties.qobuz, expected); - assert!(music_hoard.set_qobuz_url(&artist_id, QOBUZ).is_ok()); - assert_eq!(music_hoard.collection[0].properties.qobuz, expected); - - assert!(music_hoard.set_qobuz_url(&artist_id, QOBUZ_2).is_ok()); - _ = expected.insert(Qobuz::new(QOBUZ_2).unwrap()); - assert_eq!(music_hoard.collection[0].properties.qobuz, expected); - // Clearing URLs on an artist that does not exist is an error. assert!(music_hoard.clear_qobuz_url(&artist_id_2).is_err()); assert_eq!(music_hoard.collection[0].properties.qobuz, expected);