Add method to manually add artist metadata #85

Merged
wojtek merged 16 commits from 55---add-method-to-manually-add-artist-metadata into main 2024-01-10 22:33:58 +01:00
Showing only changes of commit 29ff4f9a00 - Show all commits

View File

@ -423,9 +423,9 @@ macro_rules! artist_multi_url_dispatch {
} }
impl Artist { impl Artist {
pub fn new(id: ArtistId) -> Self { pub fn new<ID: Into<ArtistId>>(id: ID) -> Self {
Artist { Artist {
id, id: id.into(),
properties: ArtistProperties::default(), properties: ArtistProperties::default(),
albums: vec![], albums: vec![],
} }
@ -1068,6 +1068,18 @@ mod tests {
use super::*; use super::*;
static MUSICBRAINZ: &'static str =
"https://musicbrainz.org/artist/d368baa8-21ca-4759-9731-0b2753071ad8";
static MUSICBRAINZ_2: &'static str =
"https://musicbrainz.org/artist/823869a5-5ded-4f6b-9fb7-2a9344d83c6b";
static MUSICBUTLER: &'static str = "https://www.musicbutler.io/artist-page/483340948";
static MUSICBUTLER_2: &'static str = "https://www.musicbutler.io/artist-page/658903042/";
static BANDCAMP: &'static str = "https://thelasthangmen.bandcamp.com/";
static BANDCAMP_2: &'static str = "https://viciouscrusade.bandcamp.com/";
static QOBUZ: &'static str = "https://www.qobuz.com/nl-nl/interpreter/the-last-hangmen/1244413";
static QOBUZ_2: &'static str =
"https://www.qobuz.com/nl-nl/interpreter/vicious-crusade/7522386";
pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| collection!()); pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| collection!());
pub fn artist_to_items(artist: &Artist) -> Vec<Item> { pub fn artist_to_items(artist: &Artist) -> Vec<Item> {
@ -1139,30 +1151,572 @@ mod tests {
#[test] #[test]
fn urls() { fn urls() {
let musicbrainz = "https://musicbrainz.org/artist/d368baa8-21ca-4759-9731-0b2753071ad8"; assert!(MusicBrainz::new(MUSICBRAINZ).is_ok());
let musicbutler = "https://www.musicbutler.io/artist-page/483340948"; assert!(MusicBrainz::new(MUSICBUTLER).is_err());
let bandcamp = "https://thelasthangmen.bandcamp.com/"; assert!(MusicBrainz::new(BANDCAMP).is_err());
let qobuz = "https://www.qobuz.com/nl-nl/interpreter/the-last-hangmen/1244413"; assert!(MusicBrainz::new(QOBUZ).is_err());
assert!(MusicBrainz::new(musicbrainz).is_ok()); assert!(MusicButler::new(MUSICBRAINZ).is_err());
assert!(MusicBrainz::new(musicbutler).is_err()); assert!(MusicButler::new(MUSICBUTLER).is_ok());
assert!(MusicBrainz::new(bandcamp).is_err()); assert!(MusicButler::new(BANDCAMP).is_err());
assert!(MusicBrainz::new(qobuz).is_err()); assert!(MusicButler::new(QOBUZ).is_err());
assert!(MusicButler::new(musicbrainz).is_err()); assert!(Bandcamp::new(MUSICBRAINZ).is_err());
assert!(MusicButler::new(musicbutler).is_ok()); assert!(Bandcamp::new(MUSICBUTLER).is_err());
assert!(MusicButler::new(bandcamp).is_err()); assert!(Bandcamp::new(BANDCAMP).is_ok());
assert!(MusicButler::new(qobuz).is_err()); assert!(Bandcamp::new(QOBUZ).is_err());
assert!(Bandcamp::new(musicbrainz).is_err()); assert!(Qobuz::new(MUSICBRAINZ).is_err());
assert!(Bandcamp::new(musicbutler).is_err()); assert!(Qobuz::new(MUSICBUTLER).is_err());
assert!(Bandcamp::new(bandcamp).is_ok()); assert!(Qobuz::new(BANDCAMP).is_err());
assert!(Bandcamp::new(qobuz).is_err()); assert!(Qobuz::new(QOBUZ).is_ok());
}
assert!(Qobuz::new(musicbrainz).is_err()); #[test]
assert!(Qobuz::new(musicbutler).is_err()); fn artist_new_delete() {
assert!(Qobuz::new(bandcamp).is_err()); let artist_id = ArtistId::new("an artist");
assert!(Qobuz::new(qobuz).is_ok()); let artist_id_2 = ArtistId::new("another artist");
let mut music_hoard = MusicHoard::<NoLibrary, NoDatabase>::new(None, None);
assert!(music_hoard.new_artist(&artist_id).is_ok());
let actual_err = music_hoard.new_artist(&artist_id).unwrap_err();
let expected_err = Error::CollectionError(String::from(
"artist 'an artist' is already in the collection",
));
assert_eq!(actual_err, expected_err);
assert_eq!(actual_err.to_string(), expected_err.to_string());
let actual_err = music_hoard.delete_artist(&artist_id_2).unwrap_err();
let expected_err = Error::CollectionError(String::from(
"artist 'another artist' is not in the collection",
));
assert_eq!(actual_err, expected_err);
assert_eq!(actual_err.to_string(), expected_err.to_string());
assert!(music_hoard.delete_artist(&artist_id).is_ok());
}
#[test]
fn artist_musicbrainz_url() {
let artist_id = ArtistId::new("an artist");
let artist_id_2 = ArtistId::new("another artist");
let mut music_hoard = MusicHoard::<NoLibrary, NoDatabase>::new(None, None);
assert!(music_hoard.new_artist(&artist_id).is_ok());
let mut expected: Option<MusicBrainz> = 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)
.is_err());
assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected);
// Adding URL to artist.
assert!(music_hoard
.add_musicbrainz_url(&artist_id, MUSICBRAINZ)
.is_ok());
_ = expected.insert(MusicBrainz::new(MUSICBRAINZ).unwrap());
assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected);
// Adding further URLs is an error.
assert!(music_hoard
.add_musicbrainz_url(&artist_id, MUSICBRAINZ)
.is_err());
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 is only okay if it matches the stored one.
assert!(music_hoard
.remove_musicbrainz_url(&artist_id, MUSICBRAINZ_2)
.is_err());
assert!(music_hoard
.remove_musicbrainz_url(&artist_id, MUSICBRAINZ)
.is_ok());
_ = expected.take();
assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected);
// Removing a URl if one does not exist is an error.
assert!(music_hoard
.remove_musicbrainz_url(&artist_id, MUSICBRAINZ)
.is_err());
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)
.is_err());
assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected);
// Setting a URL on an artist.
assert!(music_hoard
.set_musicbrainz_url(&artist_id, MUSICBRAINZ)
.is_ok());
_ = 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);
// Clearing URLs.
assert!(music_hoard.clear_musicbrainz_url(&artist_id).is_ok());
_ = expected.take();
assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected);
assert!(music_hoard.delete_artist(&artist_id).is_ok());
}
#[test]
fn artist_musicbutler_urls() {
let artist_id = ArtistId::new("an artist");
let artist_id_2 = ArtistId::new("another artist");
let mut music_hoard = MusicHoard::<NoLibrary, NoDatabase>::new(None, None);
assert!(music_hoard.new_artist(&artist_id).is_ok());
let mut expected: Vec<MusicButler> = 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 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 an error.
assert!(music_hoard
.add_musicbutler_urls(&artist_id, vec![MUSICBUTLER])
.is_err());
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
// Adding another 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_err());
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
// Removing URLs to 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_ref() != MUSICBUTLER);
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
// If any URL does not exist removing URLs is an error.
assert!(music_hoard
.remove_musicbutler_urls(&artist_id, vec![MUSICBUTLER])
.is_err());
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
assert!(music_hoard
.remove_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2])
.is_err());
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
// If any URL already exists exists adding URLs is an error.
assert!(music_hoard
.add_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2])
.is_err());
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_ref() != MUSICBUTLER_2);
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
assert!(music_hoard
.remove_musicbutler_urls(&artist_id, vec![MUSICBUTLER_2])
.is_err());
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
// Adding mutliple URLs is okay if none of them already exist.
assert!(music_hoard
.add_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2])
.is_ok());
expected.push(MusicButler::new(MUSICBUTLER).unwrap());
expected.push(MusicButler::new(MUSICBUTLER_2).unwrap());
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
// Removing multiple URLs is okay if they all exist.
assert!(music_hoard
.remove_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2])
.is_ok());
expected.clear();
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])
.is_err());
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());
expected.clear();
expected.push(MusicButler::new(MUSICBUTLER).unwrap());
expected.push(MusicButler::new(MUSICBUTLER_2).unwrap());
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
// Clearing URLs on an artist that does not exist is an error.
assert!(music_hoard.clear_musicbutler_urls(&artist_id_2).is_err());
// Clear URLs.
assert!(music_hoard.clear_musicbutler_urls(&artist_id).is_ok());
expected.clear();
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
}
#[test]
fn artist_bandcamp_urls() {
let artist_id = ArtistId::new("an artist");
let artist_id_2 = ArtistId::new("another artist");
let mut music_hoard = MusicHoard::<NoLibrary, NoDatabase>::new(None, None);
assert!(music_hoard.new_artist(&artist_id).is_ok());
let mut expected: Vec<Bandcamp> = 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 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 an error.
assert!(music_hoard
.add_bandcamp_urls(&artist_id, vec![BANDCAMP])
.is_err());
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
// Adding another 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_err());
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
// Removing URLs to 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_ref() != BANDCAMP);
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
// If any URL does not exist removing URLs is an error.
assert!(music_hoard
.remove_bandcamp_urls(&artist_id, vec![BANDCAMP])
.is_err());
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
assert!(music_hoard
.remove_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2])
.is_err());
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
// If any URL already exists exists adding URLs is an error.
assert!(music_hoard
.add_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2])
.is_err());
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_ref() != BANDCAMP_2);
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
assert!(music_hoard
.remove_bandcamp_urls(&artist_id, vec![BANDCAMP_2])
.is_err());
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
// Adding mutliple URLs is okay if none of them already exist.
assert!(music_hoard
.add_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2])
.is_ok());
expected.push(Bandcamp::new(BANDCAMP).unwrap());
expected.push(Bandcamp::new(BANDCAMP_2).unwrap());
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
// Removing multiple URLs is okay if they all exist.
assert!(music_hoard
.remove_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2])
.is_ok());
expected.clear();
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])
.is_err());
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());
expected.clear();
expected.push(Bandcamp::new(BANDCAMP).unwrap());
expected.push(Bandcamp::new(BANDCAMP_2).unwrap());
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
// Clearing URLs on an artist that does not exist is an error.
assert!(music_hoard.clear_bandcamp_urls(&artist_id_2).is_err());
// Clear URLs.
assert!(music_hoard.clear_bandcamp_urls(&artist_id).is_ok());
expected.clear();
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
}
#[test]
fn artist_qobuz_url() {
let artist_id = ArtistId::new("an artist");
let artist_id_2 = ArtistId::new("another artist");
let mut music_hoard = MusicHoard::<NoLibrary, NoDatabase>::new(None, None);
assert!(music_hoard.new_artist(&artist_id).is_ok());
let mut expected: Option<Qobuz> = 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);
// Adding URL to artist.
assert!(music_hoard.add_qobuz_url(&artist_id, QOBUZ).is_ok());
_ = expected.insert(Qobuz::new(QOBUZ).unwrap());
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
// Adding further URLs is an error.
assert!(music_hoard.add_qobuz_url(&artist_id, QOBUZ).is_err());
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 is only okay if it matches the stored one.
assert!(music_hoard.remove_qobuz_url(&artist_id, QOBUZ_2).is_err());
assert!(music_hoard.remove_qobuz_url(&artist_id, QOBUZ).is_ok());
_ = expected.take();
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
// Removing a URl if one does not exist is an error.
assert!(music_hoard.remove_qobuz_url(&artist_id, QOBUZ).is_err());
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
// Setting an incorrect URL is an error.
assert!(music_hoard.set_qobuz_url(&artist_id, MUSICBRAINZ).is_err());
assert!(music_hoard.set_qobuz_url(&artist_id, MUSICBUTLER).is_err());
assert!(music_hoard.set_qobuz_url(&artist_id, BANDCAMP).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);
// Setting a URL on an artist.
assert!(music_hoard.set_qobuz_url(&artist_id, QOBUZ).is_ok());
_ = 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);
// Clearing URLs.
assert!(music_hoard.clear_qobuz_url(&artist_id).is_ok());
_ = expected.take();
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
assert!(music_hoard.delete_artist(&artist_id).is_ok());
} }
#[test] #[test]