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 { impl Default for ArtistInfo {
fn default() -> Self { fn default() -> Self {
Self::new(MbRefOption::None) Self::new()
} }
} }
impl ArtistInfo { impl ArtistInfo {
pub fn new(musicbrainz: MbRefOption<MbArtistRef>) -> Self { pub fn new() -> Self {
ArtistInfo { ArtistInfo {
musicbrainz, musicbrainz: MbRefOption::None,
properties: HashMap::new(), properties: HashMap::new(),
} }
} }

View File

@ -461,7 +461,7 @@ mod tests {
let mut expected: MbRefOption<MbArtistRef> = MbRefOption::None; let mut expected: MbRefOption<MbArtistRef> = MbRefOption::None;
assert_eq!(music_hoard.collection[0].meta.info.musicbrainz, expected); 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()); info.musicbrainz = MbRefOption::Some(MbArtistRef::from_uuid_str(MBID).unwrap());
// 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.

View File

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

View File

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