From c162d399d8b3b4fde1392d260219c183c3cd6d57 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Mon, 30 Dec 2024 23:37:54 +0100 Subject: [PATCH] Complete code coverage --- src/core/collection/album.rs | 10 ----- src/tui/app/machine/fetch_state.rs | 60 ++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/src/core/collection/album.rs b/src/core/collection/album.rs index 762a8e0..6356692 100644 --- a/src/core/collection/album.rs +++ b/src/core/collection/album.rs @@ -156,16 +156,6 @@ impl Album { self } - pub fn with_type, Date: Into>( - mut self, - primary_type: Option, - secondary_types: Vec, - ) -> Self { - self.meta.info.primary_type = primary_type; - self.meta.info.secondary_types = secondary_types; - self - } - pub fn get_status(&self) -> AlbumStatus { AlbumStatus::from_tracks(&self.tracks) } diff --git a/src/tui/app/machine/fetch_state.rs b/src/tui/app/machine/fetch_state.rs index 862dd65..2029fd5 100644 --- a/src/tui/app/machine/fetch_state.rs +++ b/src/tui/app/machine/fetch_state.rs @@ -680,7 +680,7 @@ mod tests { } #[test] - fn recv_ok_fetch_ok() { + fn recv_ok_match_ok() { let (tx, rx) = mpsc::channel::(); let artist = COLLECTION[3].meta.clone(); @@ -707,7 +707,7 @@ mod tests { } #[test] - fn recv_ok_fetch_err() { + fn recv_ok_search_err() { let (tx, rx) = mpsc::channel::(); let fetch_result = Err(musicbrainz::api::Error::RateLimit); @@ -719,6 +719,60 @@ mod tests { assert!(matches!(app, AppState::Error(_))); } + #[test] + fn recv_ok_fetch_ok() { + let collection = COLLECTION.clone(); + + let (tx, rx) = mpsc::channel::(); + let fetch = FetchState::fetch(rx); + + let artist_id = collection[0].meta.id.clone(); + let old_album = collection[0].albums[0].meta.clone(); + let new_album = AlbumMeta::new(AlbumId::new("some new album")); + + let release_group_fetch = EntityList::Album(vec![old_album.clone(), new_album.clone()]); + let fetch_result = Ok(MbReturn::Fetch(release_group_fetch)); + tx.send(fetch_result).unwrap(); + drop(tx); + + let mut music_hoard = music_hoard(collection); + music_hoard + .expect_add_album() + .with(predicate::eq(artist_id), predicate::eq(new_album)) + .times(1) + .return_once(|_, _| Ok(())); + + let app = AppMachine::app_fetch_next(inner(music_hoard), fetch); + assert!(matches!(app, AppState::Browse(_))); + } + + #[test] + fn recv_ok_fetch_ok_add_album_err() { + let collection = COLLECTION.clone(); + + let (tx, rx) = mpsc::channel::(); + let fetch = FetchState::fetch(rx); + + let artist_id = collection[0].meta.id.clone(); + let old_album = collection[0].albums[0].meta.clone(); + let new_album = AlbumMeta::new(AlbumId::new("some new album")); + + let release_group_fetch = EntityList::Album(vec![old_album.clone(), new_album.clone()]); + let fetch_result = Ok(MbReturn::Fetch(release_group_fetch)); + tx.send(fetch_result).unwrap(); + drop(tx); + + let mut music_hoard = music_hoard(collection); + music_hoard + .expect_add_album() + .with(predicate::eq(artist_id), predicate::eq(new_album)) + .times(1) + .return_once(|_, _| Err(musichoard::Error::CollectionError(String::from("get rekt")))); + + let app = AppMachine::app_fetch_next(inner(music_hoard), fetch); + assert!(matches!(app, AppState::Error(_))); + } + #[test] fn recv_err_empty() { let (_tx, rx) = mpsc::channel::(); @@ -764,7 +818,7 @@ mod tests { } #[test] - fn recv_err_disconnected_next() { + fn recv_err_disconnected_search_next() { let mut collection = COLLECTION.clone(); collection[0].albums.clear();