Compare commits

..

No commits in common. "9488464b11cbacb71ded282468777595a26d79f8" and "6b90f470be9d5d64ece447889891950049dadb3a" have entirely different histories.

4 changed files with 36 additions and 62 deletions

View File

@ -100,14 +100,14 @@ impl ArtistMeta {
impl Default for ArtistInfo {
fn default() -> Self {
Self::new(MbRefOption::None)
Self::new()
}
}
impl ArtistInfo {
pub fn new(musicbrainz: MbRefOption<MbArtistRef>) -> Self {
pub fn new() -> Self {
ArtistInfo {
musicbrainz,
musicbrainz: MbRefOption::None,
properties: HashMap::new(),
}
}

View File

@ -461,7 +461,7 @@ mod tests {
let mut expected: MbRefOption<MbArtistRef> = MbRefOption::None;
assert_eq!(music_hoard.collection[0].meta.info.musicbrainz, expected);
let mut info = ArtistInfo::default();
let mut info = ArtistInfo::new();
info.musicbrainz = MbRefOption::Some(MbArtistRef::from_uuid_str(MBID).unwrap());
// Setting a URL on an artist not in the collection is an error.

View File

@ -350,7 +350,7 @@ mod tests {
let app = browse.increment_selection(Delta::Line);
let app = app.unwrap_browse().fetch_musicbrainz();
assert!(matches!(app, AppState::Fetch(_)));
assert!(matches!(app, AppState::Match(_)));
}
fn lookup_album_expectation(
@ -413,7 +413,7 @@ mod tests {
let app = browse.increment_selection(Delta::Line);
let app = app.unwrap_browse().fetch_musicbrainz();
assert!(matches!(app, AppState::Fetch(_)));
assert!(matches!(app, AppState::Match(_)));
}
fn lookup_artist_expectation(job_sender: &mut MockIMbJobSender, artist: &ArtistMeta) {
@ -542,23 +542,21 @@ mod tests {
}
#[test]
fn recv_err_empty_first() {
let mut collection = COLLECTION.clone();
collection[0].albums.clear();
fn recv_err_disconnected_first() {
let (_, rx) = mpsc::channel::<MbApiResult>();
let app = AppMachine::app_fetch_first(inner(music_hoard(collection)));
let inner = inner(music_hoard(COLLECTION.clone()));
let fetch = FetchState::new(rx);
let app = AppMachine::app_fetch_next(inner, fetch);
assert!(matches!(app, AppState::Match(_)));
}
#[test]
fn recv_err_empty_next() {
let mut collection = COLLECTION.clone();
collection[0].albums.clear();
fn recv_err_disconnected_next() {
let (_, rx) = mpsc::channel::<MbApiResult>();
let fetch = FetchState::new(rx);
let app = AppMachine::app_fetch_next(inner(music_hoard(collection)), fetch);
let fetch = FetchState::new(rx);
let app = AppMachine::app_fetch_next(inner(music_hoard(COLLECTION.clone())), fetch);
assert!(matches!(app, AppState::Browse(_)));
}

View File

@ -308,7 +308,7 @@ impl IAppInteractMatch for AppMachine<MatchState> {
mod tests {
use std::{collections::VecDeque, sync::mpsc};
use mockall::predicate::{self, eq};
use mockall::predicate;
use musichoard::collection::{
album::{AlbumDate, AlbumId, AlbumInfo, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType},
artist::{ArtistId, ArtistMeta},
@ -346,12 +346,8 @@ mod tests {
}
}
fn artist_meta() -> ArtistMeta {
ArtistMeta::new(ArtistId::new("Artist"))
}
fn artist_match() -> MatchStateInfo {
let artist = artist_meta();
let artist = ArtistMeta::new(ArtistId::new("Artist"));
let artist_1 = artist.clone();
let artist_match_1 = Match::new(100, artist_1);
@ -365,13 +361,14 @@ mod tests {
}
fn artist_lookup() -> MatchStateInfo {
let artist = artist_meta();
let artist = ArtistMeta::new(ArtistId::new("Artist"));
let lookup = Lookup::new(artist.clone());
MatchStateInfo::artist_lookup(artist, lookup)
}
fn album_meta() -> AlbumMeta {
AlbumMeta::new(
fn album_match() -> MatchStateInfo {
let artist_id = ArtistId::new("Artist");
let album = AlbumMeta::new(
AlbumId::new("Album"),
AlbumDate::new(Some(1990), Some(5), None),
AlbumInfo::new(
@ -379,12 +376,7 @@ mod tests {
Some(AlbumPrimaryType::Album),
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
),
)
}
fn album_match() -> MatchStateInfo {
let artist_id = ArtistId::new("Artist");
let album = album_meta();
);
let album_1 = album.clone();
let album_match_1 = Match::new(100, album_1);
@ -400,7 +392,15 @@ mod tests {
fn album_lookup() -> MatchStateInfo {
let artist_id = ArtistId::new("Artist");
let album = album_meta();
let album = AlbumMeta::new(
AlbumId::new("Album"),
AlbumDate::new(Some(1990), Some(5), None),
AlbumInfo::new(
MbRefOption::None,
Some(AlbumPrimaryType::Album),
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
),
);
let lookup = Lookup::new(album.clone());
MatchStateInfo::album_lookup(artist_id, album, lookup)
}
@ -457,34 +457,11 @@ mod tests {
fn match_state_flow(mut matches_info: MatchStateInfo, len: usize) {
// tx must exist for rx to return Empty rather than Disconnected.
let (_tx, rx) = mpsc::channel();
#[allow(unused_variables)]
let (tx, rx) = mpsc::channel();
let app_matches = MatchState::new(Some(matches_info.clone()), FetchState::new(rx));
let mut music_hoard = music_hoard(vec![]);
let artist_id = ArtistId::new("Artist");
match matches_info {
MatchStateInfo::Album(_) => {
let album_id = AlbumId::new("Album");
let mut info = album_meta().info;
info.musicbrainz = MbRefOption::CannotHaveMbid;
music_hoard
.expect_set_album_info()
.with(eq(artist_id.clone()), eq(album_id.clone()), eq(info))
.times(1)
.return_once(|_, _, _| Ok(()));
}
MatchStateInfo::Artist(_) => {
let mut info = artist_meta().info;
info.musicbrainz = MbRefOption::CannotHaveMbid;
music_hoard
.expect_set_artist_info()
.with(eq(artist_id.clone()), eq(info))
.times(1)
.return_once(|_, _| Ok(()));
}
}
let matches = AppMachine::match_state(inner(music_hoard), app_matches);
let matches = AppMachine::match_state(inner(music_hoard(vec![])), app_matches);
matches_info.push_cannot_have_mbid();
matches_info.push_manual_input_mbid();
@ -570,11 +547,10 @@ mod tests {
#[test]
fn select_empty() {
// This test will become obsolete with #203 so it just needs to work well enough for
// coverage. We expect the error state, because after selecting, fetch will be invoked, but
// with an empty collection, an error will be raised.
// Note that what really matters in this test is actually that the transmit channel has
// disconnected and so the receive within FetchState concludes there are no more matches.
let matches = AppMachine::match_state(inner(music_hoard(vec![])), match_state(None));
matches.select().unwrap_error();
matches.select().unwrap_browse();
}
#[test]