Move more tests around
This commit is contained in:
parent
b6a464f056
commit
1616cf1a36
@ -468,9 +468,14 @@ mod tests {
|
|||||||
|
|
||||||
static MUSICBRAINZ: &str =
|
static MUSICBRAINZ: &str =
|
||||||
"https://musicbrainz.org/artist/d368baa8-21ca-4759-9731-0b2753071ad8";
|
"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: &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: &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: &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]
|
#[test]
|
||||||
fn musicbrainz() {
|
fn musicbrainz() {
|
||||||
@ -522,6 +527,451 @@ mod tests {
|
|||||||
assert!(Qobuz::new(QOBUZ).is_ok());
|
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<MusicBrainz> = 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<MusicBrainz> = 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<MusicButler> = 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<MusicButler> = 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<Bandcamp> = 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<Bandcamp> = 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<Qobuz> = 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<Qobuz> = 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]
|
#[test]
|
||||||
fn merge_artist_no_overlap() {
|
fn merge_artist_no_overlap() {
|
||||||
let left = FULL_COLLECTION[0].to_owned();
|
let left = FULL_COLLECTION[0].to_owned();
|
||||||
|
@ -342,17 +342,13 @@ mod tests {
|
|||||||
use crate::database::{self, MockIDatabase};
|
use crate::database::{self, MockIDatabase};
|
||||||
use crate::library::{self, testmod::LIBRARY_ITEMS, MockILibrary};
|
use crate::library::{self, testmod::LIBRARY_ITEMS, MockILibrary};
|
||||||
|
|
||||||
// FIXME: all tests with URLs should go to collection::artist
|
|
||||||
static MUSICBRAINZ: &str =
|
static MUSICBRAINZ: &str =
|
||||||
"https://musicbrainz.org/artist/d368baa8-21ca-4759-9731-0b2753071ad8";
|
"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: &str = "https://www.musicbutler.io/artist-page/483340948";
|
||||||
static MUSICBUTLER_2: &str = "https://www.musicbutler.io/artist-page/658903042/";
|
static MUSICBUTLER_2: &str = "https://www.musicbutler.io/artist-page/658903042/";
|
||||||
static BANDCAMP: &str = "https://thelasthangmen.bandcamp.com/";
|
static BANDCAMP: &str = "https://thelasthangmen.bandcamp.com/";
|
||||||
static BANDCAMP_2: &str = "https://viciouscrusade.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: &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]
|
#[test]
|
||||||
fn artist_new_delete() {
|
fn artist_new_delete() {
|
||||||
@ -428,12 +424,14 @@ mod tests {
|
|||||||
fn collection_error() {
|
fn collection_error() {
|
||||||
let artist_id = ArtistId::new("an artist");
|
let artist_id = ArtistId::new("an artist");
|
||||||
let mut music_hoard = MusicHoard::default();
|
let mut music_hoard = MusicHoard::default();
|
||||||
|
music_hoard.add_artist(artist_id.clone());
|
||||||
|
|
||||||
let actual_err = music_hoard
|
let actual_err = music_hoard
|
||||||
.add_musicbrainz_url(&artist_id, QOBUZ)
|
.add_musicbrainz_url(&artist_id, QOBUZ)
|
||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
let expected_err =
|
let expected_err = Error::CollectionError(format!(
|
||||||
Error::CollectionError(String::from("artist 'an artist' is not in the collection"));
|
"an error occurred when processing a URL: invalid MusicBrainz URL: {QOBUZ}"
|
||||||
|
));
|
||||||
assert_eq!(actual_err, expected_err);
|
assert_eq!(actual_err, expected_err);
|
||||||
assert_eq!(actual_err.to_string(), expected_err.to_string());
|
assert_eq!(actual_err.to_string(), expected_err.to_string());
|
||||||
}
|
}
|
||||||
@ -449,16 +447,6 @@ mod tests {
|
|||||||
let mut expected: Option<MusicBrainz> = None;
|
let mut expected: Option<MusicBrainz> = None;
|
||||||
assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected);
|
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.
|
// Adding URL to an artist not in the collection is an error.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.add_musicbrainz_url(&artist_id_2, MUSICBRAINZ)
|
.add_musicbrainz_url(&artist_id_2, MUSICBRAINZ)
|
||||||
@ -472,41 +460,18 @@ mod tests {
|
|||||||
_ = expected.insert(MusicBrainz::new(MUSICBRAINZ).unwrap());
|
_ = expected.insert(MusicBrainz::new(MUSICBRAINZ).unwrap());
|
||||||
assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected);
|
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.
|
// Removing a URL from an artist not in the collection is an error.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.remove_musicbrainz_url(&artist_id_2, MUSICBRAINZ)
|
.remove_musicbrainz_url(&artist_id_2, MUSICBRAINZ)
|
||||||
.is_err());
|
.is_err());
|
||||||
assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected);
|
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.
|
// Removing a URL in the collection removes it.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.remove_musicbrainz_url(&artist_id, MUSICBRAINZ)
|
.remove_musicbrainz_url(&artist_id, MUSICBRAINZ)
|
||||||
.is_ok());
|
.is_ok());
|
||||||
_ = expected.take();
|
_ = expected.take();
|
||||||
assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected);
|
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]
|
#[test]
|
||||||
@ -520,16 +485,6 @@ mod tests {
|
|||||||
let mut expected: Option<MusicBrainz> = None;
|
let mut expected: Option<MusicBrainz> = None;
|
||||||
assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected);
|
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.
|
// Setting a URL on an artist not in the collection is an error.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.set_musicbrainz_url(&artist_id_2, MUSICBRAINZ)
|
.set_musicbrainz_url(&artist_id_2, MUSICBRAINZ)
|
||||||
@ -543,17 +498,6 @@ mod tests {
|
|||||||
_ = expected.insert(MusicBrainz::new(MUSICBRAINZ).unwrap());
|
_ = expected.insert(MusicBrainz::new(MUSICBRAINZ).unwrap());
|
||||||
assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected);
|
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.
|
// Clearing URLs on an artist that does not exist is an error.
|
||||||
assert!(music_hoard.clear_musicbrainz_url(&artist_id_2).is_err());
|
assert!(music_hoard.clear_musicbrainz_url(&artist_id_2).is_err());
|
||||||
assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected);
|
assert_eq!(music_hoard.collection[0].properties.musicbrainz, expected);
|
||||||
@ -575,109 +519,12 @@ mod tests {
|
|||||||
let mut expected: Vec<MusicButler> = vec![];
|
let mut expected: Vec<MusicButler> = vec![];
|
||||||
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
|
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.
|
// Adding URLs to an artist not in the collection is an error.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.add_musicbutler_urls(&artist_id_2, vec![MUSICBUTLER])
|
.add_musicbutler_urls(&artist_id_2, vec![MUSICBUTLER])
|
||||||
.is_err());
|
.is_err());
|
||||||
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
|
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.
|
// Adding mutliple URLs without clashes.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.add_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2])
|
.add_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2])
|
||||||
@ -686,6 +533,12 @@ mod tests {
|
|||||||
expected.push(MusicButler::new(MUSICBUTLER_2).unwrap());
|
expected.push(MusicButler::new(MUSICBUTLER_2).unwrap());
|
||||||
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
|
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.
|
// Removing multiple URLs without clashes.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.remove_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2])
|
.remove_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2])
|
||||||
@ -705,21 +558,6 @@ mod tests {
|
|||||||
let mut expected: Vec<MusicButler> = vec![];
|
let mut expected: Vec<MusicButler> = vec![];
|
||||||
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
|
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.
|
// Seting URL on an artist not in the collection is an error.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.set_musicbutler_urls(&artist_id_2, vec![MUSICBUTLER])
|
.set_musicbutler_urls(&artist_id_2, vec![MUSICBUTLER])
|
||||||
@ -727,19 +565,6 @@ mod tests {
|
|||||||
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
|
assert_eq!(music_hoard.collection[0].properties.musicbutler, expected);
|
||||||
|
|
||||||
// Set URLs.
|
// 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
|
assert!(music_hoard
|
||||||
.set_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2])
|
.set_musicbutler_urls(&artist_id, vec![MUSICBUTLER, MUSICBUTLER_2])
|
||||||
.is_ok());
|
.is_ok());
|
||||||
@ -768,109 +593,12 @@ mod tests {
|
|||||||
let mut expected: Vec<Bandcamp> = vec![];
|
let mut expected: Vec<Bandcamp> = vec![];
|
||||||
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
|
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.
|
// Adding URLs to an artist not in the collection is an error.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.add_bandcamp_urls(&artist_id_2, vec![BANDCAMP])
|
.add_bandcamp_urls(&artist_id_2, vec![BANDCAMP])
|
||||||
.is_err());
|
.is_err());
|
||||||
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
|
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.
|
// Adding mutliple URLs without clashes.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.add_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2])
|
.add_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2])
|
||||||
@ -879,6 +607,12 @@ mod tests {
|
|||||||
expected.push(Bandcamp::new(BANDCAMP_2).unwrap());
|
expected.push(Bandcamp::new(BANDCAMP_2).unwrap());
|
||||||
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
|
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.
|
// Removing multiple URLs without clashes.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.remove_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2])
|
.remove_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2])
|
||||||
@ -898,21 +632,6 @@ mod tests {
|
|||||||
let mut expected: Vec<Bandcamp> = vec![];
|
let mut expected: Vec<Bandcamp> = vec![];
|
||||||
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
|
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.
|
// Seting URL on an artist not in the collection is an error.
|
||||||
assert!(music_hoard
|
assert!(music_hoard
|
||||||
.set_bandcamp_urls(&artist_id_2, vec![BANDCAMP])
|
.set_bandcamp_urls(&artist_id_2, vec![BANDCAMP])
|
||||||
@ -920,19 +639,6 @@ mod tests {
|
|||||||
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
|
assert_eq!(music_hoard.collection[0].properties.bandcamp, expected);
|
||||||
|
|
||||||
// Set URLs.
|
// 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
|
assert!(music_hoard
|
||||||
.set_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2])
|
.set_bandcamp_urls(&artist_id, vec![BANDCAMP, BANDCAMP_2])
|
||||||
.is_ok());
|
.is_ok());
|
||||||
@ -961,12 +667,6 @@ mod tests {
|
|||||||
let mut expected: Option<Qobuz> = None;
|
let mut expected: Option<Qobuz> = None;
|
||||||
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
|
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.
|
// 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!(music_hoard.add_qobuz_url(&artist_id_2, QOBUZ).is_err());
|
||||||
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
|
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
|
||||||
@ -976,29 +676,14 @@ mod tests {
|
|||||||
_ = expected.insert(Qobuz::new(QOBUZ).unwrap());
|
_ = expected.insert(Qobuz::new(QOBUZ).unwrap());
|
||||||
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
|
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.
|
// 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!(music_hoard.remove_qobuz_url(&artist_id_2, QOBUZ).is_err());
|
||||||
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
|
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.
|
// Removing a URL in the collection removes it.
|
||||||
assert!(music_hoard.remove_qobuz_url(&artist_id, QOBUZ).is_ok());
|
assert!(music_hoard.remove_qobuz_url(&artist_id, QOBUZ).is_ok());
|
||||||
_ = expected.take();
|
_ = expected.take();
|
||||||
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
|
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]
|
#[test]
|
||||||
@ -1012,12 +697,6 @@ mod tests {
|
|||||||
let mut expected: Option<Qobuz> = None;
|
let mut expected: Option<Qobuz> = None;
|
||||||
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
|
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.
|
// 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!(music_hoard.set_qobuz_url(&artist_id_2, QOBUZ).is_err());
|
||||||
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
|
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
|
||||||
@ -1027,13 +706,6 @@ mod tests {
|
|||||||
_ = expected.insert(Qobuz::new(QOBUZ).unwrap());
|
_ = expected.insert(Qobuz::new(QOBUZ).unwrap());
|
||||||
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
|
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.
|
// Clearing URLs on an artist that does not exist is an error.
|
||||||
assert!(music_hoard.clear_qobuz_url(&artist_id_2).is_err());
|
assert!(music_hoard.clear_qobuz_url(&artist_id_2).is_err());
|
||||||
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
|
assert_eq!(music_hoard.collection[0].properties.qobuz, expected);
|
||||||
|
Loading…
Reference in New Issue
Block a user